Design a Timeline-Anchored Live Reaction Stream
System DesignModel answerLast updated
Design a system that attaches viewer comments to specific moments on a video timeline, staying synchronized across live watching, replay, seeking, and reconnection.
Timeline-Anchored Live Reaction Stream
A popular streaming platform wants to add a feature where viewers can post short text reactions that appear as a floating overlay tied to a specific moment in a video. A comment posted at the two-minute mark should appear for every viewer — live or replaying — when they reach that same moment, not when it was originally submitted.
Design the backend and client protocol for this feature end-to-end.
What to cover
- Publish and read APIs: how clients submit a comment and how they pull or receive comments
- Timeline semantics: what timestamp anchors a comment — wall-clock time, media position, or some combination — and why the choice matters
- Ordering guarantees: what "same order for all viewers" means in practice and what it costs
- Real-time delivery: the fanout path from one publisher to potentially millions of concurrent viewers
- Storage and replay: how comments are stored so a viewer who seeks to an arbitrary position gets the right comments quickly
- Moderation and abuse controls: pre-publish filtering, post-publish removal, and per-user blocking
- Backpressure and load shedding: what happens when comment volume spikes beyond what clients can render
- Client synchronization: reconnect cursors, deduplication, and handling clock skew between client and server
Constraints and assumptions
- A single live event can attract a very large concurrent audience; comment bursts during exciting moments are expected
- Viewers may pause, seek backward or forward, lose connectivity, or join mid-stream
- The overlay must remain usable under extreme load — rendering every accepted comment is not required
- The same underlying design should support both live events and on-demand replay of past events
Clarifying questions a strong candidate would raise
- Is the canonical position the server's wall-clock time, a media presentation timestamp (PTS), or an event-relative offset in seconds?
- Do all viewers need to see comments in exactly the same order, or is approximate consistency acceptable?
- What are the latency, geographic distribution, and retention requirements?
- Are secondary features — reactions, replies, creator pinning, profanity filters — in scope?
Hints
Hint 1
Start by settling on what a comment's timestamp actually means. A comment anchored to a media position offset (e.g., T+92 seconds from event start) survives seeks and replay in a way that wall-clock time alone does not — nail this before touching any infrastructure.
Hint 2
The read path and the write path have very different scaling shapes. The write path is one producer per comment; the read path fans out to potentially millions of subscribers. Think about where to break that fanout — push-based pub/sub, pull-based polling with a cursor, or a hybrid — and what each costs in latency and infrastructure complexity.
Hint 3
For replay and seeking, think in time buckets. Storing comments indexed by a quantized timeline offset (e.g., per-second or per-5-second bucket) lets you answer 'give me all comments between T+90s and T+120s' with a bounded, predictable read. Consider how you'd handle a viewer who rapidly scrubs through the timeline without overwhelming storage.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Clarifications worth settling first
Before designing anything, pin down two decisions that cascade everywhere:
-
Canonical timestamp: use a media-relative offset in milliseconds from the event start (e.g.,
event_offset_ms: 92400). Wall-clock time is unsuitable as a primary key because it breaks for replay, scrubbing, and events that pause or restart. The server converts the client-submitted playback position to this offset at ingest time, discarding client clock drift. -
Ordering guarantee: globally strict ordering (every viewer sees the same sequence) requires a single sequencer and is expensive at scale. Approximate ordering — comments at roughly the same offset appear in a consistent but not globally identical order — is almost always acceptable and far cheaper. Commit to this trade-off explicitly.
Write path
Client API: POST /events/{event_id}/comments with body { text, client_offset_ms }. The server assigns a stable comment_id (a ULID or a Snowflake ID that encodes server timestamp), stores the authoritative server_offset_ms, and publishes to a durable message bus (Kafka or a managed equivalent).
Ingest service responsibilities:
- Validate length and rate limits (e.g., one comment per user per 2 seconds via a token bucket in Redis)
- Run a synchronous fast-path abuse filter (blocklist, length check)
- Write to the bus; return
202 Acceptedimmediately. The client does not wait for fan-out or moderation.
Moderation: an async worker consumes from the bus, applies ML classifiers and human review queues, and marks comments as approved, pending, or removed. Removed comments are tombstoned — never physically deleted — so replay consistency is preserved. Clients receive a comment_removed event over the same delivery channel.
Storage
Use a time-series–friendly store (Cassandra or DynamoDB) with a partition key of (event_id, bucket) where bucket = floor(server_offset_ms / 5000) — five-second windows. The clustering/sort key is comment_id (monotonic). This layout supports:
- Append: one write to the correct bucket.
- Range query for replay/seeking: fetch all rows in buckets covering
[seek_offset - ε, seek_offset + window]— typically two or three bucket reads. - Cursor-based live delivery: a viewer's last-seen
comment_idis their resume point.
For very high-traffic events, add a read-through cache (Redis sorted set per bucket keyed by offset) with a short TTL. Cache misses fall through to the durable store.
Read / fanout path
Two delivery modes share the same comment stream:
Live viewing — WebSocket or HTTP/2 server-sent events. The viewer connects, the server subscribes them to a fan-out topic for that event (e.g., via Redis Pub/Sub or a purpose-built fan-out service). The server pushes comment events as they are approved. Keep-alive pings double as health checks.
Replay / seeking — When a viewer seeks to offset T, the client sends GET /events/{event_id}/comments?from_offset_ms=T&limit=50. The server reads the relevant buckets and returns a page. The client then switches to WebSocket delivery anchored at the last received comment_id.
Backpressure: at high comment rates, the server-side fan-out layer samples before pushing. A simple strategy: if the inbound rate exceeds a configurable threshold (e.g., 200 comments/second per channel), hash each comment_id modulo N and only forward 1-in-N. The client overlay renders those; viewers experience density, not completeness. An alternative is rank-based filtering: surface only comments with high engagement signals (reply count, reaction velocity).
Client synchronization
- Reconnect: the client stores its last received
comment_idin memory. On reconnect it sends that cursor; the server replays missed comments from the durable store before resuming live push. - Deduplication: comments carry a stable
comment_id. The client keeps a small LRU set of recent IDs and drops duplicates silently. - Clock skew: the client reports
client_offset_msas the player's current position, not a wall-clock timestamp. The server trusts its own clock forserver_offset_msand treats the client value as advisory.
Graceful degradation
| Failure | Mitigation |
|---|---|
| Fan-out service overload | Drop push; clients fall back to polling every 2 s |
| Storage latency spike | Return cached bucket data; serve stale for a few seconds |
| Moderation pipeline lag | Show comments in a "pending" visual state; promote on approval |
| Regional outage | Route to nearest healthy region; accept temporary comment loss for live, replay is unaffected |
Common mistakes to avoid
- Anchoring to wall-clock time: breaks replay and any event that pauses. Always use a media-relative offset.
- Promising strict global ordering: it requires a serialization point that becomes a bottleneck. Approximate ordering is the right default; say so.
- Skipping tombstones: physically deleting moderated comments creates consistency gaps for replaying viewers.
- Ignoring backpressure: at 50k concurrent commenters a single exciting moment can produce thousands of comments per second. Without sampling or rate shaping, the client overlay becomes a blur and the fan-out tier falls over.
- No cursor on reconnect: without a resume cursor, reconnecting clients either miss comments or re-fetch everything from the start — both are wrong.
Complexity snapshot
| Operation | Latency target | Notes |
|---|---|---|
| Comment ingest (p99) | < 100 ms | Async moderation; 202 response |
| Live push (p99) | < 500 ms end-to-end | Includes moderation fast path |
| Seek / replay query | < 200 ms | 2–3 bucket reads, cache-assisted |
| Reconnect replay | < 1 s for last 30 s | Cursor-based, bounded read |