System design basics: the fundamentals interviewers expect 14 questions in 5 chapters

  1. 01Sizing
  2. 02Traffic4 questions
  3. 03Data3 questions
  4. 04Reliability
  5. 05Coordination4 questions

Sizing

  • 1.1 How do you do a back-of-the-envelope estimate, and how does it change your design? Easy 3 min

    I turn the requirements into a few numbers: average and peak requests per second, read-to-write ratio, storage per year and bandwidth. Then I compare them with what one machine or one database can do, because that tells me which problems are real. If the peak is a few dozen writes a second, one well-indexed database is fine and I don't bring up sharding at all; if it's hundreds of thousands, partitioning becomes the core of the design.

    Read the full answer

Traffic

  • 2.1 What does a load balancer do, and what is the difference between L4 and L7 load balancing? Easy 3 min

    A load balancer spreads requests across healthy servers so no single one is overloaded and a failed one stops getting traffic. A layer 4 balancer routes TCP or UDP connections by address and port without reading the request, so it is fast and protocol-agnostic. A layer 7 balancer understands HTTP, so it can route by path, host or header, terminate TLS and retry, at the cost of more work per request.

    Read the full answer
  • 2.2 What is a CDN, and when does it help? Easy 2 min

    A CDN is a network of servers in many locations that keeps cached copies of content close to users. A request goes to the nearest edge; if the edge has the file it answers immediately, otherwise it fetches from my origin once and caches it. It helps most for static assets and cacheable responses, because it cuts latency for distant users and takes load off my servers.

    Read the full answer
  • 2.3 How do you keep a cache in sync with the database, and what is a cache stampede? Medium 3 min

    The default is cache-aside: read from the cache, on a miss read the database and fill the cache, and on a write update the database and delete the cache key. Every key also gets a TTL so a missed invalidation heals itself. A stampede is when a hot key expires and many requests miss at once and all hit the database; I prevent it with one request refilling while others wait, early refresh, and random jitter on TTLs.

    Read the full answer
  • 2.4 How does rate limiting work, and which algorithm would you choose? Medium 3 min

    A rate limiter caps how many requests a client can make in a period and rejects the excess with 429 Too Many Requests, ideally with a Retry-After header. Token bucket is my default: tokens refill at a steady rate, each request takes one, and the bucket size allows short bursts. Fixed windows are simplest but allow double bursts at the window edges, and a sliding window fixes that at a little more cost.

    Read the full answer

Data

  • 3.1 How does database replication work, and what is replica lag? Medium 3 min

    Replication keeps copies of the data on several nodes for availability and read scaling. Most systems use one leader that takes writes and followers that copy its log; multi-leader and leaderless setups accept writes in several places but must resolve conflicts. With asynchronous replication a follower can be behind, which is replica lag, so a user may not see their own write if the next read goes to a replica.

    Read the full answer
  • 3.2 How do you shard data, and how do you choose a shard key? Medium 3 min

    Sharding splits one dataset across several databases by a key, so each node holds and serves only part of it. Range sharding keeps nearby keys together and is good for range scans but can create hot ranges; hash sharding spreads load evenly but loses ordering. I pick a key with many distinct values that matches the main access pattern, like tenant or user id, and I use consistent hashing or many small virtual partitions so adding nodes moves little data.

    Read the full answer
  • 3.3 Your database is getting slow as traffic grows. What do you do, in what order? Medium 3 min

    I climb a ladder from cheapest to most expensive. First find the slow queries and fix them with indexes and better queries, then add connection pooling and caching, then move reads to replicas, then scale the machine up. Only when writes or data size outgrow one primary do I partition, and sharding is the last step because it changes the application.

    Read the full answer

Reliability

  • 4.1 How do you make a service fault tolerant when its dependencies fail? Medium 3 min

    I assume every remote call can hang or fail. Every call gets a timeout, retries are limited and use exponential backoff with jitter, and only one layer retries. A circuit breaker stops calling a dependency that keeps failing, bulkheads keep one slow dependency from using up all threads or connections, and when something is down I degrade gracefully, for example by serving cached or partial results instead of an error.

    Read the full answer
  • 4.2 How do services find each other in a microservices system? Easy 2 min

    Instances come and go, so their addresses can't be hard-coded; a service registry keeps the current list of healthy instances. With client-side discovery the caller asks the registry and picks an instance itself; with server-side discovery the caller hits a load balancer or proxy that does the lookup. In Kubernetes I just use a Service: it gets a stable DNS name and virtual IP, and the platform keeps the list of ready pods behind it.

    Read the full answer

Coordination

  • 5.1 What consistency models should you know, from linearizable to eventual? Medium 3 min

    Linearizable is the strongest for a single object: every operation looks like it happened at one instant, in real-time order, as if there were one copy. Sequential keeps one order everyone agrees on but not tied to real time, and causal only orders operations that depend on each other. Read-your-writes guarantees a user sees their own updates, and eventual only promises replicas converge if writes stop. I pick the weakest model the feature can tolerate, because stronger models cost latency and availability.

    Read the full answer
  • 5.2 What are two-phase commit, sagas and the outbox pattern, and when do you use each? Medium 3 min

    Two-phase commit makes several databases commit or abort together: a coordinator asks everyone to prepare, then tells them all to commit. It's atomic, but if the coordinator dies after prepare, participants are stuck holding locks, so it's rarely used across microservices. A saga is a chain of local transactions with compensating actions to undo earlier steps, and the outbox pattern makes "update my database and publish an event" reliable by writing the event in the same local transaction.

    Read the full answer
  • 5.3 How does leader election work, and how do you prevent split-brain? Hard 3 min

    Leader election picks one node to do a job, like accepting writes or running a scheduler. The safe ways are consensus, like Raft, where a leader needs votes from a majority, or a lease in a strongly consistent store that the leader must keep renewing. The danger is an old leader that was paused and still thinks it leads, so every write carries a fencing token, an increasing number, and storage rejects writes with an older token.

    Read the full answer
  • 5.4 How do idempotency keys make retries safe for a payment API? Medium 3 min

    The client generates a unique key, like a UUID, and sends it in an Idempotency-Key header with the POST. The server stores the key with the result of the first request; a retry with the same key gets the stored result instead of charging again. If the same key comes with a different body I reject it, and if the first request is still running I return a conflict.

    Read the full answer