Interview Q&A / System Design

INTERVIEW Q&A · 70 QUESTIONS

System Design interview questions

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

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. What is the PACELC theorem and how does it extend CAP?

    PACELC says: if there is a Partition, choose Availability or Consistency; Else, when running normally, choose between Latency and Consistency. It captures that consistency costs latency even when nothing is broken.

    AdvancedQuick answer1 min read
  10. What is the transactional outbox pattern and what problem does it solve?

    It solves the dual-write problem: updating a database and publishing an event can't be atomic. The outbox writes the event into a table in the same database transaction, and a separate process publishes it to the broker.

    AdvancedQuick answer1 min read