Interview Q&A / System Design

INTERVIEW Q&A · 70 QUESTIONS

System Design interview questions

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

  1. What is the difference between sharding and partitioning?

    Partitioning splits a big table into smaller parts, often inside one database. Sharding is partitioning where the parts live on different servers, so both data and load are spread across machines.

    BeginnerQuick answer1 min read
  2. What is the difference between SLI, SLO and SLA?

    An SLI is a measured number like request success rate. An SLO is the internal target for that number, such as 99.9%. An SLA is the contract with customers that promises a level and usually names a penalty if missed.

    BeginnerQuick answer1 min read
  3. What is the difference between strong and eventual consistency?

    Strong consistency means every read sees the latest completed write. Eventual consistency means replicas may briefly return old data but will all converge to the same value if no new writes arrive.

    BeginnerQuick answer1 min read
  4. When does the cleanup function returned from useEffect run?

    React runs it before the effect runs again and when the component unmounts. Use it to undo what the effect set up: clear timers, remove listeners, close connections or cancel requests.

    BeginnerQuick answer1 min read
  5. When would you choose vertical scaling over horizontal scaling?

    Choose vertical scaling when the system is small, stateful, or hard to split, such as a single relational database. It is simple and fast to do, but it has a hardware ceiling and leaves one machine as a single point of failure.

    BeginnerQuick answer1 min read
  6. Which HTTP methods are safe and which are idempotent?

    Safe methods (GET, HEAD, OPTIONS) don't change server state. Idempotent methods (GET, PUT, DELETE and the safe ones) give the same result when repeated. POST is neither, and PATCH is not guaranteed idempotent.

    BeginnerQuick answer1 min read
  7. Which HTTP status codes should every API developer know?

    Know the families: 2xx success (200, 201, 204), 3xx redirect (301, 304), 4xx client error (400, 401, 403, 404, 409, 429), 5xx server error (500, 502, 503, 504). The code tells clients whether retrying can help.

    BeginnerQuick answer1 min read
  8. Why are stateless services easier to scale horizontally?

    A stateless server keeps no per-user data in its own memory, so any server can handle any request. You can add, remove or replace servers freely behind a load balancer, with no sticky routing.

    BeginnerQuick answer1 min read
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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
  23. 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
  24. 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
  25. 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
  26. 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
  27. 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
  28. 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
  29. 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
  30. 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