View counter inspired by Reddit and YouTube view counts: record millions of views without hammering one database row, using in-memory counters, a durable event queue and batched writes.
See why updating a database row on every view creates a hot row.
What was missing: Nothing absorbs many writes to the same page.
Why that's risky: A hot page's row is locked by each update, so concurrent views queue behind each other; 9K writes/s on one row means 9K serialized lock waits.
What gets added: One server and one database row per page, incremented with UPDATE on every view.
Trade-offs: Exact and trivially consistent, but throughput stops at the update rate of a single row.
Count views in memory and keep the database for totals only.
What was missing: Every view writes to the database.
Why that's risky: The cache holds views the database has not seen yet, so a cache crash loses them.
What gets added: Counters live in a cache and are bumped with an atomic increment; a read service returns counts from the cache and the database keeps stored totals.
Trade-offs: Counts may trail the database slightly and a crash loses the unsaved window; acceptable because a view count only needs to be approximately right.
Buffer views in a queue and let workers flush totals in batches.
What was missing: Views exist only in memory until something writes them down.
Why that's risky: If workers fall behind, stored totals lag, and a retried batch could count twice unless the database can recognise it.
What gets added: Every view also becomes an event on a queue; flush workers read events in batches, add them up per page and write one update per page to the database every few seconds. Reddit's view counter works this way, saving counts about every 10 seconds.
Trade-offs: Batching cuts database writes by roughly 100x but adds a few seconds between a view and the stored total.
Filter bot traffic and watch the pipeline.
What was missing: Bots can inflate counts and nothing shows when flushing falls behind.
Why that's risky: Without de-duplication one script can add a million fake views, and a view count nobody trusts is worthless.
What gets added: A rate limiter that drops repeat views from the same visitor inside a short window, plus monitoring of flush lag, queue depth and rejected views.
Trade-offs: Remembering every visitor id to count each person once costs about 80 MB for a 10-million-view page; a HyperLogLog sketch estimates unique visitors in about 12 KB with roughly 1% error, which is the trade Reddit made.
You're in the middle of an interview session. Leaving now will end your current attempt.
Explore concept overviews, real-system examples, key tradeoffs, and interview talking points for each roadmap section.
You've conquered this phase. These are the skills you now own: