Lesson 17.10 · 27 min · video lesson
Transport Protocols: HTTP, WebSockets, and SSE Compared
HTTP lets a browser ask a server questions, but how does the server tell the browser "you have a new message" the instant it arrives?
In short: Plain HTTP is request-response: the client asks, the server answers, and the server cannot speak first. Polling asks again and again on a timer; long polling keeps each request open until there is news; WebSocket upgrades one connection into a two-way channel; Server-Sent Events keep one HTTP response open and stream text events from server to client. They trade simplicity, latency, server load and direction of data, and LLM token streaming usually uses SSE.
What you will learn
- HTTP request
- HTTP Polling
- HTTP Long Polling
- WebSocket
- Server-Send Events(SSE)
In this lesson
- The problem: servers cannot speak first
- HTTP request: ask, answer, done
- HTTP polling and HTTP long polling
- WebSocket: a two-way channel
- Server-Sent Events (SSE): one-way streaming over HTTP
- Code: measuring requests and delay
- Side by side: which one when?
- Common mistakes and practical tips
- Worked example, step by step
- Practice: try it yourself
Key terms in this lesson
- HTTP polling
- The client repeatedly sends requests on a timer to check for new data.
- Long polling
- The server holds a request open until data is available or a timeout, then the client re-requests.
- WebSocket
- A protocol that upgrades an HTTP connection into a persistent two-way channel of frames.
- Server-Sent Events (SSE)
- A one-way stream of text events from server to client over a single HTTP response (text/event-stream).
- Full duplex
- Both sides can send at the same time, independently.
- EventSource
- The browser API that opens an SSE stream, parses events and reconnects automatically.
This lesson is part of the Generative AI Engineering and Complete AI Engineer tracks. See plans and pricing to open the full lesson, its video, labs and quiz, or try the free lesson first (free account needed).
← 17.9 System Design: HLD, LLD and UML Diagrams with Interview Questions · 17.11 How do Voice And Video Call Work? →