Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

You are adding gRPC to a Spring Boot service. What options exist for integration, and what operational issues do you plan for?

For integration we can use the Spring gRPC project, checking its maturity for our Spring Boot version, a community starter, or plain grpc-java with our own wiring. Operationally, HTTP/2 connections are long-lived, so an L4 load balancer pins all of a client's calls to one backend; we need client-side load balancing or an L7 proxy. We also set a deadline on every call and propagate it, add interceptors for authentication, tracing and metrics, and manage .proto files as versioned contracts with breaking-change checks such as buf.

Why this question is asked

Adding gRPC to a Spring Boot service looks like a code task: add a dependency, implement a generated base class, done. The surprises come later in production: one pod at 90% CPU while the others idle, calls hanging for minutes, traces that stop at the gRPC boundary, and a field rename that breaks three consumers. Interviewers ask this scenario to see whether we plan for those issues before they happen. In this answer, we will compare the integration options, then go through load balancing, deadlines, interceptors for cross-cutting concerns, and how to manage the contracts.

1Integration Options in Spring Boot

There are three broad ways to run gRPC inside a Spring Boot application. The Spring gRPC project, from the Spring team, provides Boot auto-configuration for servers and clients, integration with Spring Security and Micrometer, and registers our service beans automatically. It is newer than the rest of the Spring portfolio, so we check which release lines support our Spring Boot version (3.5 or 4.0) and how mature it is before standardising on it. Community starters, such as the long-standing grpc-spring-boot-starter projects, offer similar features and have been used in production for years, but their release cadence depends on their maintainers.

The third option is plain grpc-java: we create the Server with a ServerBuilder in a Spring bean, register our service implementations, and manage its lifecycle with SmartLifecycle so it starts and stops with the application context. This has no extra dependency and full control, at the cost of writing the wiring, security and metrics ourselves.

Java
// a service implementation; with Spring gRPC or a starter it is picked up as a bean
@Service
class OrderGrpcService extends OrderServiceGrpc.OrderServiceImplBase {
private final OrderRepository orders;
OrderGrpcService(OrderRepository orders) { this.orders = orders; }
@Override
public void getOrder(GetOrderRequest req, StreamObserver<Order> response) {
orders.find(req.getOrderId()).ifPresentOrElse(o -> {
response.onNext(toProto(o));
response.onCompleted(); // OK
}, () -> response.onError(Status.NOT_FOUND
.withDescription("order " + req.getOrderId()).asRuntimeException()));
}
}

Whichever we choose, the service code looks the same, because it is generated grpc-java code. That keeps the choice reversible; what changes is configuration and the integrations we get for free.

2Load Balancing Long-Lived HTTP/2 Connections

This is the issue that surprises most teams. gRPC clients open one HTTP/2 connection to a target and send all calls over it as multiplexed streams, often for hours. An L4 load balancer, one that balances TCP connections, such as a Kubernetes ClusterIP service, picks a backend once per connection. So if three client pods each open one connection, at most three server pods receive any traffic, and adding more server pods does nothing.

There are two standard fixes. Client-side load balancing: the client resolves all backend addresses, for example through DNS on a Kubernetes headless service, opens connections to each, and spreads calls with a round_robin policy. Or an L7 proxy that understands HTTP/2, such as Envoy or a service mesh sidecar, which balances individual calls rather than connections. Servers can also set a maximum connection age so clients reconnect periodically and pick up new pods after scaling.

Java
ManagedChannel channel = ManagedChannelBuilder
.forTarget("dns:///orders-headless.shop.svc.cluster.local:9090") // all pod IPs
.defaultLoadBalancingPolicy("round_robin") // spread calls, not connections
.usePlaintext() // mesh or TLS config in real use
.build();
Why calls do not spread
SetupBalancing unitResult with 3 clients, 10 servers
L4 load balancer (ClusterIP)TCP connectionat most 3 servers busy
Client-side round_robin + headless DNSeach callall 10 servers share load
L7 proxy (Envoy, mesh)each callall 10 servers share load

Notice the headless service name: a normal Kubernetes service returns one virtual IP, which would put us back to a single connection.

3Deadlines on Every Call

A gRPC call without a deadline can wait forever: if the server hangs, the client thread or stream waits indefinitely, and under load those waiting calls pile up until the client runs out of resources. So the rule is simple: every call has a deadline, chosen from the caller's own latency budget.

Java
Order order = OrderServiceGrpc.newBlockingStub(channel)
.withDeadlineAfter(300, TimeUnit.MILLISECONDS) // fail with DEADLINE_EXCEEDED after 300 ms
.getOrder(GetOrderRequest.newBuilder().setOrderId("981").build());

Deadlines are also propagated. The deadline travels to the server in the grpc-timeout header, and in grpc-java it becomes part of the server call's Context. When the server makes its own gRPC calls from that Context, the remaining time is passed on automatically, so a chain of three services shares one budget instead of each waiting its own full timeout. Work that switches threads must carry the Context along, for example with Context.current().wrap(...), or the propagation is lost. Servers should check for cancellation in long operations and stop when the caller has given up.

