Interview Q&A / System Design

INTERVIEW Q&A · 70 QUESTIONS

System Design interview questions

Caching, scaling, databases and classic design problems for beginners.

  1. Why do engineers track p95 and p99 latency instead of the average?

    Averages hide slow outliers. p99 means 99% of requests were faster than this value, so it shows what your unluckiest users feel, which is what drives complaints and timeouts.

    BeginnerQuick answer1 min read
  2. Why does my useEffect run twice in development?

    In Strict Mode, React 18 and later deliberately mounts, unmounts and remounts each component once in development to check that effects clean up properly. It does not happen in production.

    BeginnerQuick answer1 min read
  3. Can you give a simple example of when Layer 7 load balancing is necessary?

    Layer 7 is needed when routing depends on request content, such as the URL path, headers or cookies. For example, sending /api traffic to API servers and /images traffic to a media cluster.

    IntermediateQuick answer1 min read
  4. How do Cache-Control and ETag headers work together?

    Cache-Control says how long a response may be reused without asking. ETag is a fingerprint of the content; after expiry the browser sends it back, and the server replies 304 Not Modified if nothing changed, saving the download.

    IntermediateQuick answer1 min read
  5. How do polling, long polling, SSE and WebSockets differ for real-time updates?

    Polling asks repeatedly; long polling holds each request open until there is news; SSE streams server-to-client over one HTTP connection; WebSockets give a two-way channel. Choose by direction of data and scale.

    IntermediateQuick answer1 min read
  6. How do you choose a good shard key?

    A good shard key has high cardinality, spreads data and traffic evenly, and matches the most common query so requests hit one shard. Avoid keys that grow monotonically or are skewed, like timestamps or country.

    IntermediateQuick answer1 min read
  7. How do you make a message consumer idempotent?

    Record the id of each processed message in the same transaction as its effect, and skip ids already seen. Or design the operation to be naturally repeatable, such as setting a value rather than incrementing it.

    IntermediateQuick answer1 min read
  8. How do you update a file that is already cached on a CDN?

    Either purge the URL on the CDN, which is slow and rate limited, or better, put a version or content hash in the filename, such as app.3f9a1c.js. A new name is a new cache entry, so there is nothing to invalidate.

    IntermediateQuick answer1 min read
  9. How do you version a public API without breaking existing clients?

    Put the version in the URL (/v1/) or a header, never change the meaning of existing fields, add new fields as optional, and announce deprecations with a long sunset period. Prefer additive changes so versions are rarely needed.

    IntermediateQuick answer1 min read
  10. How does an idempotency key stop duplicate payments?

    The client sends a unique key with each payment request. The server stores the key with the result; if the same key arrives again, it returns the saved result instead of charging again.

    IntermediateQuick answer1 min read
  11. How does DNS-based global load balancing route users to the nearest data centre?

    The DNS service answers with a different IP depending on where the user is, which server is healthy, or latency measurements. Users in Mumbai get the Mumbai address, users in London get London's.

    IntermediateQuick answer1 min read
  12. How does Kafka keep messages in order, and what role do partitions play?

    Kafka guarantees order only within a single partition. Messages with the same key go to the same partition, so ordering holds per key. More partitions give more parallelism but no global order.

    IntermediateQuick answer1 min read
  13. In CAP, why is partition tolerance not really a choice?

    Network partitions happen in any real distributed system, so you cannot opt out of P. The real decision is what to do during a partition: refuse some requests to stay consistent (CP) or answer with possibly stale data (AP).

    IntermediateQuick answer1 min read
  14. What does at-least-once delivery mean, and can you get exactly-once?

    At-least-once means a message is never lost but may be delivered more than once. True exactly-once delivery is not practical across a network, so systems use at-least-once plus idempotent consumers to get exactly-once effects.

    IntermediateQuick answer1 min read
  15. What is a cache stampede and how do you prevent it?

    A cache stampede happens when a popular key expires and many requests miss at once, all hitting the database together. Prevent it with request coalescing or locks, jittered TTLs, and refreshing entries before they expire.

    IntermediateQuick answer1 min read
  16. What is a hot partition and how do you fix it?

    A hot partition is a shard or partition that receives far more traffic than the rest, so it becomes the bottleneck. Fix it with better keys, key salting, splitting the hot shard, or caching hot items.

    IntermediateQuick answer1 min read
  17. What is a stale closure in a React effect, and how do you fix it?

    A closure captures the values from the render where it was created. An effect with a missing dependency keeps using old values. Fix it by listing the dependency, using the updater form of setState, or storing the latest value in a ref.

    IntermediateQuick answer1 min read
  18. What is backpressure and how do you handle a queue that keeps growing?

    Backpressure means slowing or limiting producers when consumers cannot keep up. For a growing queue, add consumers, make processing faster, reject or throttle new work, and set limits so the queue cannot grow without bound.

    IntermediateQuick answer1 min read
  19. What is lazy initialisation in useState, and when should you use it?

    Pass a function to useState, as in useState(() => compute()). React runs it only on the first render. Without the function form, the expensive call runs on every render, even though its result is ignored after the first.

    IntermediateQuick answer1 min read
  20. What is the difference between synchronous and asynchronous replication?

    Synchronous replication makes the leader wait for replicas to confirm before acknowledging a write, so no acknowledged write is lost but writes are slower. Asynchronous replies immediately and replicates later, which is faster but can lose recent writes.

    IntermediateQuick answer1 min read
  21. What is the difference between write-through and write-back caching?

    Write-through writes to the cache and the database together before replying, so data is safe but writes are slower. Write-back writes to the cache first and flushes to the database later, which is faster but can lose data on a crash.

    IntermediateQuick answer1 min read
  22. What is the N+1 problem in GraphQL and how is it solved?

    N+1 happens when fetching a list triggers one query for the list and then one extra query per item for a nested field. DataLoader batches those per-item lookups into a single query.

    IntermediateQuick answer1 min read
  23. When would you choose useReducer over useState?

    Choose useReducer when state has several related fields, or the next state depends on complex rules and actions. It centralises update logic in one pure function, which is easier to test and reason about than many scattered setters.

    IntermediateQuick answer1 min read
  24. When would you pick Redis over Memcached for a cache?

    Memcached is a simple, fast key-value cache. Redis adds data structures (lists, sets, sorted sets), optional persistence, replication and pub/sub, so choose Redis when you need more than plain get and set.

    IntermediateQuick answer1 min read
  25. When would you use gRPC instead of REST?

    Use gRPC for fast, strongly typed communication between internal services and for streaming. It uses HTTP/2 and Protocol Buffers, which are compact and quick, but browsers and public clients find REST easier.

    IntermediateQuick answer1 min read
  26. Why is returning a total count with every page expensive, and what are the alternatives?

    COUNT(*) over a large filtered table scans many rows on every request. Alternatives are returning only has_next, using approximate counts, caching the count, or showing 'more than 1,000' instead of an exact total.

    IntermediateQuick answer1 min read
  27. Why must a reducer function be pure, and what breaks if it is not?

    React may call a reducer more than once with the same inputs, for example in Strict Mode. A pure reducer returns a new state from state and action only. Mutating state or running side effects inside it gives wrong or duplicated results.

    IntermediateQuick answer1 min read
  28. Why should retries use exponential backoff with jitter?

    Backoff spaces out retries (1s, 2s, 4s...) so a struggling service gets room to recover. Jitter adds randomness so thousands of clients do not all retry at the same instant and cause a retry storm.

    IntermediateQuick answer1 min read
  29. How do you add more shards to a running system without a long outage?

    Avoid plain modulo hashing, which moves most keys when the shard count changes. Use consistent hashing or many small virtual shards mapped to servers, then move a few of them in the background while dual-checking routing.

    AdvancedQuick answer1 min read
  30. What is the difference between useEffect and useLayoutEffect?

    useEffect runs after the browser has painted. useLayoutEffect runs after DOM changes but before paint, and blocks painting. Use the layout version only to measure or adjust the DOM so users do not see a flicker.

    AdvancedQuick answer1 min read