An approximate membership sketch gates a one-time signup bonus: a 'yes' means already paid, so payment is skipped. What breaks, and what repairs it?
answer
- which branch is standing on certainty
- silent, irreversible, user-visible
- the 'no' is the safe branch
- confirm the 'yes' against the record
- a lost entry inverts the failure
basics
~20 sThe uncertain direction is the one that fires the irreversible branch: a wrong 'yes' silently denies a real user the payment, with no error and no retry. Confirm every 'yes' against the authoritative record before acting on it.
solid answer
~50 sOn the membership structures normally used here the uncertainty is asymmetric — a 'no' is certain, a 'yes' may be wrong — and this design has wired the action to the wrong one. A user who was never paid can be told they were, the bonus is skipped, nothing raises an error, no retry is triggered, and the user has no way to see it happened. The repair is not a lower error rate, which only makes the same failure rarer; it is to act only on the certain direction. Let 'no' mean pay immediately, and make 'yes' mean check the authoritative record before skipping. Then weigh what happens when the entry itself disappears: this is a volatile tier, and a lost sketch answers 'not seen' for everyone, which flips the failure from silent denial to repeated payment.
go deeper
Recall the asymmetry: one of the two answers is certain and the other is not. Work out which one the code is trusting before anything else.
Explain why a smaller error rate does not fix this: it changes how often the failure happens, not whether it can happen, and the failure produces no error to observe.
Demonstrate the production judgment: name the irreversible, user-invisible consequence, put the confirmation behind the uncertain answer, and state what the flow does when the entry itself is gone.
Turn it into a reviewable rule — an approximate answer may not be the last word before an irreversible or user-visible action — and say who checks new uses of it against that rule.
## Which branch the uncertainty lands on An approximate membership sketch is a fixed-memory structure that answers *have we seen this before*, and on the structures normally chosen for membership the two answers are not equally trustworthy: a 'no' is certain, while a 'yes' carries a bounded chance of being wrong. The chance is small and it is never zero, and it is not reported per answer — nothing in the reply distinguishes a wrong 'yes' from a right one. The design in the question attaches the consequential branch to the untrustworthy answer. Its failure looks like this: - A genuinely new account is answered 'yes'. - The bonus is skipped. - No exception is raised, no counter increments, nothing is queued for retry — the system is doing exactly what it was told. - The user was expecting money, did not get it, and there is no evidence anywhere that it was withheld. That combination — irreversible, user-visible, silent — is precisely the case in which an approximate answer must not be the last word. ## Check the direction, do not assume it Before wiring any branch to a sketch, confirm which direction the specific structure can be wrong in. It is a property of the structure you were handed, not of the class. Structures that estimate how often something has been seen typically over-count. Variants that permit removing an item generally trade one-sided error for error in both directions, which would make even the 'no' branch unsafe here. The whole safety argument collapses if the direction is assumed rather than read. ## The rule, in four steps 1. **Name the action behind each answer.** Not 'the check', but what actually happens: money is sent, money is withheld, an email goes out, a job is skipped. 2. **Establish which direction the structure guarantees**, and make sure that is the one the consequential action hangs on. 3. **If the uncertain direction drives something irreversible or user-visible, put a cheap exact confirmation behind it** — read the authoritative record before taking the irreversible branch — or do not use a sketch at that point at all. 4. **Decide what happens when the sketch is gone.** On a volatile tier this is not hypothetical. Applied here, the repaired flow is: a 'no' pays immediately, because a 'no' is certain; a 'yes' triggers a read of the authoritative payment record, which decides. The sketch has not become useless — it still answers most of the traffic without touching the record of truth — but the answer that can be wrong no longer decides anything on its own. ## Why a smaller error rate is not the fix Allocating more memory lowers the frequency of a wrong 'yes'; it does not change its class. At a million signups, a rate small enough to sound negligible still denies a measurable number of real people their bonus every day, silently, with no path to detection because nothing in the system knows it happened. Changing a failure from frequent-and-silent to rare-and-silent is not a control. Only the confirmation step turns it into a failure that cannot occur. ## What each answer is safe to drive | answer | what it means | safe to act on alone | why | |---|---|---|---| | 'no' | definitely never added | yes | the certain direction on these structures | | 'yes' | probably added | only if the consequence is cheap and reversible | the direction that can be wrong | | no sketch (entry lost) | nothing is known | no | every identifier reads as never seen | ## The volatile-tier half of the problem A sketch on this tier is an ordinary entry. It can be lost to a restart, to a failover, or to pressure at the memory ceiling, and what a store keeps across a restart varies widely across this class — some keep nothing at all, others write a point-in-time copy or a log of writes, and the guarantee is a configuration decision rather than a property of the class. When the entry is gone, every identifier reads as 'never seen'. The failure mode inverts: instead of silently denying real users, the system happily pays everyone a second time. So the design has two distinct risks pointing in opposite directions, and the authoritative record is what bounds both. Once that record is being consulted before the irreversible branch, the sketch is an optimisation whose loss costs throughput rather than money. One more shape consequence: a lifetime attaches to the entry, not to anything inside it, so 'seen' accumulates for as long as the entry lives and individual identifiers cannot be aged out. If your question is really 'seen in the last hour', that has to be expressed as a rotated entry per window, not as an expiry on a member.
- Where may a 'yes' be acted on with no confirmation at all?Where the consequence is cheap and reversible and no user sees it: skipping optional enrichment, deferring a background refresh, declining to re-index something that will be re-indexed anyway. The test is whether a wrong 'yes' costs work rather than correctness, and whether the next run puts it right by itself.
- The team proposes allocating more memory so the error rate drops. Does that close the issue?No. It makes the same failure rarer and just as silent. At signup volumes a small rate is still real people denied a payment with nothing recording it. Frequency is not a control here; only confirming the uncertain answer against the authoritative record removes the failure class.
- How would you detect the wrong answers in production if the confirmation were not added?You largely cannot from inside the flow — nothing distinguishes a wrong 'yes' from a right one. You would be reduced to sampling: periodically compare sketch answers against the authoritative record for a slice of traffic and measure the disagreement rate. That sampling job is most of the cost of just doing the confirmation.
saying these in an interview costs you the question
- Assumes the wrong answer causes a duplicate payment rather than a missing one
- Treats a 'yes' and a 'no' as equally trustworthy answers
- Plans to lower the error rate until wrong answers stop occurring
- Adds a retry on the skipped branch, though nothing reported an error
- Believes a restart of the tier leaves the answers unchanged
- Expects an individual answer to indicate that it might be wrong