When should a team accept a Redis Bloom, count-min, top-k or t-digest answer in a user-visible feature, and what standing rules does a lead set first?
answer
- who pays when it errs
- can the user check it
- is an exact answer behind it
- what if the key vanishes
- is exact affordable anyway
basics
~20 sAccept one when a wrong answer is cheap or an exact store can confirm it, and an exact structure costs too much. First require a stated error direction, explicit sizing, a rebuild path and a plan for losing the key.
solid answer
~50 sI ask who pays when the answer is wrong, and whether a user can tell. A trending panel from `TOPK.LIST` or a percentile label from `TDIGEST.CDF` can't be checked by the reader, so an estimate is fine. A label reading 'you viewed this 3 times' from `CMS.QUERY` can be checked and sits in the noise. Anything touching money, access or uniqueness needs an exact store behind it: `BF.EXISTS` may shortcut the sign-up read, but the database decides. Then I check that exact isn't simply affordable, since small sets don't need a sketch. My standing rules: explicit reservation rather than auto-creation, a recorded error direction and owner, an alert on `BF.INFO` sub-filters and the `CMS.INFO` threshold, a tested rebuild from the source of truth, and a plan for key loss, because `BF.EXISTS` replies `0` on a missing key.
code
plaintext · 11 lines> BF.INFO signup:usernames FILTERS
1) (integer) 1
> BF.INFO signup:usernames SIZE
1) (integer) 98876776
> CMS.INFO fraud:declines:2026110310
1) width
2) (integer) 1000000
3) depth
4) (integer) 10
5) count
6) (integer) 812345go deeper
Recall that these structures trade exactness for memory, and that a feature's wrong answer has a real cost to someone. Be able to give one case where that is fine and one where it is not.
Connect each structure's error direction to what the user would see, and name the exact store that confirms a yes. Know that BF.EXISTS replies 0 on a missing key.
Build the operating side: explicit reservations, sub-filter alerts, a live CMS threshold, a tested rebuild and protection from eviction. Show what happens to the feature when the key is lost.
Argue the tradeoff in the open: memory saved against owner cost, support burden and lost auditability. Be willing to reject a sketch because exact data is affordable, and to set the rules teams must meet to use one.
## The decision a lead owns Nobody needs a lead to pick `BF.RESERVE` over `CMS.INITBYPROB`. The real decision is whether a feature may show users an answer that is sometimes wrong, and what the team must have in place first. There is no single right answer, because it depends on who bears the error and on what exact data would cost. ## Four questions to ask of each feature 1. **Who pays when it is wrong?** A false yes from `BF.EXISTS` on an ad-already-seen check loses one impression. An inflated `CMS.QUERY` that blocks a card costs a customer a declined payment. 2. **Can the user check it?** Nobody can audit a trending panel, but people do know how many times they did something. 3. **Is there an exact answer behind it?** If the database confirms every consequential yes, the sketch is an optimization that can fail without harm. If it stands alone, its error is now product behaviour. 4. **Is the exact version affordable anyway?** For values such as IP addresses, the docs compare about 40 bytes per item in a Redis Set with 19.170 bits in a Bloom filter at 0.01%. At 100,000 usernames the Set costs a few megabytes, and the sketch's saving is not worth its operational cost. At hundreds of millions the argument reverses. ## Applying them | Feature | Structure | What a wrong answer looks like | Reasonable position | |---|---|---|---| | Username availability | Bloom | A free name looks taken | Accept, with a database check on yes | | Coupon validity | Cuckoo | A bad delete rejects a valid code | Accept only with gated deletes and a rebuild path | | Trending panel | Top-K | An item is missing or misranked | Accept freely | | Faster than x% of runs | t-digest | The percentage is slightly off | Accept, and round the number shown | | Viewed this 3 times | Count-min | The number is visibly wrong | Reject, count exactly | | Card block on frequency | Count-min | An innocent card is blocked | Only as a gate before an exact check | A sketch also changes how support works. When a customer asks why a coupon failed, a filter cannot explain itself, because it holds no record of items. Features with that kind of support load deserve an exact log regardless of what serves the read. ## Standing rules worth setting - **Explicit creation only.** Ban reliance on `BF.ADD` and `CF.ADD` auto-creation, since capacity 100 at 1% is a default for many tiny filters and not for a production set. - **Recorded error and owner.** Each sketch has a named owner, a stated error direction, and the capacity or threshold it was sized for. - **Alerts on drift.** Alert when `BF.INFO` shows `Number of filters` above 1, or when `error * count` from `CMS.INFO` approaches the rule's limit. - **A rehearsed rebuild.** None of these structures holds a full list of its items, so the source of truth must be able to refill them. A sketch with no source of truth is the only copy of an approximate answer. - **A plan for losing the key.** `BF.EXISTS` and `CF.EXISTS` reply `0` on a missing key, so a lost filter makes every name look free. Eviction under an `allkeys-*` policy or a mistaken `FLUSHALL` can remove the key, and asynchronous replication during a failover can drop recent adds. Keep sketches away from eviction, and make sure a hard constraint sits behind them. - **Availability.** Since Redis 8.0 these commands are in Redis Open Source and included in binary distributions, but a source build needs `redis-full.conf` or a release tarball's `redis.conf`. Grant ACL users `@bloom`, `@cuckoo`, `@cms`, `@topk` or `@tdigest` deliberately. ## Where it stays a judgment call - **Savings that disappear.** A filter in front of a database saves work only on the `0` replies. If most checks reply `1`, the database is read anyway, and the filter just adds a step. - **Team cost.** Every sketch is a new failure mode that engineers must understand. One or two well-owned sketches may beat a dozen small savings. - **What to display.** Rounding a t-digest percentage, or showing a band such as top 10%, can make a feature honest without making it more accurate. - **Reversibility.** Moving from a Set to a filter is easy later, once scale demands it. Moving back needs the exact data you chose not to keep, so a team without that data should choose more slowly.
- Your filter's key disappears at 3 a.m. What should the sign-up path do, and what should you have decided beforehand?Every BF.EXISTS now replies 0, so the database's unique constraint rejects real duplicates and sign-ups stay correct if slower. Decide beforehand to keep that constraint, to check EXISTS on the key from monitoring, and to have a rebuild job ready. Without the constraint, the outage becomes duplicate accounts.
- A team argues that the Bloom filter saves a database read on every sign-up. How do you test that claim?Measure how many checks reply 0 and what one read costs at peak. Sign-ups are rare compared with reads, and a well-indexed unique lookup is cheap, so the saving may not justify owning a sketch. It earns its place when the check runs on every keystroke, or at a volume the database actually feels.
- When would you allow a sketch with no exact store behind it?When the answer is disposable and the error harmless: a trending list, a dashboard percentile, an ad frequency hint. Rotating such a sketch or losing it costs a brief blank or a thin panel. The test is whether anyone would be owed an explanation if a particular answer turned out wrong.
- A probabilistic answer is acceptable anywhere the error rate is low enough.
- A Bloom filter's no stays reliable even if the key has been evicted.
- A sketch is always the cheaper choice, whatever the size of the data set.
- A filter can be rebuilt from its own contents after a capacity mistake.
- A filter in front of the database saves a read on every check, including yes answers.
- Because a sketch is small, it needs no owner, alerts or rebuild plan.
Assumes Redis 8.10; the structures and their ACL categories are in Redis Open Source since 8.0, while older deployments depended on installing the RedisBloom module or Redis Stack.