SDE & MLE Prep

Live Comments (Facebook Live / Twitch Chat)

Requirements: viewers of a live video see new comments in real time (< 1–2 s); millions of viewers on popular streams; comments also stored.

commenter -> comment svc -> store (Cassandra, partition = video_id) + publish to pub/sub topic(video_id)
                                                                          |
                          gateway servers (hold SSE/WebSocket connections) subscribe per video they serve
                                                                          |
                                                               fan-out to their local viewers

Deep dives: two-level fan-out — the pub/sub layer fans out to gateway servers (hundreds), each gateway fans out to its local connections (thousands); gateways subscribe only to videos their viewers watch (dynamic subscription registry); for mega-streams sample/aggregate comments and rank them; SSE is enough (server → client), WebSockets if clients send often; backpressure for slow clients.