System Design Notebook / 07
Real-Time Backends
What it costs to let the server speak first
Polling, long polling, SSE and WebSockets, priced honestly. The proxies that eat your stream, the six-connections-per-origin limit, and what any of it does to a server you have to keep running.
- pages
- 90
- sections
- 49
- editions
- Reading, Print, Tablet
Sign in to read it
Sign in and the whole notebook opens, all three editions with it. An account is what makes a download belong to someone.
Sign in with GitHub or GoogleStart reading
How to use this book
What is inside
Every section, and every one of them opens in the browser. Nothing here is hidden: if a section you need is not in this list, the notebook is not the right one and you should not spend a week on it.
- How to use this book
- The whole picture on one page
- 1The requirement: two people, one board
- 2The shape of every request you have written so far
- 3Polling, and why it is not stupid
- 4The arithmetic of polling
- 5Long polling, and the gap
- 6The two inversions
- 7A 200 that does not close
- 8The wire format: four fields and a blank line
- 9Reconnection you did not write
- 10Why nobody streams an LLM with EventSource
- 11The proxy that eats your stream
- 12Six connections per origin
- 13What SSE cannot do
- 14The handshake, byte by byte
- 15What 101 actually changed
- 16The frame
- 17Masking, and the proxy it was designed to protect
- 18Ping, pong, and the connection that is already dead
- 19Close codes, and the one you cannot send
- 20Choosing: polling, long polling, SSE, WebSocket
- 21Ceiling 1: file descriptors
- 22The thousand-descriptor limit is language-dependent
- 23Ceiling 2: the client's ports, not the server's
- 24Ceiling 3: memory, and where 10 KB goes
- 25The ceiling the benchmark did not measure
- 26Compression, and the budget it destroys
- 27What you just broke
- 28Sticky sessions are not the answer, and not for the reason you think
- 29Pub/sub: the instances talk to each other
- 30Redis pub/sub is at-most-once, and deploys are when it bites
- 31Ordering, and why sequence numbers come first
- 32The catch-up protocol
- 33Fan-out: events times subscribers
- 34Coalescing: the other lever
- 35The reconnect storm
- 36Deploys: draining a connection that never ends
- 37Authenticating a socket
- 38The token that never expires
- 39Cross-site WebSocket hijacking
- 40Presence: who is online
- 41Collaborative editing, in one page
- 42Where this goes next: WebTransport
- 43The delivery script
- 44Whiteboard drawing order
- 45Follow-up question bank
- Appendix A. Numbers to memorise
- Appendix B. Glossary
- Appendix C. Self-test
How to read it
Read with a pen. Every notebook opens with a question to answer before you start and asks you to redo the answer at the end, and the margin in the Print edition exists so you have somewhere to be wrong first. The Tablet edition is 16:9 with vector text, so note apps draw on it rather than treating it as a photograph.