REST vs GraphQL vs gRPC for Java Services Compared Fairly
Choose between REST, GraphQL and gRPC for a Java service by who calls it, how data is shaped and what tooling you need, with a verdict for each case.

Three styles of API cover most services, and the debate between them is usually about the wrong thing. They solve different problems. This comparison states which problem each one solves, the Java support for each and a verdict by situation. The REST side is described in REST API design rules and building REST APIs with Spring MVC.
What each one is
REST exposes resources at URLs and uses HTTP methods and status codes. Payloads are usually JSON. GraphQL exposes a typed schema through a single endpoint; the client sends a query naming the fields it wants. gRPC defines services and messages in .proto files, compiles them to client and server stubs and sends Protocol Buffers over HTTP/2.
Side by side
| REST | GraphQL | gRPC | |
|---|---|---|---|
| Transport | HTTP/1.1 or 2, JSON | HTTP, JSON | HTTP/2, Protocol Buffers |
| Contract | OpenAPI (optional) | Schema (required) | .proto (required) |
| Client picks fields | No (fixed responses) | Yes | No (fixed messages) |
| Caching | HTTP caches work | Hard, usually per query | Not HTTP-cache friendly |
| Streaming | Server-sent events, WebSocket | Subscriptions | Native, bidirectional |
| Browser clients | Native | Native | Needs gRPC-Web and a proxy |
| Payload size | Larger (text) | Larger (text) | Smaller (binary) |
| Java support | Spring MVC, Jakarta REST | Spring for GraphQL, graphql-java | grpc-java, Spring gRPC |
Choose REST when
The API is public, consumed by browsers and many unknown clients, or simple enough that the resource model fits. HTTP gives you caching, status codes and a mountain of tooling (curl, proxies, gateways, browser dev tools). Most business services should start and stay here. The risks are over-fetching (a response with fields the client does not use) and under-fetching (several calls to assemble one screen), which are real for mobile clients on slow networks.
Choose GraphQL when
Several clients (web, iOS, Android, partners) need different slices of a connected data model, and the number of tailored endpoints is getting out of hand. A mobile screen asks for the three fields it shows, and a dashboard asks for twenty. With Spring for GraphQL, you map schema fields to controller methods:
@Controller
class OrderController {
@QueryMapping
Order orderById(@Argument String id) { return orders.get(id); }
@SchemaMapping(typeName = "Order")
Customer customer(Order order) { return customers.get(order.customerId()); }
}The costs: query complexity needs limits (depth and cost analysis) or one query can load your database; the N plus 1 problem moves into resolvers (batch loading with @BatchMapping); HTTP caching is lost; authorization must be applied per field. Do not choose GraphQL for a CRUD service with one client.
Choose gRPC when
Services call each other inside your platform, latency and throughput matter, and you want a strict, versioned contract with generated clients in several languages. A .proto file is the single source of truth:
service OrderService {
rpc GetOrder (GetOrderRequest) returns (Order);
rpc StreamUpdates (GetOrderRequest) returns (stream OrderUpdate);
}Streaming is native, which suits event feeds and long-lived calls. The costs: binary payloads are harder to inspect, browsers need a gateway, load balancing HTTP/2 needs a proxy that understands it, and debugging needs tooling (grpcurl). Between microservices that speak Java to Java, the generated stubs also remove a class of serialization bugs. The communication styles are discussed in synchronous vs asynchronous service calls.
Decision
- Public or unknown clients: REST.
- Many client types needing different shapes of one graph: GraphQL, behind a gateway, with limits.
- Internal calls where performance and a strict contract matter: gRPC.
- Unsure: REST. It is the cheapest to change later, because the tooling is plentiful.
A common arrangement is gRPC between services and REST (or GraphQL) at the edge, with the edge service translating.
A same-feature comparison in code
Tables compare features, and the feeling of the three styles comes from writing the same operation in each. The operation is "fetch an order with its customer name and the SKUs of its lines". In REST, the client either receives a fixed representation or asks for a second resource:
@RestController
@RequestMapping("/orders")
class OrderRestController {
@GetMapping("/{id}")
OrderView get(@PathVariable long id) {
Order order = orders.findWithLines(id).orElseThrow(OrderNotFound::new);
return new OrderView(order.id(), order.customerId(), order.lines().stream().map(OrderLine::sku).toList());
}
}curl -s localhost:8080/orders/42
curl -s localhost:8080/customers/c-17 # a second call for the customer nameThe server decides the shape, so every client receives the same fields, and the customer name costs one more round trip, or a field you add for the screen that needs it. In GraphQL the client names exactly the fields, and the server resolves each one:
query {
orderById(id: "42") {
id
customer { name }
lines { sku }
}
}@Controller
class OrderGraphController {
@QueryMapping
Order orderById(@Argument String id) { return orders.get(id); }
@SchemaMapping
Customer customer(Order order) { return customers.get(order.customerId()); }
@BatchMapping
Map<Order, List<OrderLine>> lines(List<Order> orders) { return lineRepository.byOrders(orders); }
}The @BatchMapping method is not decoration: without it, a query for twenty orders issues twenty line queries, which is the N plus 1 problem reappearing in the resolver layer. gRPC fixes the shape in the .proto file and generates the Java classes you call:
OrderServiceGrpc.OrderServiceBlockingStub stub = OrderServiceGrpc.newBlockingStub(channel)
.withDeadlineAfter(500, TimeUnit.MILLISECONDS);
Order order = stub.getOrder(GetOrderRequest.newBuilder().setId("42").build());
String firstSku = order.getLines(0).getSku();Notice the deadline on the stub. gRPC treats a time limit as part of every call and propagates it to downstream calls, which is a feature that REST clients have to build by hand. Lined up this way, the difference is where the decision sits: the REST server decides the shape and the client decides how many calls to make, the GraphQL client decides the shape, and the gRPC contract decides both, in a file both sides compile.
Operating the three in production
Choosing a style also chooses a set of operational habits. REST gets observability almost free, because every URL and status code appears in access logs, gateways and browser tools, and a 429 or a 503 means the same thing to every proxy on the path. GraphQL funnels everything through one URL, so the interesting information is in the query: log the operation name, put limits on depth and complexity, and consider persisted queries so that production accepts only operations your clients have registered. gRPC needs a load balancer that understands HTTP/2 and balances calls rather than connections, since one long-lived connection from a client can pin all traffic to one server. It also needs health checking through the standard gRPC health service, and tooling such as grpcurl for the engineer who has only a terminal during an incident. None of these costs is a reason to avoid a style. They are the line items to put in the estimate, beside the shape of the data.
Where the comparison does not apply
Event-driven communication (messages through Kafka) replaces request-response rather than competing with it. Real-time bidirectional UI needs WebSockets or server-sent events. The gRPC documentation, the Spring for GraphQL reference and the OpenAPI specification are the primary sources.


