What is the difference between REST and gRPC?
REST (Representational State Transfer) and gRPC are both approaches for building networked APIs, but they make fundamentally different tradeoffs optimized for different contexts.
REST is an architectural style built on HTTP semantics: resources are identified by URLs, operations are expressed with HTTP verbs (GET, POST, PUT, DELETE, PATCH), and representations are typically JSON or XML. REST is stateless, cacheable (GET responses can be cached at HTTP layer), and leverages existing HTTP infrastructure. Its strength is interoperability and accessibility: any client that speaks HTTP can call a REST API without a generated client — browsers, curl, Python's requests, all work natively. REST APIs are self-documenting through URL structure and HTTP conventions, and humans can understand and debug them with basic tools.
gRPC is a Remote Procedure Call framework from Google, built on HTTP/2 and Protocol Buffers (protobuf). Instead of resources and verbs, you define services and methods in a `.proto` schema file. protoc generates strongly typed client and server stubs in your target language. Messages are binary-encoded (not human-readable text), making them ~5-7x smaller than equivalent JSON and faster to serialize/deserialize. HTTP/2 enables multiplexed streams over one connection, bidirectional streaming, and header compression.
The four communication patterns gRPC supports that REST doesn't match natively: unary RPC (one request, one response — REST equivalent), server streaming (one request, stream of responses — REST needs SSE/chunked), client streaming (stream of requests, one response), and bidirectional streaming (both sides stream independently — no REST equivalent without WebSockets).
When to choose REST: public-facing APIs where clients are diverse and unknown, APIs that benefit from HTTP caching, web browser clients (gRPC-Web exists but adds complexity), when developer experience and discoverability matter more than raw performance.
When to choose gRPC: internal service-to-service communication in microservices architectures, high-throughput low-latency APIs (real-time systems, ML inference), when you need strong typing and generated clients to reduce integration bugs across team boundaries, or when you need streaming.
Contract enforcement is a key gRPC advantage: the .proto file is a formal contract. Breaking changes are caught at code generation time. REST with OpenAPI approximates this, but JSON's dynamic nature means runtime type errors are more common.
| Aspect | REST | gRPC |
|---|---|---|
| Protocol | HTTP/1.1 or HTTP/2 | HTTP/2 only |
| Payload format | JSON/XML (text, human-readable) | Protocol Buffers (binary, compact) |
| Interface definition | OpenAPI (optional) | .proto file (required, generates stubs) |
| Streaming | Limited (SSE, chunked transfer) | Native: unary, server, client, bidirectional |
| Browser support | Native | Requires gRPC-Web proxy |
| Performance | Good, higher overhead per message | High — binary encoding, HTTP/2 multiplexing |
| Best for | Public APIs, browser clients, CRUD | Internal services, high-throughput, streaming |
Correctly distinguishes the protocol/format differences (HTTP+JSON vs HTTP/2+protobuf), explains the type safety and code generation benefits of gRPC, and gives appropriate use cases for each.
All of the above plus: explains all four gRPC communication patterns (especially streaming), discusses HTTP/2 multiplexing benefits, mentions browser limitations of gRPC, and articulates the contract enforcement advantage of .proto files.
Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.
Get Graded — Free Assessment