$ cat resources/system-design.md
# system design
Low-level design, multithreading and system design, grouped into pattern families. Read a family's approach first, then practise its problems. CORE marks the 30 must-do problems.
94 problems · 20 pattern families · 30 core
## low-level design machine coding · OOD
L1 Game Engines 3
how to approach · start with Snake & Ladder → Tic-Tac-Toe → Chess
Model (board, pieces, players) is separate from the rules and from the game loop. The engine never knows about the UI.
steps
- List entities: Game, Board, Cell/Piece, Player, Dice/Move.
- Put every rule behind an interface (MoveValidator, WinChecker).
- Model game states: NOT_STARTED → IN_PROGRESS → WON / DRAW.
- Keep win/move checks cheap (row/col counters, lookup maps).
- Keep the engine UI-free so it is unit-testable.
- patterns
- Strategy (rules, dice), State (game status), Factory (pieces/boards), Command/Memento (undo), Observer (UI events)
- follow-ups & traps
- Undo/redo; new board size or rules; AI player; multiplayer / concurrent moves; save & load game.
- start with
- Snake & Ladder → Tic-Tac-Toe → Chess
- Snake & Ladder (opens in a new tab) easy · core · W1
Model an N-player board game with snakes, ladders and dice; rules and board size should be configurable.
key ideas: Configurable board, dice strategy, turn mgmt, win detection
Amazon · Adobe · Microsoft · Flipkart · Swiggy · Zynga
- Tic-Tac-Toe (N×N) (opens in a new tab) easy · skim
Two players on an N×N board; detect a win in O(1) per move and keep the engine independent of the UI.
key ideas: Game state, win check in O(1), extensible players
Atlassian
- Chess Game Engine (opens in a new tab) hard · core · W2
Pieces with their own move rules, move validation, check and checkmate; adding a new piece type should not touch existing code.
key ideas: Polymorphic pieces, move validation, check/checkmate, extensible rules
Asana · Wayfair · Atlassian
L2 Booking & Reservation 3
how to approach · start with Parking Lot → Movie Ticket Booking → Meeting Room
A resource (spot, seat, room) is claimed for a time window. The hard part is allocation and never double-booking.
steps
- Identify Resource, Slot/Time, Reservation, User.
- Reservation lifecycle: AVAILABLE → HELD → CONFIRMED → EXPIRED/CANCELLED.
- Allocation as a Strategy (nearest, first-fit, cheapest).
- Make check-and-claim atomic (per-resource lock or CAS).
- Add hold-expiry and a pricing Strategy.
- patterns
- Strategy (allocation, pricing), State (reservation), Factory (vehicle/seat types), Observer (notify on release)
- follow-ups & traps
- Concurrent users; payment timeout; overlapping intervals (sort + sweep / interval tree); multi-floor / multi-city.
- start with
- Parking Lot → Movie Ticket Booking → Meeting Room
- Parking Lot (opens in a new tab) easy · core · W1
Multi-floor lot with spot types (bike, car, truck), entry/exit tickets and pricing; follow-up: many gates at once.
key ideas: Strategy (pricing / spot allocation), enums, ticketing; follow-up: concurrent entry/exit
Uber · Swiggy · Flipkart · Amazon · Google · Microsoft · Adobe
- Movie Ticket Booking (BookMyShow) (opens in a new tab) medium · core · W2
Cities, theatres, shows and seat maps; hold seats while the user pays and never sell the same seat twice.
key ideas: Seat locking, double-booking prevention, payment timeout
-
Book rooms for time slots, find free rooms, and detect overlapping meetings, including recurring ones.
key ideas: Interval overlap, room allocation strategy, calendar integration
Flipkart
L3 Money & Ledger 4
how to approach · start with Splitwise → Digital Wallet → Payment Gateway
Money movement must be atomic, auditable and idempotent. Think append-only entries, not "update the balance".
steps
- Model Account + immutable Transaction/Entry (integers or BigDecimal, never float).
- A transfer = debit + credit as one atomic unit; lock accounts in id order to avoid deadlock.
- Add an idempotency key per request.
- Payment state machine: INIT → PENDING → SUCCESS/FAILED → REFUNDED.
- Retries with backoff + reconciliation job.
- patterns
- State (payment), Strategy (split type, bank routing), Command (transaction), Observer (webhooks)
- follow-ups & traps
- Duplicate requests; partial failures; multiple banks / virtual banks; simplify debts (Splitwise); audit trail.
- start with
- Splitwise → Digital Wallet → Payment Gateway
- Splitwise (expense sharing) (opens in a new tab) medium · core · W2
Record shared expenses split equally, exactly or by percentage, show who owes whom, and simplify debts.
key ideas: Balance graph, split strategies (equal/exact/%), simplify debts
Swiggy · Flipkart · Upstox
- Digital Wallet System (opens in a new tab) medium · skim
Users top up, pay and transfer between wallets with a transaction history; transfers must be atomic.
key ideas: Accounts, transactions, atomic transfer, idempotency
Flipkart
- In-Memory Banking System (opens in a new tab) medium · skim
Accounts, deposits, transfers and scheduled payments, extended level by level (rankings, merges, history).
key ideas: Accounts, transfers, scheduled payments, ranking, level-by-level extension
Anthropic
-
Route payments to banks or providers, track each payment through its states, retry failures and pay merchants out.
key ideas: Multi-bank routing (virtual banks), retries, idempotency, state machine
Meesho · Razorpay · Stripe · PayPal
L4 In-Memory Stores & Data-Structure Design 5
how to approach · start with LRU Cache → In-Memory KV DB → File System
Pick the right data structure first, then wrap it in a clean, extensible API.
steps
- Write the API (get/put/delete…) and complexity targets first.
- Choose structures (HashMap + DLL, Trie, heap, sorted map).
- Make policies pluggable (eviction, TTL) behind interfaces.
- Define edge behaviour (capacity, expiry, missing key).
- Add thread-safety last, thinking about lock granularity.
- patterns
- Strategy (eviction), Composite (file system), Decorator (TTL/stats), Iterator
- follow-ups & traps
- O(1) guarantees; TTL cleanup (lazy vs background); persistence / crash recovery; concurrency; versioned reads.
- start with
- LRU Cache → In-Memory KV DB → File System
- LRU Cache (pluggable eviction + TTL) (opens in a new tab) medium · core · W1
get/put in O(1) with least-recently-used eviction; then make eviction pluggable (LFU, FIFO) and add expiry.
LC 146 key ideas: HashMap + doubly linked list; Strategy for LRU/LFU/FIFO; crash-resilient variant
Google · Amazon · Microsoft · Facebook · Adobe · Netflix · Atlassian · Anthropic
-
Directories and files in memory with mkdir, ls, read and write on paths; extensible to new commands.
key ideas: Composite pattern, Trie of path segments, extensible commands
Uber
- In-Memory Key-Value DB (TTL, tombstones, versioning) (opens in a new tab) medium · core · W2
set/get/delete with expiry, then versioned reads ("value at time t") and prefix scans.
key ideas: Versioned maps, TTL eviction, prefix scan, historical reads
Anthropic · Atlassian
-
Cells hold values or formulas like =SUM(A1:A3); when a cell changes, dependants update and cycles are caught.
key ideas: Dependency graph, cycle detection, recomputation, formula parsing
Google · Stripe
- Multi-Level Cache (L1/L2, write-through/back) hard · skim · ★ extra
A small fast cache in front of a larger one; define reads, writes, write policies and eviction across levels.
key ideas: Layered caches, eviction/consistency policies, metrics
L5 Pluggable Policy Engines 6
how to approach · start with Rate Limiter → Logger → Notification Service
Behaviour that changes (algorithm, channel, rule) lives behind an interface so new variants never touch existing code.
steps
- Identify what varies (algorithm, channel, rule).
- Define the interface + a Factory / registry.
- Build 2 concrete implementations to prove the design.
- Add config / dynamic reload.
- Show how a 3rd variant is added without editing old code.
- patterns
- Strategy, Chain of Responsibility, Factory, Observer, Command (+ Memento for undo)
- follow-ups & traps
- Add a new algorithm; dynamic config; thread safety; memory growth from per-client state; retries / backoff.
- start with
- Rate Limiter → Logger → Notification Service
-
Count hits in the last 5 minutes, or print a message at most once every 10 seconds.
key ideas: Queue + sliding window, rate-limiter adjacent
Atlassian
- Logging Framework (opens in a new tab) easy · skim
Log levels, several destinations (console, file) and formats; a message flows through a chain of handlers.
key ideas: Chain of Responsibility (log levels), Singleton, async appenders
Amazon · Microsoft · Apple · Google · Splunk
- Rate Limiter (pluggable algorithms) (opens in a new tab) medium · core · W2
Allow or reject requests per user with token bucket, fixed or sliding window, chosen by configuration.
key ideas: Strategy (token bucket / sliding window), factory, config reload
Uber · Atlassian
-
Users rate items; compute averages and rankings, and add new rating rules or aggregations without rewrites.
key ideas: Aggregation strategies, scale-up requirement added mid-round
Atlassian
- Notification Service (channels, retries, templates) medium · skim · ★ extra
Send email, SMS or push from templates, with user preferences, retries and adding a channel without code changes.
key ideas: Observer + Strategy per channel, retry/backoff, priority queue
- Text Editor with Undo / Redo medium · skim · ★ extra
Insert, delete and format text with unlimited undo and redo (Command / Memento).
key ideas: Command + Memento patterns, cursor, selection
L6 Scheduling, Matching & State Machines 5
how to approach · start with Vending Machine → Elevator → Cab Booking → Stock Exchange
Entities move through states and a dispatcher decides who gets which resource.
steps
- Draw the state diagram first (states + events).
- Model each state as a class or a transition table (State pattern).
- Separate the Dispatcher / Scheduler from the entities.
- Make the matching policy pluggable (nearest, SCAN/LOOK, price-time priority).
- Think about concurrent requests hitting the dispatcher.
- patterns
- State, Strategy (dispatch), Observer, PriorityQueue / heap
- follow-ups & traps
- Multiple elevators / drivers; cancellations; fairness / starvation; order-book matching; runtime-configurable workflows.
- start with
- Vending Machine → Elevator → Cab Booking → Stock Exchange
- Vending Machine (opens in a new tab) easy · core · W1
Select a product, insert money, get it and the change; the machine moves through clear states (idle, has money, dispensing).
key ideas: State pattern, inventory, payment handling
Google · Amazon · Microsoft · Apple · Oracle
- Coffee Machine (opens in a new tab) easy · skim
Beverages from ingredient recipes, low-stock alerts, and several outlets making drinks at the same time.
key ideas: Recipe/ingredient model, concurrent beverage preparation
Flipkart
- Elevator System (single → multi-lift) (opens in a new tab) medium · core · W2
Handle floor requests for one lift, then dispatch requests across many lifts efficiently.
key ideas: State machine, scheduling (SCAN/LOOK), dispatcher strategy
Amazon · Microsoft · Uber · Google · Adobe · Lyft
- Ride-Sharing / Cab Booking App (opens in a new tab) medium · skim
Riders request trips, nearby drivers are matched, and each trip moves from requested to completed with a fare.
key ideas: Driver–rider matching strategy, trip lifecycle, pricing strategy
Flipkart · Uber
-
Keep buy and sell order books per stock and match orders by price and time priority; support cancels.
key ideas: Order book (PriorityQueue per price), matching rules, concurrency
Navi
L7 Catalog, Cart & Order Modelling 4
how to approach · start with Pizza Ordering → Food Delivery Cart → Shopping Cart with Coupons
Mostly entity design: get the nouns, relationships and order lifecycle right.
steps
- Extract nouns (User, Item, Cart, Order, Menu…).
- Draw relationships (1:N, N:M) and ownership.
- Model the cart / order lifecycle as states.
- Decorator or Builder for customisable items (toppings, add-ons).
- Search / filter via Specification or Strategy.
- patterns
- Builder, Decorator, State, Specification / Strategy (filters), Observer
- follow-ups & traps
- Price / discount rules; inventory; search filters; multi-restaurant carts.
- start with
- Pizza Ordering → Food Delivery Cart → Shopping Cart with Coupons
- Library Management System (opens in a new tab) easy · skim
Books, copies and members; search, issue and return books, with limits and late fines.
key ideas: Entities, search, issue/return, fines
- Pizza Ordering System (opens in a new tab) easy · skim
Build pizzas from a base plus toppings with correct pricing (Decorator / Builder) and track each order’s status.
key ideas: Decorator/Builder for toppings, order state machine (reported Sep 2026)
Amazon
- Food Ordering / Food Delivery Cart (opens in a new tab) medium · skim
Restaurants and menus, a cart, placing orders and assigning delivery partners as orders move through states.
key ideas: Menu, cart, order state machine, delivery-partner assignment strategy
Uber · Flipkart · Zomato · Swiggy · DoorDash
- Shopping Cart with Coupons & Discounts (opens in a new tab) medium · ★ extra
Cart totals with stackable discount rules (percent off, buy-X-get-Y, coupons) that can be added without touching the cart.
key ideas: Strategy / Specification for discount rules, cart pricing pipeline
## multithreading concurrency rounds
M1 Thread Signalling Basics 4
how to approach · start with Print in Order → FooBar → Zero-Even-Odd
Make threads take turns in a fixed order using shared state plus a way to wait and wake.
steps
- Name the shared state (turn counter / flag).
- Pick the primitive (mutex + condition, semaphore, latch).
- Always wait in a while loop (spurious wake-ups).
- After changing state, signalAll / notifyAll.
- Check: no deadlock, no lost wake-up, correct order.
- patterns
- Mutex + Condition, Semaphore, CountDownLatch, Barrier
- follow-ups & traps
- Using if instead of while; notify() lost wake-ups; forgetting to unlock in finally.
- start with
- Print in Order → FooBar → Zero-Even-Odd
- Print in Order (opens in a new tab) easy · core · W3 · ★ extra
Three threads call first(), second(), third() in any order; make the output always come out in order.
LC 1114 key ideas: Ordering with semaphores / latches / condition variables
- Print FooBar Alternately (opens in a new tab) easy · W3 · ★ extra
Two threads print "foo" and "bar"; make them alternate exactly n times.
LC 1115 key ideas: Two-thread alternation, mutex + condition variable
- Print Zero-Even-Odd (opens in a new tab) medium · skim · ★ extra
Three threads cooperate to print 0 1 0 2 0 3 … by passing the turn between them.
LC 1116 key ideas: Three-thread coordination, state variable + condition
- Building H2O (opens in a new tab) medium · skim · ★ extra
Hydrogen and oxygen threads must group into exact H₂O molecules before any of them proceeds (a barrier).
LC 1117 key ideas: Barrier + semaphores, grouping threads
M2 Producer–Consumer & Queues 4
how to approach · start with Bounded Blocking Queue → Producer–Consumer → Async Logger
Decouple producers from consumers with a bounded buffer; block when full or empty.
steps
- State the invariant: 0 ≤ size ≤ capacity.
- Lock + two conditions (notFull, notEmpty) or two semaphores.
- enqueue waits while full; dequeue waits while empty.
- After each operation signal the opposite condition.
- Add shutdown (poison pill), timeouts, backpressure.
- patterns
- BlockingQueue, Semaphore pair, Condition variables
- follow-ups & traps
- Multiple producers / consumers; fairness; timed offer/poll; graceful shutdown; batching.
- start with
- Bounded Blocking Queue → Producer–Consumer → Async Logger
- Design Bounded Blocking Queue (opens in a new tab) medium · core · W3
A fixed-capacity queue: enqueue blocks while full, dequeue blocks while empty, safe for many threads.
LC 1188 key ideas: Lock + 2 conditions or 2 semaphores; avoid lost wake-ups and deadlock
Rubrik
-
Producers and consumers share a buffer; solve it three ways and explain the trade-offs.
key ideas: Thread signalling, shutdown/poison pill, backpressure
Netflix
- Async Logger / Batched Writer with Background Thread medium · skim · ★ extra
Callers log without blocking; a background thread batches and writes, and flushes on shutdown.
key ideas: Queue + worker, flush policy, graceful shutdown
- Connection / Object Pool (blocking, timeouts) medium · skim · ★ extra
Lend a fixed number of connections, block or time out when none are free, and never leak one.
key ideas: Semaphore-bounded pool, validation, leak handling
M3 Thread Pools & Executors 4
how to approach · start with Thread Pool → Scheduled Executor → DAG Task Scheduler
A fixed set of worker threads pulls tasks from a queue; extend with delays, futures and dependencies.
steps
- Core = bounded queue + N workers looping take().
- submit() returns a Future (result + exception).
- Decide the rejection policy when the queue is full.
- Shutdown: stop accepting, drain, interrupt.
- Scheduling: DelayQueue / PriorityQueue + timed wait.
- DAG tasks: track indegree, run when ready.
- patterns
- Worker pool, Future / Promise, DelayQueue, topological order
- follow-ups & traps
- Task exceptions; timeouts; reclaiming stuck threads; cancellation; work stealing.
- start with
- Thread Pool → Scheduled Executor → DAG Task Scheduler
- Web Crawler Multithreaded (opens in a new tab) medium · skim · ★ extra
Crawl every page on one host from a start URL using many threads, visiting each page exactly once.
LC 1242 key ideas: Visited set (concurrent), work queue, thread pool
- Thread Pool / Task Executor (exception handling, timeout, thread reclaim) (opens in a new tab) hard · core · W3
Fixed workers take tasks from a queue; handle task failures, timeouts, results and graceful shutdown.
key ideas: Worker threads, bounded queue, rejection policy, shutdown
Rubrik
-
Run tasks after a delay or repeatedly at a fixed rate, with cancellation, like ScheduledExecutorService.
key ideas: DelayQueue / PriorityQueue + condition wait with timeout
Netflix · Pure Storage · Uber
-
Run tasks in parallel, but only after the tasks they depend on finish; detect cycles and failures.
key ideas: Topological order, ready-queue, parallel execution, failure propagation
Google
M4 Locks, Sync Primitives & Deadlock 6
how to approach · start with Dining Philosophers → Reader–Writer Lock → Custom Latch / Semaphore
Reason about correctness: mutual exclusion, visibility, ordering and deadlock.
steps
- List shared variables and who writes them.
- Choose granularity: one lock vs striped locks vs lock-free (CAS).
- Check the 4 deadlock conditions; break one (lock ordering is the usual fix).
- Prefer tryLock with timeout where possible.
- Check visibility (volatile / happens-before).
- patterns
- ReentrantLock, ReadWriteLock, Atomics / CAS, lock ordering, double-checked locking
- follow-ups & traps
- Starvation; fairness; reentrancy; upgrade / downgrade; "can you remove the lock?".
- start with
- Dining Philosophers → Reader–Writer Lock → Custom Latch / Semaphore
- Thread-Safe Singleton (double-checked locking, volatile) easy · skim · ★ extra
Create exactly one instance lazily under concurrency, and explain why volatile is needed.
key ideas: Memory visibility, happens-before, initialization-on-demand holder
-
Make a counter or stack thread-safe without locks using compare-and-swap, and discuss ABA.
key ideas: AtomicInteger, compare-and-swap, ABA, follow-up on removing locks
Pure Storage
- Custom CountDownLatch / CyclicBarrier / Semaphore medium · skim · ★ extra
Implement these primitives with a lock and conditions to show how they work underneath.
key ideas: Build sync primitives from monitor (wait/notify)
- The Dining Philosophers (opens in a new tab) medium · core · W4 · ★ extra
Five philosophers share five forks; let them all eat without deadlock or starvation.
LC 1226 key ideas: Deadlock avoidance: lock ordering / resource hierarchy
- Reader–Writer Lock (fair / writer-preference) (opens in a new tab) hard · core · W4
Many readers or one writer at a time, without starving writers; then make it fair.
key ideas: Starvation, reentrancy, upgrade/downgrade
Netflix
- Deadlock Detection & Prevention (wait-for graph) hard · skim · ★ extra
Detect deadlock with a wait-for graph, then prevent it with lock ordering or tryLock timeouts.
key ideas: Lock ordering, tryLock with timeout, cycle detection
M5 Thread-Safe Products (applied) 5
how to approach · start with Thread-Safe Rate Limiter → Thread-Safe LRU → Pub/Sub
Take a normal LLD design and make it correct under concurrency.
steps
- Write the single-threaded design first.
- Mark shared mutable state and the invariant that must hold.
- Choose lock scope (per key / per resource), not one global lock.
- Make check-and-act atomic (computeIfAbsent, CAS).
- Walk through 2 threads on the critical path.
- patterns
- ConcurrentHashMap, per-key locks, atomic counters, optimistic vs pessimistic locking
- follow-ups & traps
- Hot keys; memory growth; lock contention; the distributed version of the same problem.
- start with
- Thread-Safe Rate Limiter → Thread-Safe LRU → Pub/Sub
-
A per-user rate limiter that stays correct under heavy concurrency without one global lock.
key ideas: Atomic refill, per-user ConcurrentHashMap, lock striping
Uber · Atlassian
-
Make the LRU cache safe for many threads while keeping get and put fast.
key ideas: Lock granularity, sharding, read-heavy optimisation
Atlassian
-
The parking lot with several gates assigning spots at once; never give one spot to two cars.
key ideas: Atomic spot allocation, race-free ticketing
Uber
- Seat / Ticket Booking – prevent double booking medium · skim · ★ extra
Many users grab the same seats at once; hold, confirm or release seats so none is sold twice.
key ideas: Pessimistic vs optimistic locking, lock with TTL, compare-and-set
-
Topics, publishers and subscribers in memory, delivering in order per subscriber with slow consumers handled.
key ideas: Topics, subscriber threads, ordering, slow-consumer handling
Uber
## high-level design system design
H1 Real-Time Fan-out & Delivery 4
how to approach · start with Notification → News Feed → Chat
One event must reach many users quickly and reliably: feeds, messages, notifications, collaboration.
steps
- Requirements + scale (DAU, fan-out ratio).
- Choose push (fan-out on write), pull (on read) or hybrid for celebrities.
- Async pipeline: queue → workers → per-channel senders.
- Persistent connections (WebSocket) + presence for real time.
- Retries, dedup, ordering, delivery receipts.
- patterns
- Queues / Kafka, cache, WebSockets, fan-out, idempotency
- follow-ups & traps
- Celebrity with 100M followers; ordering guarantees; offline users; per-user rate limiting; multi-region.
- start with
- Notification → News Feed → Chat
- Notification System (opens in a new tab) medium · core · W5
Send millions of push, SMS and email notifications reliably, with user preferences, retries and rate limits.
key ideas: Fan-out, channels, retries, dedup/idempotency, priority queues
Meta · Amazon · Airbnb · Uber · Google
- Chat / Messaging System (WhatsApp) (opens in a new tab) medium · core · W6
1:1 and group chat with online status, delivery and read receipts, and offline message delivery.
key ideas: WebSockets, delivery receipts, ordering, presence, group fan-out
Meta · Uber · Apple · Discord · Tesla
- News Feed / Twitter Timeline (opens in a new tab) medium · core · W5
Build each user’s feed from accounts they follow; choose fan-out on write vs read, including celebrities.
key ideas: Fan-out on write vs read, celebrity problem, ranking, caching
Meta · Twitter/X · Dropbox · Microsoft · Amazon · LinkedIn
-
Many users edit one document live; merge concurrent edits (OT or CRDT) and show cursors.
key ideas: OT vs CRDT, presence, versioning, offline edits
Google · Palantir
H2 Geo-Indexing & Marketplaces 4
how to approach · start with Nearby Places → Ride-Sharing → Food Delivery → Maps
Match supply and demand by location in real time.
steps
- Define entities: rider, driver, order.
- Index locations with geohash / quadtree / S2.
- Handle frequent location updates in memory + stream, not DB writes.
- Matching service + dispatch with timeouts.
- ETA and pricing as separate services.
- patterns
- Geo-index, streaming, cache, sharding by region
- follow-ups & traps
- Hot cities; surge pricing; driver re-assignment; assignment consistency.
- start with
- Nearby Places → Ride-Sharing → Food Delivery → Maps
- Ride-Sharing Service (Uber / Lyft) (opens in a new tab) medium · core · W6
Match riders to nearby drivers in real time from constant location updates, and run trips end to end.
key ideas: Geohash/quadtree, driver location updates, matching, ETA
Uber · Lyft · Google · Meta
-
Restaurant search, ordering, and assigning couriers with live tracking.
key ideas: Order lifecycle, restaurant search, dispatch, payments, tracking
Uber · DoorDash · Meta · Google
- Google Maps / Routing (opens in a new tab) hard · skim
Store the road graph, compute fastest routes with live traffic, and give ETAs at scale.
key ideas: Graph partitioning, contraction hierarchies, tiles, live traffic
Google · Lyft · Uber
- Nearby Places / Proximity Service (Yelp) (opens in a new tab) medium · ★ extra
Find businesses near a location fast; index locations (geohash or quadtree) for a read-heavy load.
key ideas: Geohash / quadtree index, read-heavy caching, business CRUD
H3 Consistency, Booking & Payments 5
how to approach · start with Ticket Booking → Payment / Ledger
Correctness over speed: no double-sell, no double-charge.
steps
- Name the invariants (a seat sold once; money in = money out).
- Reserve with a TTL lock, then confirm on payment.
- Idempotency keys on every write API.
- Pick the transaction model: ACID DB for the core, saga for multi-service.
- Reconcile asynchronously.
- patterns
- Idempotency, DB transactions, distributed locks / leases, saga / outbox, queues
- follow-ups & traps
- Flash-sale traffic; payment timeout; retries; exactly-once effects; reconciliation.
- start with
- Ticket Booking → Payment / Ledger
- Online Calendar (shared calendars) (opens in a new tab) medium · skim
Events, invites, shared calendars and recurring events across time zones, with reminders.
key ideas: Recurring events, free/busy, notifications, sharing/ACL
Uber · Google
- Ticket Booking (Ticketmaster / StubHub) (opens in a new tab) medium · core · W6
Sell tickets for popular events: hold seats, take payment, and survive huge spikes without overselling.
key ideas: Seat reservation with TTL locks, flash-sale traffic, payments
OpenAI · Amazon · Google · Meta · Stripe
- Hotel / Travel Booking System (opens in a new tab) medium · skim
Search availability by date range, book rooms, and keep inventory consistent across overlapping bookings.
key ideas: Availability, overbooking, inventory consistency, search
Meta · Amazon · Square
- Online Auction System (opens in a new tab) medium · skim
Run timed auctions with live bids; order bids correctly and pick the winner at close.
key ideas: Bid ordering, real-time updates, concurrency, closing logic
Meta
- Idempotent Double-Entry Ledger / Payment System (opens in a new tab) hard · core · W7
Move money exactly once despite retries, using idempotency keys and a double-entry ledger that always balances.
key ideas: ACID vs sagas, double-entry invariants, reconciliation
Stripe · Uber
H4 Blob Storage, Metadata & CDN 6
how to approach · start with Dropbox → YouTube → S3
Big files live in object storage, metadata lives in a DB, and users read through a CDN.
steps
- Split data: blobs vs metadata.
- Chunk + resumable upload with pre-signed URLs.
- Async processing (transcode, thumbnails) via a queue.
- CDN + caching for reads.
- Dedup / versioning / sync in the metadata service.
- patterns
- Object store, chunking, CDN, queues, content hashing
- follow-ups & traps
- Sync conflicts; resume large uploads; cost tiers; hot content; durability (erasure coding).
- start with
- Dropbox → YouTube → S3
- Pastebin easy · skim · ★ extra
Store text snippets and share them by short URL, with expiry; a gentle intro to blob plus metadata storage.
key ideas: Object store + metadata DB, expiry, CDN
- Cloud File Storage (Dropbox / Google Drive) (opens in a new tab) medium · core · W6
Upload, sync and share files across devices: chunking, deduplication, versioning and conflicts.
key ideas: Chunking, dedup, sync protocol, metadata service, conflict resolution
Google · Amazon · Microsoft · Dropbox
- Video Streaming (YouTube / Netflix) (opens in a new tab) medium · skim
Upload, transcode into many qualities, and stream through a CDN with adaptive bitrate.
key ideas: Upload pipeline, transcoding, CDN/ABR, recommendations
Google · Netflix · TikTok · Amazon · Meta
- Instagram / Photo Sharing (opens in a new tab) medium · skim
Upload photos, follow users and build a feed; store media and serve it fast worldwide.
key ideas: Media storage, feed, CDN, graph storage
Meta
- Object Storage (S3-style) (opens in a new tab) hard · skim
Store huge numbers of blobs durably: buckets, metadata, replication or erasure coding.
key ideas: Erasure coding, metadata/data separation, durability, multipart upload
Amazon · Backblaze · Google
- CDN Design hard · skim · ★ extra
Cache content close to users: routing to edges, cache fill and invalidation, origin protection.
key ideas: Edge caching, cache invalidation, origin shield, routing
H5 Search, Indexes & Crawling 3
how to approach · start with Autocomplete → Web Crawler → Full-Text Search
Precompute structures so reads are fast; keep indexing separate from serving.
steps
- Define query types (prefix, keyword, geo).
- Pick the index (trie / inverted index / geo).
- Offline or streaming pipeline builds the index.
- Cache hot queries; rank results.
- Crawler: frontier + politeness + dedup.
- patterns
- Trie, inverted index, Bloom filter, cache, queue / scheduler
- follow-ups & traps
- Freshness; typo tolerance; personalisation; sharding the index; per-domain politeness.
- start with
- Autocomplete → Web Crawler → Full-Text Search
- Search Autocomplete / Typeahead (opens in a new tab) medium · core · W6
Suggest the top completions for each keystroke within milliseconds, updated by popularity.
key ideas: Trie / prefix index, top-K per prefix, caching, freshness
Uber · Google · Amazon
- Web Crawler (opens in a new tab) medium · core · W6
Crawl billions of pages politely: URL frontier, de-duplication, robots.txt, and re-crawling.
key ideas: URL frontier, politeness, dedup, scheduling, DNS caching
Google · eBay · Meta
- Full-Text Search (posts / products) (opens in a new tab) hard · ★ extra
Keyword search over many documents with an inverted index, ranking, and near-real-time updates.
key ideas: Inverted index, tokenising, ranking, index updates and sharding
H6 Stream Aggregation & Analytics 4
how to approach · start with Top-K → Ad Click Aggregator → Metrics
Ingest massive event streams and answer aggregate questions (counts, Top-K) with bounded error and latency.
steps
- Clarify accuracy vs latency (exact vs approximate).
- Ingest through a partitioned log (Kafka).
- Window + aggregate in a stream processor.
- Store rollups in OLAP / TSDB.
- Handle late events and duplicates.
- patterns
- Kafka, stream processing, count-min sketch, TSDB / OLAP, dedup
- follow-ups & traps
- Exactly-once; hot keys; backfill; cardinality explosion.
- start with
- Top-K → Ad Click Aggregator → Metrics
- Distributed Logging System (opens in a new tab) easy · skim
Collect logs from thousands of services, then store, search and retain them cheaply.
key ideas: Agents → Kafka → storage/index, retention, search
Uber
- Top-K / Leaderboard System (opens in a new tab) medium · W7
Live top-K (most played, highest scores) over a stream of events, exact or approximate.
key ideas: Count-min sketch, heaps, windowed aggregation, Redis sorted sets
Uber
- Ad Click Aggregator (opens in a new tab) hard · W7
Count ad clicks per ad per minute, accurately and fast, without double counting.
key ideas: Stream processing, exactly-once, late events, dedup, OLAP store
Meta · Google · TikTok
-
Ingest metrics from many hosts, store time series, and power dashboards and alerts.
key ideas: Ingest → TSDB, rollups, alerting, cardinality
Google · Facebook · Amazon · Datadog · Atlassian · Stripe
H7 Core Distributed Infrastructure 10
how to approach · start with URL Shortener → Rate Limiter → Job Scheduler → KV Store → Kafka
The reusable pieces everything else is built from: limiters, KV stores, caches, queues, schedulers, locks.
steps
- Define the API + guarantees (at-least-once? ordering?).
- Partition data (consistent hashing).
- Replicate (leader / follower, quorum).
- Define failure behaviour (what happens when a node dies).
- Add observability + backpressure.
- patterns
- Consistent hashing, replication / quorum, Raft / Paxos, leases / fencing tokens, WAL
- follow-ups & traps
- Hot partitions; rebalancing; clock skew; split brain; exactly-once.
- start with
- URL Shortener → Rate Limiter → Job Scheduler → KV Store → Kafka
- URL Shortener (TinyURL) (opens in a new tab) easy · core · W5
Turn long URLs into short codes and redirect fast; ID generation, caching and analytics.
key ideas: Base62/hash IDs, KV store, caching, redirect latency, multi-DC
Uber · Amazon · LinkedIn · Palantir · Google · Microsoft · Meta · Atlassian
- Rate Limiter (distributed) (opens in a new tab) easy · core · W5
Limit requests per user across many servers with shared counters and low added latency.
key ideas: Token bucket/sliding window in Redis, race conditions, per-tenant config
Amazon · Atlassian · Uber · Microsoft · Stripe · Pinterest · Google
- Distributed Key-Value Store (opens in a new tab) medium · W7
A Dynamo-style store: partitioning, replication, quorum reads and writes, and failure handling.
key ideas: Consistent hashing, replication, quorum, LSM trees
Google · Anthropic
- Job Scheduler (opens in a new tab) medium · core · W5
Run millions of scheduled and recurring jobs on time, at least once, with retries.
key ideas: Delayed/recurring jobs, at-least-once execution, sharding, leases
Google · Amazon · Microsoft · DoorDash · Netflix · Atlassian
- Online Coding Judge (opens in a new tab) medium · skim
Run user code safely in sandboxes, judge it against test cases, and handle contest spikes.
key ideas: Sandboxing, execution queue, isolation, result delivery
Meta · Google
- Distributed Cache (opens in a new tab) medium · skim
A shared cache like Redis: sharding with consistent hashing, replication and eviction.
key ideas: Sharding, eviction, hot keys, replication, invalidation
- Distributed Message Queue (Kafka-like) hard · W7 · ★ extra
Durable, partitioned log with producers, consumer groups, ordering and replay.
key ideas: Partitioning, replication/ISR, ordering, consumer rebalancing
-
Let services hold locks safely across machines using consensus, leases and fencing tokens.
key ideas: Paxos/Raft, leases, fencing tokens, clock issues
- Code Deployment System (opens in a new tab) hard · skim
Build once and roll out to thousands of machines fast and safely, with rollback.
key ideas: Build/artifact pipeline, rollout strategies, rollback, health checks
- Distributed ID Generator (Snowflake) + Distributed Counter hard · skim · ★ extra
Generate unique, roughly ordered IDs without a central bottleneck, and count at scale.
key ideas: Clock skew, sharded counters, uniqueness vs ordering
H8 AI / LLM Infrastructure 5
how to approach · start with LLM Gateway → GPU Inference Batching → RAG / Semantic Search
GPU-heavy, long-running, expensive requests: batching, scheduling and metering matter most.
steps
- Define latency vs throughput targets.
- Queue + dynamic batching to keep GPUs busy.
- Fair scheduling + preemption / checkpointing for long jobs.
- Meter tokens / cost for quotas.
- Distribute large model artefacts with versioned rollouts.
- patterns
- Queues, schedulers, token-bucket quotas, caching, blob distribution
- follow-ups & traps
- Cold start; autoscaling; noisy neighbours; cost control.
- start with
- LLM Gateway → GPU Inference Batching → RAG / Semantic Search
-
Queue and run long, expensive GPU jobs (e.g. video generation) fairly, with progress and retries.
key ideas: Queueing, fair scheduling, preemption, checkpointing, cost
Google
-
Limit and bill AI usage by tokens rather than requests, per user and per agent.
key ideas: Token accounting, quotas, burst vs sustained, consistency
Google
-
Serve a large model with low latency by batching requests on GPUs and streaming tokens back.
key ideas: Dynamic batching, queueing, latency/throughput, autoscaling
Anthropic · Google · OpenAI
- LLM Gateway (multi-provider routing & fallback) medium · ★ extra
One API in front of several LLM providers: routing, automatic fallback, quotas and cost tracking.
key ideas: Unified API, provider adapters, routing, fallback, quotas, cost tracking
- RAG / Semantic Search System hard · ★ extra
Answer questions over your documents: chunk and embed them, search a vector index, and ground the answer.
key ideas: Chunking + embeddings, vector index, retrieval + re-ranking, freshness
No problems match these filters.
## reference cheat sheets
5 LLD patterns that solve most problems
- Strategy
- A behaviour has several interchangeable algorithms (pricing, eviction, matching, rules).
- e.g. Rate limiter algorithms, LRU/LFU eviction, parking pricing, split types
- State
- An object behaves differently depending on its state; transitions are rule-driven.
- e.g. Vending machine, elevator, order / payment lifecycle, game status
- Observer
- Many parties must react when something changes.
- e.g. Notification service, pub/sub, price alerts, UI updates
- Factory
- Object creation depends on type or config and callers should not know the concrete class.
- e.g. Vehicle / piece / limiter creation, notification channels
- Command
- Operations must be queued, logged, undone or replayed.
- e.g. Text editor undo/redo, canvas commands, transaction log
12 HLD building blocks
- Caching & invalidation
- Reach for it when: Read-heavy traffic, hot keys
- Trade-off: Staleness, invalidation complexity
- shows up in URL shortener, feed, autocomplete
- Sharding / consistent hashing
- Reach for it when: Data or QPS exceeds one node
- Trade-off: Hot shards, rebalancing, cross-shard queries
- shows up in KV store, cache, chat
- Replication & quorum
- Reach for it when: Availability and durability
- Trade-off: Consistency vs latency (CAP / PACELC)
- shows up in KV store, DBs, queues
- Queues & streams (Kafka)
- Reach for it when: Async work, smoothing spikes
- Trade-off: At-least-once ⇒ need idempotency; ordering only per partition
- shows up in Notifications, ad clicks, logging
- Fan-out on write vs read
- Reach for it when: One-to-many delivery
- Trade-off: Write amplification vs read latency
- shows up in Feed, notifications, group chat
- Idempotency & exactly-once effects
- Reach for it when: Retries, payments, bookings
- Trade-off: Needs key storage and a dedup window
- shows up in Payments, ticketing, ledger
- Geo-indexing
- Reach for it when: Location queries
- Trade-off: Cell-boundary issues, hotspots
- shows up in Uber, maps, delivery
- Blob storage + metadata + CDN
- Reach for it when: Large media and files
- Trade-off: Metadata consistency, cost, durability
- shows up in Dropbox, YouTube, S3
- Search: inverted index / trie
- Reach for it when: Text and prefix queries
- Trade-off: Index freshness and size
- shows up in Autocomplete, search, crawler
- Stream aggregation & sketches
- Reach for it when: Counts / Top-K on streams
- Trade-off: Approximation error, late data
- shows up in Ad clicks, metrics, Top-K
- Rate limiting
- Reach for it when: Protect services, meter usage
- Trade-off: Accuracy vs cost; distributed counters
- shows up in API gateway, AI billing
- Consensus & locking (Raft, leases, fencing)
- Reach for it when: Leader election, coordination
- Trade-off: Latency, complexity, clock skew
- shows up in Lock service, scheduler, KV store
concurrency checklist
- 1. What is the shared state?
- Write down every variable touched by more than one thread and who writes it.
- 2. What invariant must always hold?
- E.g. 0 ≤ size ≤ capacity; a seat has at most one owner. Check it after every critical section.
- 3. What should a thread wait for?
- Express it as a condition on shared state; wait in a while loop, never if.
- 4. Who wakes it up, and when?
- Signal after every state change that can satisfy a waiter (signalAll if unsure).
- Deadlock = 4 conditions
- Mutual exclusion, hold-and-wait, no preemption, circular wait. Break one — usually via global lock ordering or tryLock with timeout.
- Lock granularity
- Global lock → striped / per-key lock → lock-free (CAS). Justify the choice with contention and complexity.
- Always release in finally
- Unlock / release in finally so exceptions cannot leave a lock held.
interview time-boxes
- LLD / machine coding (60 min)
- Clarify 5 → entities 5 → class diagram + APIs 10 → code core flow 25 → edge cases + concurrency 8 → extensibility / follow-ups 7.
- HLD (45 min)
- Requirements 5 → estimation 5 → API 5 → data model 5 → high-level design 10 → deep dive on 2 components 10 → bottlenecks, failures, trade-offs 5.
- Multithreading round
- State the shared state + invariant first → write the simple version → add synchronisation → walk through 2 threads → discuss follow-ups (timeouts, shutdown, fairness).