Design a Page View Counter

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.

Functional requirements

  • Record a view for a page or video, ignoring obvious repeats and bots
  • Show the current view count for a page, quickly and cheaply
  • Count views in memory and write them to the database in batches, so one popular page does not hammer a single database row
  • Keep views in a durable queue so a crash loses at most the last few seconds of counts
  • Never let a count go backwards, even after a restart or a retry
  • Throttle bots and repeated views from the same client

Non-functional requirements

  • Recording a view < 50ms p99; reading a count < 50ms p99 from the counter cache
  • Handle 10K requests per second at peak, about 90% views; a single viral page can take 5K views per second
  • Counts may lag by up to a minute but never go backwards
  • 99.9% of views are eventually counted (at-least-once delivery with de-duplication)
  • Database writes are batched, so total write load grows with pages, not with views
  • Scale to 1B views per day
  • 99.9% availability for recording; reading a count can fall back to the last known total

How the design evolves

Stage 1: One Row Per Page

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.

Stage 2: In-Memory Counters

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.

Stage 3: Batch Writes With a Queue

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.

Stage 4: Bot Protection and Monitoring

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.

PRISM
System Design Interview
Round 1 of 4 · Architecture Design · 60:00 remaining
PRISM logo PRISM logo
Problems
AI Interview
Interview Challenges
Build & Stress Test NEW
System Architectures
Design & Fix NEW
Interactive Roadmap
Problems
Today's mission
Notifications
    Theme
    Pricing Community NEW Send feedback Report a problem NEW
    Sign in
    Theme
    Community NEW Send feedback Report a problem NEW
    All problems
    Phase
    Build & Stress Test
    Phase 01: Thinking in Systems
    Upcoming

    Components

    User
    CDN
    Load Balancer
    Server
    Cache
    Database
    Blob Storage
    Search Index
    Queue
    Worker
    Rate Limiter
    Service
    API Gateway
    Reverse Proxy
    WebSocket Server
    Third-party API

    Inspector

    Notes
    Use clear names so your design intent is easy to understand.
    Good
    Name by business meaning
    "Order API", "Restaurant Service"
    Avoid
    Generic names = zero signal
    "Server 1", "API", "Queue"
    A short description for each component makes feedback much better.
    100%
    Start by identifying:
    • Users & entry points
    • APIs & services
    • Databases & storage
    • Traffic flow & scale

    Round 1 of 4 Architecture Design

    Run a simulation to see results.

    Time Remaining
    60:00
    System Design Interview

    What are the core functional requirements?
    What are the key non-functional constraints?

    Questions

    Start Evaluation to unlock questions.

    Test yourself like it's the real thing.

    Interview prep guide
    Architecture Design
    Draw your system on the canvas. Define components, connections, and data flow.
    FR & NFR Requirements
    Answer functional and non-functional requirement questions about your design.
    MCQ Round
    Multiple choice questions testing your depth on the chosen system.
    Tradeoff Analysis
    Justify your design decisions and defend your architectural tradeoffs.
    AI interviews left 0left
    This week 0 / 0
    Used today 0 / 0

    Choose a Problem
    No problem selected
    • 30 min
    • 45 min
    • 60 min
    Round 2 of 4
    MCQ Round
    Answer multiple-choice questions based on your design.

    Exit Interview?

    You're in the middle of an interview session. Leaving now will end your current attempt.

    Your progress will be saved.

    Open a saved design

    Select a design to load into the canvas.

    My Evaluations

    Your past evaluation sessions

    Here’s a simple request flow that follows the expected layer order.

    External User
    →
    Edge CDN → API Gateway → Load Balancer
    →
    Compute App Servers / Services
    →
    DataAccess Cache
    →
    Storage Database / Search Index
    →
    Async Queue → Worker

    Tip: keep arrows moving forward through layers (Edge → Compute → Storage). Avoid sending storage back to compute.

    Evaluation Instructions

    Read the rules carefully before starting. The test auto-submits on refresh.

    Before you start

    • Build your architecture on the canvas. The timer starts when you click Start Evaluation.
    • Don't forget to answer Functional Requirement and Non Functional Requirements.
    • When satisfied with your design, click Next to lock it and view the questions.
    • Please answer final step questions to complete the evaluation.

    Dos

    • Do read each question carefully before answering.
    • Do include required components to maximize component coverage.
    • Do save a copy of your design if you want to keep it before submission.

    Don'ts

    • Don't refresh or close the tab during an active evaluation — this will auto-submit your answers.
    • Don't switch app modes or open another tab while the evaluation is running.
    • Don't attempt to edit the design after clicking Next; the workspace will be locked.

    All the best!!

    Confirm

    Input

    Notice

    Evaluation Report
    Report a problem

    Evaluation Complete

    Generating Your Report

    Hang tight — our AI is evaluating your design…

    Did you know?

    Loading…

    Share feedback

    Tell us what worked well and what we can improve.

    Let's personalize this

    Answer a couple of quick questions so we can tailor your journey and missions.

    Your welcome gift: of Full PRISM Access

    Your Pro access starts as soon as you press Start my journey.

    SYSTEM BRIEF

    System Constraints

    What the system must do — every item is a user-facing behaviour your architecture must support.

      ↑ Engineering Constraints

      These are the failure modes you must design against — latency SLAs, durability targets, traffic ceilings.

        ⇆ Architecture Constraints

        Core Concepts to Master

        Your Journey
        PHASE – –
        0 / 0 0%
        0
        Mock Interview Checklist

        Pick a topic to start

        Explore concept overviews, real-system examples, key tradeoffs, and interview talking points for each roadmap section.

        Phase Mastered

        You've conquered this phase. These are the skills you now own:

          +500 XP

          Company Interview Paths

          Progress Summary