Choosing a probabilistic data structure 00:00:01 Three questions arrive at one operator desk A dashboard team gets one stream and three requests. Has a particular device checked in? How often was checkout called? How many distinct devices called anything? What information would each answer need? In this example the service receives twelve thousand requests a second. It wants bounded memory and quick summaries for a fixed time window. The event records can still exist in another system. Each question needs a different kind of memory: one for presence, one for frequency, one for distinct count—no single tool fits all. Take one device calling checkout three times and a second device calling once. Membership asks about a named device, frequency asks about checkout, and distinct count asks for two devices. Four events alone cannot answer all three. 00:00:48 Membership asks about a named key A Bloom filter hashes a named identifier to selected bit positions. If any required bit is clear, an insertion-only filter with complete updates can say the identifier is absent. When all the bits are set, the answer is maybe. Several other identifiers can have set those positions. The filter cannot return the original device IDs from its bits. Use a positive as a reason for an authoritative lookup when a mistaken positive matters. A false positive can cost an extra disk read without corrupting the underlying records. Insert both real device identifiers consistently into the filter before relying on negative probes. A delayed write can make the application appear to have a false negative, even though the mathematical filter is behaving correctly. 00:01:31 Frequency asks how many times A Count-Min Sketch chooses one counter in each hash row for the endpoint name and increments those counters for each request. It keeps bounded arrays in place of an unbounded name-to-count map. To estimate the frequency for checkout, take the smallest corresponding row value. For nonnegative updates without counter overflow, collisions can add counts, but cannot subtract checkout’s own increments. The sketch needs an endpoint name to query. Its counters alone cannot list every endpoint, so a popular-endpoints report needs a separate way to discover candidate names. For the four checkout events, each of the relevant counters receives at least four increments. Unrelated endpoint collisions can push some counters higher. Taking their minimum suppresses some of that excess. 00:02:16 Distinctness ignores repetitions HyperLogLog estimates a distinct count from hashed identifiers. A hash prefix selects a register and the remaining bits supply a rank. Each register retains its largest observed rank. If the same device visits again, the hash stays the same, so no new maximum is recorded—repeats don’t change the count. Its estimate has statistical error that depends on precision and the implementation. A single observed estimate is neither an exact count nor a universal confidence interval. A repeat from the same device chooses the same register and proposes the same rank. It adds no new information. Two different devices can also leave indistinguishable evidence, which is why the answer is an estimate. 00:03:03 Choose from the cost of error For a cache precheck, a false positive might mean one wasted authoritative lookup. A popularity chart might tolerate slight overestimation, while deciding a one-time financial entitlement typically needs exact records. I need to know the window size, expected count, and what failure costs—then pick the right tool for each job. Match the required answer to the summary. Ask one membership question, estimate a known key’s frequency, or estimate the number of distinct identities. Keep the exact source where the contract demands proof. Write down which outcomes are recoverable. An unnecessary read consumes time. Treating a probable hit as permission can change a real account. A billing contract can require exact records even when a trend chart accepts estimation.