Quick revision
The short answer
gRPC defines services in protobuf contracts, encodes messages in a compact binary format and runs over HTTP/2, with client and server stubs generated from the contract, while REST over JSON usually uses text payloads, looser contracts and hand-written clients. gRPC has four call types: unary, server streaming, client streaming and bidirectional streaming. Its contracts have strict evolution rules (never reuse a field number, add new fields rather than changing old ones), deadlines and cancellation are part of the protocol, and browsers need gRPC-Web or a gateway.
What to remember
In this answer, we compared gRPC with REST over JSON. gRPC starts from a protobuf contract, encodes messages in compact binary, runs on HTTP/2 and generates client and server stubs, while REST usually relies on text JSON and looser contracts. We went through the four call types, unary, server streaming, client streaming and bidirectional streaming, the evolution rules that keep contracts compatible (new field numbers, never reuse, reserve removed numbers), deadlines and cancellation built into the protocol, and the need for gRPC-Web or a gateway for browsers.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
gRPC defines services in protobuf contracts, encodes messages in a compact binary format and runs over HTTP/2, with client and server stubs generated from the contract, while REST over JSON usually uses text payloads, looser contracts and hand-written clients. gRPC has four call types: unary, server streaming, client streaming and bidirectional streaming. Its contracts have strict evolution rules (never reuse a field number, add new fields rather than changing old ones), deadlines and cancellation are part of the protocol, and browsers need gRPC-Web or a gateway.
Why this question is asked
Most Java developers start with REST, and many first meet gRPC when a platform team introduces it for internal calls. The two can look interchangeable, since both call a remote operation and get a result, but they differ in how contracts are written, how data is encoded, how calls flow over the network and what clients can reach them. Interviewers ask this question to check that we understand those differences, not just the buzzwords. In this answer, we will recap protobuf contracts, compare the encoding and transport, go through the four call types with an example service, look at schema evolution rules, and finish with deadlines and browser support.
1A Quick Recap of Protobuf Contracts
In gRPC, the contract comes first. We write a .proto file that declares messages, the data structures, and services, the operations. A compiler, protoc with the gRPC plugin, generates Java classes for the messages and stubs for the services. On the server we extend a generated base class and implement the methods; on the client we call a generated stub as if it were a local object.
Each field in a message has a name, a type and a field number. The field number, not the name, is what identifies the field on the wire, which is why it is central to compatibility later.
With REST over JSON, the contract is often an OpenAPI document written next to or after the code, and clients may ignore it entirely and parse JSON by hand. With gRPC, there is no way to call the service without the generated code, so the contract is always in use.
2Encoding and Transport Compared
JSON is text: field names are repeated in every message, numbers are written as decimal digits, and the receiver parses strings. Protobuf is binary: each field is written as its number and type in a compact tag, followed by the value, with integers in a variable-length encoding. An Order that is about 50 bytes as JSON is typically around 15 to 20 bytes in protobuf, and parsing it is cheaper because there is no text to scan.
gRPC always runs over HTTP/2. HTTP/2 multiplexes many concurrent calls as streams over one TCP connection, compresses headers, and allows both sides to send data on a stream at the same time, which is what makes gRPC's streaming possible. REST APIs can use HTTP/2 too, but usually behave as one request and one response per call.
| Aspect | gRPC | REST over JSON |
|---|---|---|
| Contract | .proto file, required | OpenAPI, optional in practice |
| Encoding | binary protobuf | text JSON |
| Transport | HTTP/2 always | HTTP/1.1 or HTTP/2 |
| Clients | generated stubs, many languages | any HTTP client, often hand-written |
| Streaming | four call types built in | request-response; SSE or WebSocket aside |
| Deadlines | in the protocol (grpc-timeout) | per-client timeouts only |
| Browsers | need gRPC-Web or a gateway | native |
3The Four Call Types
A service method can stream in either direction, both or neither. The stream keyword in the .proto file says which.
Unary is the familiar request and response, the equivalent of a REST call. Server streaming lets the client send one request and receive a series of responses, for example every status change of an order until it is delivered. Client streaming is the reverse: the client sends many messages, such as 10,000 items to import, and the server answers once with a summary, which avoids 10,000 separate calls. Bidirectional streaming opens a channel where both sides send messages independently, as in a chat or a live negotiation between services.
In grpc-java, streaming methods use a StreamObserver: the server calls onNext for each message and onCompleted at the end, and the client does the same for client streaming. All four types run over a single HTTP/2 stream, so they share the same connection, security and deadlines.
4Schema Evolution Rules
Because fields are identified by number, protobuf can evolve safely if we follow its rules. Adding a new field with a new number is safe: old readers skip unknown fields, and new readers see the default value when the field is missing. In proto3, scalar fields have no presence by default (a missing int is just 0), so when we need to know whether a value was set, we declare it with the optional keyword.
Breaking changes are the ones that change the meaning of a number. We never reuse a field number for a different field, never change a field's type in an incompatible way, and when we remove a field we reserve its number and name so nobody reuses them by accident.
These rules are stricter than most REST teams apply to JSON, and that is a strength: tools such as buf can check every change for breaking violations in CI.
5Deadlines, Cancellation and Browser Support
In gRPC, a client sets a deadline, the point in time by which it needs an answer, and the deadline travels with the call in the grpc-timeout header. The server can see how much time is left and stop work when it has expired; if the server calls other services, grpc-java can pass the remaining deadline along through its Context. If the client cancels, the server is notified. REST has no standard equivalent; each client sets its own timeout, and the server keeps working after the client has given up.
Browsers are the main limitation. Browser JavaScript cannot control HTTP/2 framing and trailers the way gRPC needs, so a browser cannot call a gRPC service directly. gRPC-Web is a variant protocol that browsers can use, translated by a proxy such as Envoy, and gateways can also transcode REST and JSON requests into gRPC calls. That is why many companies use gRPC internally and REST or GraphQL at the edge.
6Follow-up questions
Is gRPC always faster than REST?
Per message, it is usually smaller and cheaper to parse, and HTTP/2 multiplexing avoids connection overhead. But for many business services, the time is spent in databases and other calls, so the difference in end-to-end latency can be small. The bigger benefits are often the typed contract, generated clients and streaming, rather than raw speed.
What happens if an old client receives a message with a new field?
The old client's generated code does not know the field number, so it skips the field while parsing and keeps working. That is why adding fields is backward compatible. Recent protobuf versions also keep unknown fields when a message is re-serialised, so a proxy-like service does not lose them.
Why do enums start with an UNSPECIFIED value?
Because in proto3 the default for an enum field is its zero value. If 0 meant PAID, a missing status would look like a paid order. Making 0 an explicit UNSPECIFIED value means "not set" is distinguishable from every real state.
7Conclusion
In this answer, we compared gRPC with REST over JSON. gRPC starts from a protobuf contract, encodes messages in compact binary, runs on HTTP/2 and generates client and server stubs, while REST usually relies on text JSON and looser contracts. We went through the four call types, unary, server streaming, client streaming and bidirectional streaming, the evolution rules that keep contracts compatible (new field numbers, never reuse, reserve removed numbers), deadlines and cancellation built into the protocol, and the need for gRPC-Web or a gateway for browsers.
Open with
The main difference is that gRPC is contract first. I define messages and services in a .proto file, and protoc generates the message classes and client and server stubs, so clients in any language call typed methods instead of building JSON by hand.
Then, if they want more
Messages are encoded as binary protobuf, which is smaller and cheaper to parse than JSON, and gRPC always runs over HTTP/2, which multiplexes many calls on one connection and allows streaming.
There are four call types: unary, one request and one response; server streaming, one request and a stream of responses, like watching an order's status; client streaming, many messages in and one summary out, like an import; and bidirectional streaming, where both sides send independently, like a chat.
For evolution, fields are identified by number, not name, so I can add new fields freely because old readers skip unknown ones, but I must never reuse or change a field number, and when I remove a field I reserve its number and name.
Deadlines are part of the protocol, sent in the grpc-timeout header, so servers know when to stop and can propagate the remaining time, and cancellation reaches the server too.
The main limitation is browsers: they cannot speak gRPC directly, so we need gRPC-Web through a proxy or a REST gateway, which is why gRPC is mostly used for internal service-to-service calls.
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.
- Official documentation
- Spring Framework reference, Spring Web MVC
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 "What are the main differences between gRPC and REST over JSON, and what are the four...": https://scrivio-interview-library.netlify.app/spring-boot/web-other/2aa6af37de/