REST vs gRPC¶
REST — HTTP/JSON, resource-oriented, widely used for public APIs. Stateless, cacheable, easy to debug. gRPC — HTTP/2 + Protocol Buffers (binary), fast, strongly typed, streaming. Best for internal microservice communication. Choose REST for simplicity and external APIs, gRPC for performance-critical internal services.
Key Concepts¶
Deep Dive: Detailed Comparison
| Feature | REST | gRPC |
|---|---|---|
| Protocol | HTTP/1.1 or 2 | HTTP/2 |
| Format | JSON (text) | Protobuf (binary) |
| Contract | OpenAPI (optional) | .proto file (required) |
| Performance | Good | Excellent (10x faster) |
| Streaming | Limited (SSE) | Bidirectional |
| Browser support | Native | Requires gRPC-Web |
| Code generation | Optional | Built-in |
| Caching | Easy (HTTP cache) | Complex |
| Debugging | Easy (readable JSON) | Hard (binary) |
Deep Dive: When to Use Each
Use REST: - Public/external APIs - Web/mobile frontends - Simple CRUD operations - When caching is important - When human readability matters
Use gRPC: - Internal microservice communication - High-performance, low-latency - Streaming data (real-time feeds) - Polyglot environments (auto-generated clients) - When strong typing is important
Common Interview Questions
- What is gRPC? How is it different from REST?
- What are Protocol Buffers?
- When would you choose gRPC over REST?
- What is bidirectional streaming?
- Can browsers use gRPC directly?