What is the difference between REST and gRPC?
Compare REST and gRPC: JSON vs Protocol Buffers, HTTP/1.1 vs HTTP/2, streaming, contracts and browser support, with examples and interview questions.
Expected Interview Answer
REST is a resource-oriented style that sends human-readable JSON over HTTP/1.1, while gRPC is a high-performance RPC framework that sends compact binary Protocol Buffers over HTTP/2 and calls remote methods directly.
gRPC uses a strict .proto contract to generate typed client and server code, and its HTTP/2 foundation enables multiplexing and streaming (client, server, and bidirectional). REST is text-based, loosely typed, and universally supported by browsers and tools, making it easy to debug and cache. gRPC is faster and smaller on the wire and excels at internal service-to-service communication, but needs extra tooling (like gRPC-Web or a proxy) to work directly in browsers.
- gRPC's binary Protobuf is smaller and faster than JSON
- gRPC supports streaming and multiplexing over HTTP/2
- gRPC generates typed code from a .proto contract
- REST is human-readable and easy to debug
- REST works natively in browsers and caches over HTTP
AI Mentor Explanation
REST is like the public scoreboard everyone in the stadium can read at a glance — clear, human-friendly numbers anyone understands. gRPC is like the coded signals between captain and bowler: compact, pre-agreed gestures that pass rich instructions in an instant. The signals are far faster and denser, but only those who share the codebook can interpret them, unlike the open scoreboard.
Step-by-Step Explanation
Step 1
Compare the paradigm
REST is resource-oriented around URLs; gRPC calls remote methods (procedures) directly.
Step 2
Look at the wire format
REST sends text JSON; gRPC sends compact binary Protocol Buffers, smaller and faster.
Step 3
Examine the transport
REST commonly uses HTTP/1.1; gRPC requires HTTP/2, enabling multiplexing and streaming.
Step 4
Consider contracts and codegen
gRPC generates typed clients from a .proto file; REST relies on optional OpenAPI docs.
Step 5
Match to use case
gRPC shines for internal microservices; REST suits public, browser-facing APIs.
What Interviewer Expects
- Understanding RPC versus resource-oriented design
- Knowing Protobuf binary versus JSON text trade-offs
- Awareness of HTTP/2 features and streaming
- Knowing gRPC's browser limitations and gRPC-Web
- Ability to choose based on internal versus public APIs
Common Mistakes
- Saying gRPC works natively in all browsers
- Claiming REST cannot stream at all
- Ignoring gRPC's .proto contract and code generation
- Assuming binary always beats JSON regardless of context
Best Answer (HR Friendly)
“REST sends easy-to-read JSON over the web and works everywhere, while gRPC sends compact binary messages over a faster connection and directly calls functions on another server. gRPC is quicker for services talking to each other; REST is simpler and browser-friendly.”
Code Example
// gRPC: typed contract, binary over HTTP/2
service UserService {
rpc GetUser (UserRequest) returns (User);
}
message UserRequest { int32 id = 1; }
// REST: text JSON over HTTP/1.1
// GET /users/42 -> { "id": 42, "name": "Ada" }Follow-up Questions
- Why does gRPC require HTTP/2 and what does that enable?
- How do Protocol Buffers compare to JSON in size and speed?
- What is gRPC-Web and why is it needed for browsers?
- What types of streaming does gRPC support?
- When would you prefer REST over gRPC for an API?
MCQ Practice
1. What serialization format does gRPC use by default?
gRPC uses Protocol Buffers, a compact binary format, which is smaller and faster than text JSON.
2. Which transport does gRPC require?
gRPC is built on HTTP/2, enabling multiplexing and bidirectional streaming.
3. Why can't standard gRPC be called directly from most browsers?
Browsers cannot control the low-level HTTP/2 frames gRPC needs, so gRPC-Web or a proxy is required.
Flash Cards
gRPC paradigm? — Remote procedure calls — invoking methods on a server directly.
gRPC wire format? — Binary Protocol Buffers, compact and fast.
gRPC transport? — HTTP/2, enabling multiplexing and streaming.
Browser gRPC? — Needs gRPC-Web or a proxy; not natively callable.