Sign in to keep reading
“Distributed Counters” is free with an account. Your progress and bookmarks follow you across devices.
Sign in to continueDesign YouTube View Counter - This system design covers distributed counting at scale, idempotent event ingestion, hotspot mitigation, and near real-time serving with strong correctness guarantees.
Written by a Staff+ Engineer and an Engineering Manager
10+ years of experience in low-latency streaming and AI infrastructure. Tech lead for real-time LLM serving platforms handling millions of concurrent requests. Over 12 years of industry experience with 6 years in engineering leadership, building and scaling tech infrastructure teams that deliver end-to-end large-scale distributed systems.
“Distributed Counters” is free with an account. Your progress and bookmarks follow you across devices.
Sign in to continueChallenge Yourself
Could you answer these today? Tick what you already know.
Design a backend system that powers YouTube long-form video view counters.
Key user behaviors (what the system should provide)
FR1 — Ingest view events
Accept view signals for a video_id and persist them so the system can later decide whether a view should be counted.
FR2 — Serve view counts (watch page)
Provide GetViewCount(video_id) to return the public view count quickly and reliably for end users.
NFR1 — Correctness
video_id (including the same shard), increments must not overwrite each other.NFR2 — Latency / Freshness
GetViewCount(video_id) latency: p95 ≤ 50 ms, p99 ≤ 150 msNFR3 — Scale / Hotspot Resistance
video_id without a single partition/shard meltingGetViewCount via caching/edge servingNFR4 — Availability > Consistency
So under partition:
What we "give up" (and how we contain it)?
Requirement Summary
| Functional Requirements (FRs) | |
|---|---|
| Name | Description |
| 1. Ingest View Events | Accept view signals for a video_id and persist them so the system can later decide whether a view should be counted. |
| 2. Serve View Counts | Provide GetViewCount(video_id) to return the public view count quickly and reliably for end users. |
| Non-Functional Requirements (NFRs) | |
|---|---|
| Name | Description |
| 1. Correctness | No double-counting on retries; no lost updates under concurrency. |
| 2. Latency / Freshness | GetViewCount p95 ≤ 50 ms, p99 ≤ 150 ms; freshness p95 ≤ 2 s, p99 ≤ 5 s. |
| 3. Scale / Hotspot Resistance | Peak ingest ≥ 200K events/sec; hot video ≥ 50K increments/sec for a single video_id. |
| 4. Availability > Consistency | AP: always accept events and serve counts, even during partitions; converge via event-log + rollups. |