HTTP, Connections and Real-Time Protocols

Learn the HTTP features that shape system design (methods, status codes, caching headers, HTTP/2 and HTTP/3) and the options for real-time push.

Beginner · about 3 hours · difficulty 2/5

Learn first: Client-Server Model and How the Internet Works

HTTP is the language most of your components will speak, so its details show up in every design discussion.

The parts that matter for design

  • Methods: GET is safe and should be cacheable; PUT and DELETE are idempotent; POST is neither by default. This drives retries and caching.
  • Status codes: 2xx success, 3xx redirect (a URL shortener lives on 301 vs 302), 4xx client error (429 means rate limited), 5xx server error (retry candidates).
  • Headers: Cache-Control, ETag and Last-Modified for caching; Authorization for identity; Idempotency-Key for safe retries.

Versions

  • HTTP/1.1: one request at a time per connection, so browsers open several connections.
  • HTTP/2: many streams multiplexed over one TCP connection, header compression. Head-of-line blocking still exists at the TCP layer.
  • HTTP/3: runs on QUIC over UDP, avoids TCP head-of-line blocking and handles network switches (Wi-Fi to 4G) better.

Getting data to clients in real time

  • Short polling: client asks every few seconds. Simple, wasteful.
  • Long polling: server holds the request until there is news. Works everywhere.
  • Server-Sent Events (SSE): one-way stream from server to client over HTTP. Good for live scores and notifications.
  • WebSockets: full duplex, persistent connection. Used for chat, multiplayer and trading screens.

Persistent connections change your scaling story: a server may hold lakhs of open sockets, and you need a way to route a message to whichever server holds the recipient's connection.

Pitfalls

  • Using POST for everything and losing caching and safe retries.
  • Choosing WebSockets when SSE or polling every 30 seconds would do.

You are ready to move on when you can pick between polling, SSE and WebSockets for a cricket score app, a chat app and an order tracking page, with a reason for each.

Key concepts

  • Methods, safety and idempotency
  • Status codes that matter
  • Caching headers
  • HTTP/2 and HTTP/3
  • Long polling
  • Server-Sent Events
  • WebSockets

Mini project

Build a tiny server that pushes a live counter to the browser three ways (polling, SSE and WebSocket). Measure requests per minute for each with 10 open tabs and write down the trade-offs.

Check yourself

Why is it safe for a client to retry a timed-out PUT but risky to retry a timed-out POST that creates an order?

Free resources