04
When to pick what — deeper context
REST — not just CRUD
REST over HTTP/2 is faster than people assume. With gzip/brotli compression and connection multiplexing, the JSON overhead shrinks significantly. REST shines when you need HTTP caching (CDN, browser cache, reverse proxy), hypermedia discovery, and broad tooling support. For 80% of systems, REST is the right default.
gRPC — the microservices backbone
Google, Netflix, and Uber use gRPC for internal communication. The protobuf schema acts as an enforced contract between teams. Streaming RPCs (server-streaming, client-streaming, bidirectional) handle patterns that would require WebSocket in REST-land. The main pain point: debugging binary payloads is harder than JSON.
GraphQL — powerful but complex
GraphQL solves real problems (over-fetching, under-fetching, API versioning) but introduces new ones: query cost analysis (prevent expensive queries), caching complexity (no HTTP cache by default), and schema governance. Best when you have many client types with different data needs. Overkill for a single client consuming a single backend.
WebSocket — connection management is the hard part
The protocol is simple; the operations are hard. At scale, you need: (1) a pub/sub layer (Redis, Kafka) to fan messages across WebSocket servers, (2) connection state management (which user is on which server), (3) graceful reconnection handling. Load balancers need sticky sessions or connection-aware routing.
SSE — the underrated option
SSE is often overlooked in favor of WebSocket, but for server-push-only patterns (notifications, live feeds, progress updates), SSE is simpler: standard HTTP, automatic reconnection, works through most proxies. ChatGPT's streaming response uses SSE. Use it when you don't need the client to send data back over the same connection.
Combining protocols
Production systems typically use multiple protocols: REST for the public API gateway + gRPC between internal services + WebSocket for real-time features + SSE for streaming responses. Articulate this layering in interviews.