Video in progress

Staff 🌱 Spring

Someone proposes moving from REST to gRPC between internal services. How do you evaluate this decision in the Spring ecosystem?

gRPC gives a strict contract, small binary messages, HTTP/2 streaming and code generation; but it doesn't work with browsers directly, debugging and tooling are harder, and you have to configure load balancing and gateways separately.

📖 Answer

First we measure: is the problem really serialization and the network? In many cases 90% of the latency is in the database, not in JSON.

What gRPC gives you:

  • .proto is a single contract, and clients for Java, Go and Python are generated automatically. The backward-compatibility rules are clear thanks to field numbers.
  • Protobuf is more compact than JSON and faster to parse, which is noticeable in high-volume, high-frequency calls.
  • HTTP/2: many requests on one connection, bidirectional streaming.
  • Deadlines are propagated along the chain by the protocol itself.

The cost:

  • A browser can't speak gRPC directly, so for an external API you still need REST or gRPC-Web/transcoding.
  • You can't check it with curl; you need grpcurl, reflection and special tools.
  • Load balancing: a long-lived HTTP/2 connection sticks to one pod behind a plain L4 balancer. You need an L7 balancer, a service mesh or client-side balancing.
  • The error model is different (status codes, Status.details), so you have to adapt your existing monitoring and exception handling.
  • Spring integration: there is now an official Spring gRPC project, and before that teams used third-party starters. This part is younger than REST.

Where it pays off:

  • high-frequency internal calls (tens of thousands per second), for example a pricing or scoring service;
  • a multi-language environment that needs a strict contract;
  • streaming (real-time updates).

My approach: I don't migrate everything. I pilot one high-load path and measure p99 and CPU before and after. The external API stays REST. If the main problem is messy contracts, you can solve that with REST + OpenAPI + contract tests too, without changing the protocol.