← Thumbtack Interview Insights
Start by clarifying requirements and constraints, then propose a hybrid architecture that uses approximate data structures (e.g., HyperLogLog for distinct counts) to meet memory limits while achieving error bounds under 0.5 percentage points. Explain how to handle late events with watermarks and deduplication using per-user state, and discuss fault tolerance through checkpointing and replication.
Pro tip: Quantify memory and error trade-offs explicitly: for 1B users, a HyperLogLog with 2^14 registers uses ~16KB and gives ~0.81% error, but to get under 0.5 percentage points you might need 2^16 registers (~64KB) per month, which is still feasible. Also, mention that percentage share error can be bounded by combining HLL errors.
Restate the problem: track new vs returning users per calendar month, emit counts and percentage shares at month end. Confirm constraints: 1B distinct users, 50K RPS, 8GB RAM, late events up to 7 days, duplicates, limited per-user state. Ask about exact vs approximate tolerance and definition of 'new' (e.g., first-ever seen vs first in month).
Propose using HyperLogLog (HLL) for approximate distinct counts of new and returning users per month. For exact counts, consider a combination of Bloom filters for deduplication and counters, but note memory limits. Calculate memory: HLL with 2^16 registers uses ~64KB per month per set; for 12 months and two sets, ~1.5MB, well within 8GB. For deduplication, use a Bloom filter with 1B items and 1% false positive rate requires ~1.2GB, which is feasible.
Use event-time processing with watermarks to handle late events up to 7 days. Define a watermark strategy: allow lateness of 7 days, and trigger window emission at month end plus 7 days. Use a allowed lateness mechanism to update results if late events arrive. Discuss trade-off between latency and completeness.
Deduplicate events using a unique event ID or user ID + timestamp. Since per-user state is limited, use a Bloom filter to track seen user IDs for the month, with a false positive rate that doesn't significantly affect counts. For returning users, maintain a global Bloom filter of all users ever seen; new users are those not in the global filter. Update the global filter periodically.
Ensure fault tolerance via checkpointing of state (HLL registers, Bloom filters) to durable storage (e.g., S3) and replication. Discuss time complexity: O(1) per event for HLL and Bloom filter updates. Space complexity: O(2^p) for HLL and O(n) for Bloom filter. Mention that approximate results have error bounds: HLL error ~1.04/sqrt(2^p), so for p=16, error ~0.81%, but percentage share error can be computed via error propagation.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.