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
Sign in to read it
The whole notebook is free for 7 days. No card, no payment. We ask for an account so the download link belongs to someone.
Sign in with GitHub or GoogleWhat is inside
The full table of contents. 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.
- The whole picture on one page
- 1. The requirement: two people, one board
- 2. The shape of every request you have written so far
- 3. Polling, and why it is not stupid
- 4. The arithmetic of polling
- 5. Long polling, and the gap
- 6. The two inversions
- 7. A 200 that does not close
- 8. The wire format: four fields and a blank line
- 9. Reconnection you did not write
- 10. Why nobody streams an LLM with EventSource
- 11. The proxy that eats your stream
- 12. Six connections per origin
- 13. What SSE cannot do
- 14. The handshake, byte by byte
- 15. What 101 actually changed
- 16. The frame
- 17. Masking, and the proxy it was designed to protect
- 18. Ping, pong, and the connection that is already dead
- 19. Close codes, and the one you cannot send
- 20. Choosing: polling, long polling, SSE, WebSocket
- 21. Ceiling 1: file descriptors
- 22. The thousand-descriptor limit is language-dependent
- 23. Ceiling 2: the client's ports, not the server's
- 24. Ceiling 3: memory, and where 10 KB goes
- 25. The ceiling the benchmark did not measure
- 26. Compression, and the budget it destroys
- 27. What you just broke
- 28. Sticky sessions are not the answer, and not for the reason you think
- 29. Pub/sub: the instances talk to each other
- 30. Redis pub/sub is at-most-once, and deploys are when it bites
- 31. Ordering, and why sequence numbers come first
- 32. The catch-up protocol
- 33. Fan-out: events times subscribers
- 34. Coalescing: the other lever
- 35. The reconnect storm
- 36. Deploys: draining a connection that never ends
- 37. Authenticating a socket
- 38. The token that never expires
- 39. Cross-site WebSocket hijacking
- 40. Presence: who is online
- 41. Collaborative editing, in one page
- 42. Where this goes next: WebTransport
- 43. The delivery script
- 44. Whiteboard drawing order
- 45. Follow-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.