Why this matters
These problems recur in interviews because each isolates one hard idea. Knowing the hard part of each saves you from spending time on the easy parts.
The drills
URL shortener
- Hard part: generating short unique IDs at scale and serving reads fast.
- Design: base62 of a sequence or random ID with a uniqueness check; key-value store; heavy caching (reads ≫ writes); 301 vs 302 (cacheable vs countable); analytics via an async event stream.
Rate limiter
- Hard part: accurate counting across many servers.
- Design: Redis with atomic increments; token bucket or sliding window; keys per user/tenant/endpoint; return 429 with
Retry-After; fail-open vs fail-closed when Redis is down (a deliberate choice). For LLM APIs, limit tokens per minute too (Q16).
Notification service
- Hard part: reliable delivery across channels without duplicates.
- Design: event → queue → per-channel workers (email, SMS, push); user preferences; idempotency keys per notification; retries with backoff and DLQ; templates; rate limits per user.
File upload and processing
- Hard part: large files and slow processing.
- Design: presigned URLs for direct-to-storage upload; storage event → queue → workers; status in DB; virus scan; size and type validation; thumbnails or transcoding; private buckets.
News feed
- Hard part: fan-out.
- Design: fan-out on write (push into followers' feeds; fast reads, expensive for celebrities) vs on read (compute at read time); hybrid for very popular accounts; cursor pagination; caching.
Pattern you should notice
Every drill uses the same handful of blocks from 6.1: cache, queue, idempotency, object storage, rate limiting. AI drills add a model, retrieval and evaluation to the same blocks.
Interview follow-ups
- "URL shortener: how do you avoid ID collisions across servers?" Pre-allocated ID ranges per server, a central sequence, or random IDs with a uniqueness check on insert.
- "Rate limiter: sliding window or token bucket?" Token bucket allows controlled bursts and is cheap; sliding windows are more precise at boundaries. For LLM APIs, token buckets on both requests and tokens.
- "Notification spam: how do you protect users?" Per-user rate limits, digesting (batch into one message), quiet hours and preference checks before send.
Check yourself
Fail-open or fail-closed when the rate limiter's store is unavailable?
It depends on what the limit protects. Fail-open (allow traffic) keeps the product working when abuse risk is low; fail-closed (deny) protects expensive or dangerous resources, like paid model calls with a hard budget.
Why presigned URLs for uploads?
Clients send bytes directly to object storage, so your servers don't proxy large files, and access is time-limited and scoped to one object without sharing credentials.
Build it
Pick two drills and write a one-page design each using the framework, including three failure modes.