The interview problem
Estimate daily distinct device IDs across regions without retaining every ID centrally. Explain what a union means and which questions the sketch cannot answer.
Original practice, not a reported company interview. Scenarios and numbers are illustrative. Interview date: not applicable. Sources retrieved October 1, 2026.
1. Scope and worked approach
Assume stable pseudonymous IDs and a compatible hash/version configuration. Each region updates a HyperLogLog per day; the aggregator merges sketches for the requested union instead of adding their reported counts. Store population definition and time window with every sketch. Repeated delivery of the same sketch is harmless only under the sketch's idempotent merge semantics. Device IDs are not unique people. Retain exact counts for a small validation cohort and an independent path for questions requiring individual membership.
2. Trace the design or derivation
Identify population → update regional sketch → merge compatible windows → report uncertainty
For a query spanning incomplete regional uploads, return coverage metadata with the estimate. A mathematically valid merge of only three of four regions is still an incomplete business answer. Keep sketch version and ingestion watermark separate so approximate arithmetic does not conceal missing data.
3. Calculate the example
Region A observes {a,b,c} and B observes {b,c,d}. Adding cardinalities gives six while the exact union has four. If a sketch has an illustrative 1% relative standard error, a million-item estimate has roughly 10,000-item standard deviation, not a guaranteed ±10,000 bound.
4. Failure cases and trade-offs
Changing hash seeds makes merges invalid. Identity rotation inflates distinct-device counts. Standard HLL cannot remove one item or list members; window expiry needs separate window sketches. Exact sets cost more memory but support those operations. Do not derive a small intersection by subtracting several noisy large estimates without error analysis.
5. Validation, follow-ups and self-review
Test repeated merges, disjoint/overlapping sets and hash-version rejection against exact fixtures. Follow-up: how would monthly distinct counts differ from summing days? A strong answer defines identity, union and uncertainty separately.
Sources and related practice
Technical reference: redis.io — Approximate distinct cardinality and union operations.
Source publication/update: Not established. Retrieved October 1, 2026. The workflow, calculations and review exercises are original; this reference is not evidence that a company asked this question.
Continue with Skip absent-key disk reads with Bloom filters; Count reactions across regions.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.