Loading lesson...
Sub-linear memory, sub-second latency, terabytes of data. Let's talk.
Sub-linear memory, sub-second latency, terabytes of data. Let's talk.
Topics covered: Count-Min Sketch: Sub-Linear Frequency Estimation, Heavy Hitters: Boyer-Moore Voting in O(1) Space, Frequency-Based Join and Aggregation Optimization, Probabilistic Counting at Scale: Approximate vs Exact, System Design: Real-Time Top-K Frequency Monitoring
Count-Min Sketch is the data structure that solves the frequency estimation problem at scale. You have a stream of billions of events. You cannot hold a Counter in memory. But you need to answer queries like: 'How many times has user_id 8675309 appeared in the last hour?' Count-Min Sketch answers this with a provable accuracy guarantee using O(1/epsilon * log(1/delta)) memory — which in practice is kilobytes, not gigabytes. This is the structure behind frequency tracking in Kafka Streams, Redis
The majority vote problem: given an array, find the element that appears more than n/2 times. The Counter solution is O(n) time and O(n) space. Boyer-Moore voting is O(n) time and O(1) space — no dict, no Counter, no memory allocation proportional to cardinality. It is one of the most elegant algorithms in computer science. The generalization — finding all elements that appear more than n/k times — requires O(k) space and appears in data engineering as 'find all dominant event types in a stream'
Every data engineer knows that GROUP BY + COUNT is expensive. But knowing why — and knowing what to do about it at scale — is the difference between an engineer who can describe the problem and one who can fix it. Frequency analysis is step zero of any join optimization. Before you write a single line of Spark code, you should know the frequency distribution of your join keys. That distribution tells you which optimization strategy to use. The Three Skew Scenarios and Their Solutions Pre-Aggrega
The most important staff-level judgment in frequency counting is knowing when 'good enough' is right. Exact counting requires memory proportional to cardinality. Approximate counting requires constant memory with a tunable error bound. Most business questions about frequency do not require exactness. 'How many distinct users visited today?' does not need to be precise to the person — 99% confidence within 2% is perfectly fine for capacity planning, anomaly detection, and trend analysis. Knowing
This is the capstone system design question for frequency counting at advanced level. 'Design a system that can answer top-K most frequent events over a sliding time window, with sub-second query latency and support for millions of events per second.' This question appears in staff and senior staff interviews. It synthesizes Count-Min Sketch, heap-based top-K maintenance, sliding window expiry, and distributed sketch merging. Let's build it piece by piece. Component Architecture Distributed Exte