Facebook Live Comments System Design
The prompt sounds like a chat room: "Design the comments system for Facebook Live. While someone is broadcasting, viewers can post comments, and everyone watching sees new comments appear in near real time. Some streams have a handful of viewers; a few have millions."
Everyone can draw the first version: a POST that writes the comment to a database, and a socket per viewer that pushes every new comment to every person watching. That version works for a stream with forty viewers. Point it at a musician going live to five million people and it falls apart. Five million viewers posting about one comment every seventeen minutes produce 5,000 comments a second. Pushing each of them to everyone is 25 billion deliveries a second for one stream, to screens where a person can read maybe ten. The first version's real problem isn't speed. It never asked who reads what.
The Trap Built Into a Familiar Question
Two failures show up again and again:
- The Chat Room: treats Live comments as group chat. Every comment goes to every viewer, ordering is a global sequence, delivery is acknowledged per viewer. It's a fine design for a ten-person room and an impossible one for a five-million-person stream. Signal: hasn't noticed that the hard part is the fan-out, not the write.
- The Firehose Plumber: knows the fan-out is huge and throws machinery at it, with Kafka topics per video, Redis Pub/Sub everywhere and WebSockets for both directions. Then they still try to deliver every comment, which no amount of plumbing makes readable. Signal: scales the pipes without questioning what flows through them.
The passing performance starts from one asymmetry. At peak, 50,000 comments a second come in, an ordinary write load. Out of them come about 150 million deliveries a second to 50 million open connections, because every comment is copied to everyone watching its stream. Most of that fan-out comes from the few huge streams, and that's also where people can't read everything. So the design caps what each viewer receives at about ten comments a second and makes the system choose. A shared broadcast lane carries the best, safety-checked comments for everyone. A personal lane guarantees you see your own comments and your friends', even when a component fails. Underneath, a durable log keyed by video gives every stream an order and a way to resume. A tree of routers, relays and gateways keeps any one machine from pushing ten gigabits a second.
Sign in to continue reading
The rest of this lesson is available with a free account. Signing in with Google or Microsoft is free.
Sign in to read the full lesson