internalsGet Pro

Module 13 · Lesson 7 of 10Pro

Approximate queries for speed at scale

Level
Advanced
Topic
OLAP and real-time analytics
Reading time
17 min

When you finish this page you can

  1. Explain why an exact distinct count or percentile needs memory that grows with the data, and what an approximate function keeps instead.
  2. Write approximate distinct counts, percentiles and top-k in ClickHouse, Snowflake and DuckDB, and compare them with the exact answer.
  3. Store daily sketch states and combine them for any date range, instead of adding up daily distinct counts.
  4. Decide which numbers may be approximate and which must stay exact, starting with anything finance reconciles.
  1. Modeling events and clickstreams17 min
  2. Real-time OLAP: ClickHouse, Druid and Pinot17 min
  3. Pre-aggregation and rollups16 min

The shoppers tile runs out of memory

At 10:15 IST on Friday 7 January 2028, the operations team opens its morning dashboard. The tile “Unique shoppers, last hour” takes about 9 seconds. Someone switches it to “last 7 days, by category”, and the tile fails: the query hit the server’s memory limit.

Our biggest sale ever · Black Friday

Flat 50% Off

Pro

Continue reading

Unlock every course, now and later

  • System Design, live
  • AI Engineering, live
  • Data Engineering, live
  • Machine Learning Engineering, live
  • Inference Engineering, coming soon
  • AI Research, coming soon
  • Performance Engineering, coming soon
  • Agent & Harness Engineering, coming soon
  • LLM Fine-tuning, coming soon
  • LLM Pre-training & Post-training, coming soon
  • Reinforcement Learning, coming soon
  • AI Infrastructure & Platform Engineering, coming soon
  • AI Evaluation & Safety, coming soon
  • Forward Deployed Engineering, coming soon
  • Cloud Computing, coming soon
  • DevOps, coming soon

50% off · Annual and Lifetime

BLACKFRIDAY50Applied at checkout

Choose a plan