Preparing your design workspace

Loading the problem and your latest saved attempt…

Design Accurate Video View Counts

Record qualified video-view events once and return exact, reproducible per-video analytics counts with honest coverage.

Problem statement

Design analytics that records views for each video and accurately returns each video's count. For this exercise, assume trusted collectors already determine which observations qualify as views.

They submit immutable events with(video_id,view_id),occurred_at and bounded payload; one distinct qualifying event counts once, while repeated viewing can produce distinct events. The service validates identity and its time policy, durably acknowledges accepted input and returns a stable receipt token.

Identical retries recover the original acceptance; conflicting retained identity reuse is rejected. First admission accepts events up to seven days old and at most five minutes in the future. A collector must never change the content/time of an existing event identity.

Authorized analytics clients query a video's cumulative accepted unique-view count since collection began, or a bounded batch of up to 100 video IDs. Every result is an exact integer for its returned covered log-position watermark, with generation and freshness.

Processing may lag; it must not call an estimate or an incomplete wall-clock total exact. If the caller supplies an acceptance receipt as minimum coverage, return pending until that event is covered.

Retain raw accepted evidence and admission/dedup receipts for 30 days; preserve lifetime totals through durable cumulative checkpoints and a complete later log tail. Deletion must wait if evidence is still required for a valid checkpoint or rebuild.

Design ingestion,idempotency,skew-aware counting,query storage,coverage,backpressure and recovery. Video playback,media storage,top-N ranking,distinct-viewer estimates,view-qualification policy,fraud detection and advertising are outside scope.

What to build

  1. Trusted collectors record one qualified view event with retry-safe durable acceptance,conflicting-reuse validation and explicit event-time admission outcomes.
  2. Analytics clients read exact cumulative counts for one or up to 100 videos with coverage generation,watermark,freshness and optional pending minimum-receipt coverage.
  3. Operators recover or rebuild lifetime counts from durable cumulative checkpoints and a complete accepted-event tail without losing or counting an event twice.

At scale

  • For this exercise, assume 20 million videos,100,000 qualified view events/s normally and 1 million/s peak; a single premiere may receive 20 percent of peak events.
  • For this exercise, support 10,000 count queries/s with at most 100 video IDs per request; target 300 ms p95 healthy read latency and 60 seconds p95 visibility for accepted events.
  • For this exercise, accept first-delivery events up to seven days late and five minutes future-skew; retain raw accepted events and admission/dedup receipts for 30 days, and retain durable cumulative totals/checkpoints for the video's counted lifetime. Defer raw deletion if a required checkpoint/rebuild tail is not yet complete.
  • For this exercise, accepted events and complete published count checkpoints survive one availability-zone failure. A pipeline outage may return a clearly stale count or pending/unavailable result,never a fabricated current exact total.