SD System Design In Depth
0%
lesson system-designanalyticsrecovery

Raw events vs derived analytics

Module 4.3: Probabilistic Sketches & Stream Analytics Updated Sep 17, 2026
📄 Cheat Sheet
"Turning the database inside out with Apache Samza" by Martin Kleppmann
Strange Loop Conference "Turning the database inside out with Apache Samza" by Martin Kleppmann Watch on YouTube ↗

The definitive talk on treating an immutable event log as the source of truth and every aggregate, index or cache as a rebuildable derived view.

0:00 / --:--

Raw Events vs Derived Analytics

A fundamental debate in analytics architecture is whether to store raw events forever, or to pre-aggregate (derive) the data and throw the raw events away to save storage.

The Value of Raw Events

Raw event data (e.g., every single click, JSON payload, and timestamp stored in S3) is the ground truth. The primary advantage is flexibility. If a product manager asks a totally new question ("How many users clicked X, then Y, but only on iOS 14?"), you can write a Spark job to query the raw data and get the answer. If you only saved pre-aggregated daily counts, you cannot answer this question retroactively.

The Necessity of Derived Analytics

However, running complex queries over petabytes of raw data is extremely slow and expensive. Dashboards cannot wait 10 minutes for a Hadoop job to finish. Therefore, systems build ETL pipelines to continuously pre-aggregate data (derived analytics) into OLAP databases (like ClickHouse) so dashboards load instantly.

The Best of Both Worlds

Modern architectures often retain bounded raw history in object storage and serve versioned derived tables from an OLAP store. For example, if fraud rule v2 excludes two impressions that rule v1 counted, rebuild into a new aggregate version, validate it, then atomically switch the report; mutating rows in place can leave mixed definitions. Raw retention enables replay but increases privacy, deletion, schema-evolution, and storage obligations. Record event schema, transformation version, source range, and correction lineage, and define what happens when source history has expired.

Worked example: storage and query cost

LayerAssumptionSizeQuery latency
Raw JSON events10 billion events per day x 500 bytes5 TB per dayMinutes to hours
Raw in ParquetColumnar, compressed about 5 to 10 times0.5 to 1 TB per day; 90 days is about 45 to 90 TBSeconds to minutes with a query engine
Hourly aggregates by ad, country, deviceSparse rollupTens of GB per daySub-second in an OLAP store
Dashboard tilesPre-computed top-level metricsMBMilliseconds

The 1,000 to 100,000 times reduction from raw to aggregate is what makes dashboards instant, and also what makes new questions impossible once raw data is gone.

Trade-offs

ApproachFlexibilityCostRisk
Aggregates onlyLowLowestCannot fix bugs or answer new questions
Raw only, query on demandHighestHigh compute per querySlow dashboards, unpredictable bills
Raw with bounded retention plus versioned aggregatesHighModerateNeeds lineage and a deletion process

Lambda vs Kappa

Lambda runs a batch layer over raw storage for correctness and a speed layer for freshness, then merges them; the cost is two codebases computing the same logic. Kappa, popularised by Jay Kreps at LinkedIn, keeps a replayable log and reprocesses history by running a new version of the streaming job from the beginning of the retained log, then switching readers. Kappa needs long log retention or tiered storage, which Kafka and Pulsar now offer.

Privacy obligations

Under GDPR-style deletion requests, raw events containing a user ID must be deleted or anonymised within the required period, including in backups and derived tables that are not fully aggregated. Common patterns are partitioning raw data by date so whole partitions age out, pseudonymising user IDs with a per-user key that can be destroyed (crypto-shredding), and aggregating to levels where individuals cannot be identified.

Check yourself Question 1 of 3
Versioned rebuilds recall
From: Raw Events vs Derived Analytics

Fraud rule v2 excludes some impressions that rule v1 counted. How should the derived aggregate tables be corrected?

Key Takeaways

Raw events provide ground-truth flexibility for retroactive, ad-hoc queries.
Derived analytics (pre-aggregations) are required for fast dashboard rendering.
Store raw data in cheap storage (S3/Parquet) and derived data in fast databases.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue