Pattern

Real-time aggregation systems

Turn a high-volume event stream into fast rolling counts, sums, or top-k rankings, trading exactness for freshness.

What it is

Aggregation design questions ask you to build a system that ingests a firehose of events (clicks, metrics, searches) and answers a rollup question over a time window — a count, a rate, or a top-k list — fast, continuously, and at a volume where recomputing from raw events on every query is not an option. The core design decision is always the same shape: pre-aggregate as events arrive (streaming counters, sliding windows, sketches) rather than scanning raw history per query, and decide up front which of exactness, latency, and cost you're willing to trade against the others for this particular use case.

When it applies

Tells in the problem

The classic mistake

A design built only for the average case load glosses over the two things that actually break averages: duplicate/out-of-order events (which silently double-count or undercount if not deduplicated and windowed correctly) and the exactness-versus-approximation line, left implicit instead of stated. A design that never explains how it distinguishes a retried click from a second real click, or that promises exact top-100 rankings over hundreds of millions of distinct keys without acknowledging the cost of doing so exactly, looks complete on the whiteboard but collapses under the first follow-up question. State explicitly, before diagramming components: which queries in this system must be exact (and why — usually billing or alerting), which can tolerate approximation, and what happens to a duplicate or a late event under your chosen windowing strategy.

Questions to start with

All 3 real-time aggregation systems questions

Problem statement, examples and hints are free on every page; the worked approach, solution and tests are in the company guides.

Free starter pack

13 must-tier questions with full solutions

Sign in with an email — no purchase — and read them in the full reader.

No password, no spam. One sign-in email; you can read the pack in the full reader.