This walkthrough explains how to design YouTube live comment and live comments delivery with scalable fan-out and low-latency reads.
Live commenting on Youtube allows viewers to continuously share messages during a broadcast, creating a stream of user interactions that updates almost instantly as the video is happening.
Functional Requirements
- Users can view live comments while watching live video
- Users can type in comments and see their comment in the live video comment section
- Users can scroll down to view past comments of the live video
Non-Functional Requirements
- The system should prioritize availability over consistency, eventual consistency is acceptable
- The system must be able to handle millions of simultaneous live streams, with each stream potentially receiving thousands of comments per second.
- Comment delivery should be low-latency, ensuring updates reach viewers in near real time (typically within ~200ms under normal network conditions).
Data Model
- User: Represents participants in the system, who may act as viewers or broadcasters.
- Live Video: An active video stream created by a broadcaster. While managed by a separate service, it is a key dependency for the commenting system.
- Comment: A message submitted by a user during a live stream, associated with a specific live video.
API Design
- We need a GET endpoint to get live comments for a live video
GET /comments/:liveVideoID?cursor={lastCommentID}&pageSize=10 - We need a POST endpoint to make comments for a live video
POST /comments/:liveVideoID/
We don’t pass userId in the request body because client input is not trustworthy and can be easily manipulated. Instead, we rely on JWT or session tokens, which are validated by the server. The server extracts the user identity from the token, ensuring secure and consistent authentication.