All quizzesHard
System Design Expert
Preview — 3 of 10 questions
Twitter has 500M users. A celebrity with 50M followers posts a tweet. Design the feed delivery system.
javascript
Elon Musk posts → 150M followers
Fan-out writes: 150M Redis/DB writes
Time at 1M writes/s: 150 seconds
→ Feed is 2.5 minutes stale for last followerAUse a hybrid fan-out: pre-compute feeds for regular users via async workers; for celebrities (> 1M followers), inject their tweets at read time from a separate hot-path cache.
BWrite the tweet to a single table; all followers query it with a JOIN on every page load.
CUse fan-out on write for all users regardless of follower count — Redis can handle 50M writes per tweet.
DCache the celebrity's tweet in every user's browser localStorage to avoid server load.
Design Uber's real-time driver matching system. A user requests a ride — how do you find the nearest available driver efficiently?
javascript
Driver App → GPS update every 4s
→ [Location Service] → Redis GEO + Cassandra (persist)
Rider requests ride:
→ [Dispatch Service]
→ GEORADIUS drivers:online {lat} {lon} 2km ASC WITHCOORD COUNT 10
→ Get top 10 nearby drivers
→ For each: estimate ETA via routing engine (OSRM / Google Maps API)
→ Rank by ETA + rating + acceptance rate
→ Send offer to best driver (5s to accept, else next driver)AUse geospatial indexing (PostGIS or Redis GEO) with a location update pipeline; query nearby drivers within a radius using spatial queries, then rank by ETA.
BStore driver locations in a SQL table and run SELECT * FROM drivers ORDER BY distance ASC LIMIT 5 on every request.
CMaintain a list of all drivers in memory on a single server for O(1) lookup.
DUse graph-based shortest path algorithms like Dijkstra for every match request.
Two instances of your billing service receive the same LemonSqueezy webhook simultaneously. How do you prevent double-processing?
javascript
-- webhookEvents table has UNIQUE(id)
INSERT INTO webhook_events (id, type, payload, received_at)
VALUES ('evt_123', 'order_created', '...', NOW())
ON CONFLICT (id) DO NOTHING;
-- Instance 1: INSERT succeeds → processes webhook
-- Instance 2: INSERT fails (conflict) → skips processingAUse a database UNIQUE constraint on the webhook ID — both will try to INSERT; one will fail with a constraint violation.
BUse a distributed lock (Redis SETNX) to acquire exclusive access before processing; release after completion.
CUse a message queue with exactly-once delivery semantics.
DBoth A and B are valid approaches; A is simpler and sufficient for most cases.
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.