4Interceptors for Auth, Tracing and Metrics

Cross-cutting concerns belong in interceptors, gRPC's equivalent of servlet filters. A ServerInterceptor sees every incoming call's metadata (gRPC's headers) before the method runs; a ClientInterceptor sees every outgoing call. We use them for authentication, validating a bearer token from the authorization metadata and putting the identity in the Context, and rejecting with UNAUTHENTICATED otherwise; for tracing, propagating the trace context so traces continue across the gRPC boundary; and for metrics, recording calls by service, method and status code.

Micrometer provides observation interceptors for grpc-java (ObservationGrpcServerInterceptor and ObservationGrpcClientInterceptor), and Spring gRPC and the starters can register them automatically. With them, gRPC calls appear in the same dashboards and traces as our HTTP calls. Alongside, we expose the standard gRPC health service so load balancers and Kubernetes probes can check readiness, and server reflection in non-production so tools like grpcurl can call methods for debugging.

Step throughA call through client and server interceptors
CallerClient interceptorsServer interceptorsOrderGrpcService
getOrder, deadline 300 ms
metadata: authorization, traceparent, grpc-timeout
validate token, start span, start timer
invoke with identity in Context
Order or Status
status code recorded, span ended
Order

7 messages in order. Play them, or step through them one at a time.

5Managing .proto Files as Versioned Contracts

A .proto file is an API contract shared by producers and consumers, so it needs a home and rules. Common practice is a dedicated repository or module for the contracts, versioned packages such as shop.v1, and generated artifacts (a Java jar, plus code for other languages) published to the internal repository so consumers depend on a version rather than copying files.

Breaking changes are caught automatically. A tool such as buf runs lint rules (naming, enum zero values, package versions) and a breaking-change check that compares the new files with the last released version, failing the build if a field number is reused, a type changes or a field is removed without being reserved. Changes that are truly breaking go into a new package version, shop.v2, served alongside v1 until consumers have moved.

6Follow-up questions

Why does adding pods not reduce the load on the busy pod?

Because existing clients keep their long-lived HTTP/2 connections to the pods they connected to first, and an L4 balancer only acts when a connection opens. New pods only get new connections. Client-side round_robin over a headless service or an L7 proxy fixes it, and a maximum connection age on the server makes clients reconnect and rebalance regularly.

How do gRPC status codes map to HTTP-style errors?

gRPC has its own codes, carried in trailers: NOT_FOUND, INVALID_ARGUMENT, UNAUTHENTICATED, PERMISSION_DENIED, DEADLINE_EXCEEDED, UNAVAILABLE and others. The HTTP status of a gRPC response is normally 200 even for errors. We map domain errors to the right codes on the server, and clients retry only codes that are safe to retry, usually UNAVAILABLE.

Can a Spring Boot app serve REST and gRPC at the same time?

Yes. The gRPC server usually listens on its own port, for example 9090, next to the HTTP port, and both share the same beans. Some setups also serve gRPC on the main servlet container's port; check what your integration and Spring Boot version support.

7Conclusion

In this answer, we looked at adding gRPC to Spring Boot: the Spring gRPC project (checking its maturity for our Spring Boot version), community starters, or plain grpc-java with our own wiring. We planned for the main operational issues: long-lived HTTP/2 connections that defeat L4 load balancers and need client-side balancing or an L7 proxy, deadlines on every call that propagate through the Context, interceptors for authentication, tracing and metrics, and .proto files managed as versioned contracts with breaking-change checks such as buf.

What to say in the interviewAbout 90 seconds aloud

Open with

For integration I see three options. The Spring gRPC project gives Boot auto-configuration, security and Micrometer integration, but it is fairly new, so I would check its maturity and support for our Spring Boot version.

Then, if they want more

Community starters have been used in production for years but depend on their maintainers. Or plain grpc-java with a ServerBuilder in a bean and SmartLifecycle, which is more wiring but no extra dependency. The service code is the same generated grpc-java code in every case, so the choice is reversible.

Operationally, the first thing I plan for is load balancing: gRPC uses one long-lived HTTP/2 connection per target, so an L4 balancer like a ClusterIP service pins each client to one pod and new pods get nothing. I would use client-side round_robin over a headless service, or an L7 proxy like Envoy or a mesh, plus a maximum connection age.

Second, deadlines on every call, from the caller's latency budget, propagated through the gRPC Context so a chain of services shares one budget, and servers that stop on cancellation. Third, interceptors for auth, tracing and metrics, using Micrometer's observation interceptors so gRPC shows up in the same dashboards, plus the health service for probes.

Finally, I would keep .proto files in a contract repository with versioned packages, publish generated artifacts, and run buf lint and breaking-change checks in CI.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "You are adding gRPC to a Spring Boot service. What options exist for integration, and...": https://scrivio-interview-library.netlify.app/spring-boot/web-other/2799ac1d3d/