Communication Protocols: HTTP/REST, WebSocket & RPC
Request-response covers most client-server traffic — until a feature needs the server to speak first.
Intermediate
GET /restaurants?near=94103 -> 200 OK, list of restaurants
POST /orders -> 201 Created, the new order
GET /orders/482 -> 200 OK, order 482's details
PATCH /orders/482 {"status":"cancelled"} -> 200 OK, updated order
| Approach | How it works | Downside |
|---|---|---|
| Polling | The client re-sends a GET request every few seconds, hoping for new data. | Wastes bandwidth and server load on requests that usually return "nothing changed." |
| Long polling | The server holds the request open for up to some timeout, responding as soon as new data exists (or on timeout). | Better, but still re-establishes a new HTTP request/response cycle for every update, and ties up a server thread/connection per waiting client. |
| WebSocket | After an initial HTTP handshake, the connection is upgraded to a persistent, bidirectional channel — either side can send a message at any time. | The server must hold open one connection per active client, which is a real cost at large scale. |
getDeliveryEstimate(orderId) — hiding the network round-trip behind an interface that looks local. Frameworks like gRPC use this pattern along with a compact binary format (protocol buffers) instead of JSON, trading some human-readability for lower latency and smaller payloads.| Situation | Best fit |
|---|---|
| Public API, client-driven requests | HTTP/REST |
| Server needs to push updates without being asked | WebSocket |
| High-throughput internal service-to-service calls | RPC (e.g. gRPC) |
| Tight budget, moderate throughput, simplicity matters | HTTP/REST |