Lesson 11 of 16
40. Design Video Upload and Streaming (YouTube)

40.10 How do you count views?

3 min read+10 XP

A view count must be cheap (billions of events a day), roughly live, and hard to inflate:

  • The player sends a view event after meaningful watching (the chapter's code uses an assumed 30 seconds).
  • De-duplicate per viewer and video within a window: refreshing the page shouldn't add views. In the chapter's code, a refresh within 30 minutes and a 5-second watch are not counted; a return after the window is.
  • Count in sharded counters (many small counters per hot video, Chapter 13's hot keys), flushed to the stored total every few seconds or minutes.
  • Run fraud detection asynchronously (bots, click farms) and subtract invalid views later; the public count can lag.
  • Exact numbers for creator payouts come from a separate, audited pipeline over the event log, like Chapter 35's final job.

Memory code: "Count real watches once per viewer, in shards, and audit the money later."