</> MAANG.io

Expert

Design landmark systems in depth, from Dynamo, GFS, Bigtable and Kafka to payments and ads pipelines.

0 of 232 solved 0%

Section 5: Store the Facts, Precompute the Questions - Data Modeling

Executive Summary: Behind Section 4's endpoints sit three layers of data. The immutable raw event log is the source of truth. The session table holds facts that exist only once a visit is complete. The cubes are questions answered ahead of time, holding only additive counters and mergeable sketches. The rule holding it together is simple: store what can be summed or merged across any date range, and never store a ratio or a daily-user total. We key and partition each layer, walk the Lisbon hiker through all three, and add the real-time store and the version stamp that separates provisional numbers from final ones.

The interviewer taps the runReport box: "That answers in under two seconds. What is it reading?" "A database" is the weak answer. The strong one starts from access patterns: one firehose writer at ~1.2M hits/s, and three readers. Standard reports want small pre-shaped answers, explorations want flexible scans, and the batch job rebuilds whole days. No single shape serves all three, so we store the same facts at three grains.

Three Layers, Three Grains

Raw events and sessions keep event-level data for 2 or 14 months, cubes outlive them, and the real-time store forgets after 30 minutes.

Three storage layers: the Kafka hit log (72 h retention) feeds raw events (100B rows/day, 10 TB/day) and a real-time store (per-minute sketches, 30-min TTL); raw events are sessionized into sessions (4B rows/day), both aggregate into cubes (~30 reports, ~1 TB/day), and the query service reads cubes, sampled raw events and the real-time store

Sign in to continue reading

The rest of this lesson is available with a free account. Signing in with Google or Microsoft is free.

Sign in to read the full lesson

Sign in to MAANG.io

Use your Google or Microsoft account — no password to remember.

Continue with Google Continue with Microsoft

Please accept the terms above to continue.