Hack4Hack

System Design practice questions with answers

Practise system design questions at your own pace: scaling, load balancing, caching, sharding, queues, consistency and APIs. Pick an answer to see whether you are right and why. Nothing is timed or ranked here; for that, play the Daily Quiz at 4 PM IST.

  1. What does a load balancer do?

    easy

    1. Stores user sessions
    2. Spreads incoming requests across several servers
    3. Compresses images
    4. Backs up the database

    Answer: B. Spreads incoming requests across several servers

    Explanation: It improves capacity and availability: if one server fails, traffic goes to the others.

  2. Horizontal scaling means:

    easy

    1. Buying a bigger server
    2. Adding more servers
    3. Adding more columns
    4. Making the UI wider

    Answer: B. Adding more servers

    Explanation: Vertical scaling is a bigger machine (it has limits). Horizontal scaling adds machines, which works best with stateless services.

  3. What is a CDN used for?

    easy

    1. Running database queries
    2. Serving static content such as images and scripts from servers close to users
    3. Sending email
    4. Authenticating users

    Answer: B. Serving static content such as images and scripts from servers close to users

    Explanation: Edge servers cache content near users, cutting latency and load on the origin.

  4. Why add a cache like Redis in front of a database?

    easy

    1. To store data permanently
    2. To serve frequently read data from memory, faster and with less load on the database
    3. To replace the database
    4. To encrypt data

    Answer: B. To serve frequently read data from memory, faster and with less load on the database

    Explanation: The hard parts are deciding what to cache and when to invalidate it so users do not see stale data.

  5. What is database sharding?

    medium

    1. Making backups
    2. Splitting data across several databases by a key, such as user id, so each holds a part
    3. Adding indexes
    4. Encrypting rows

    Answer: B. Splitting data across several databases by a key, such as user id, so each holds a part

    Explanation: Sharding scales writes and storage, but cross-shard queries and re-balancing become harder.

  6. Why use a message queue (Kafka, RabbitMQ, SQS) between services?

    medium

    1. To make requests synchronous
    2. To decouple producers from consumers, absorb traffic spikes and process work asynchronously with retries
    3. To store images
    4. To replace the API

    Answer: B. To decouple producers from consumers, absorb traffic spikes and process work asynchronously with retries

    Explanation: For example, an upload service queues "resize image" jobs that workers process at their own pace.

  7. What does rate limiting protect against?

    medium

    1. Slow disks
    2. Clients sending too many requests, whether by accident, abuse or attack
    3. SQL syntax errors
    4. Expired certificates

    Answer: B. Clients sending too many requests, whether by accident, abuse or attack

    Explanation: Common algorithms are the token bucket and the sliding window. Return HTTP 429 when a client is over its limit.

  8. What is eventual consistency?

    medium

    1. Data is never consistent
    2. Replicas may briefly disagree but converge to the same value if no new writes arrive
    3. Every read sees the latest write immediately
    4. Consistency checked once a day

    Answer: B. Replicas may briefly disagree but converge to the same value if no new writes arrive

    Explanation: It is the trade-off many distributed systems make for availability and speed, for example like counts on a social feed.

  9. How would a URL shortener generate short, unique codes at scale?

    hard

    1. Random 2-character strings
    2. Encode a unique id (from a counter or distributed id generator) in base62
    3. Use the full URL as the key
    4. Hash with MD5 and keep the first character

    Answer: B. Encode a unique id (from a counter or distributed id generator) in base62

    Explanation: Base62 with 7 characters gives about 3.5 trillion codes. Pure hashing needs collision handling.

  10. What is consistent hashing used for?

    hard

    1. Password storage
    2. Spreading keys across cache or storage nodes so adding or removing a node moves only a small share of keys
    3. Encrypting traffic
    4. Sorting data

    Answer: B. Spreading keys across cache or storage nodes so adding or removing a node moves only a small share of keys

    Explanation: With plain hash(key) % N, changing N remaps almost every key. Consistent hashing remaps about 1/N of them.

  11. What does an idempotent API operation guarantee?

    hard

    1. It is fast
    2. Repeating the same request has the same effect as doing it once, so retries are safe
    3. It needs no authentication
    4. It never fails

    Answer: B. Repeating the same request has the same effect as doing it once, so retries are safe

    Explanation: Payments use idempotency keys so a retried request after a timeout does not charge twice. GET, PUT and DELETE are meant to be idempotent; POST usually is not.

  12. Which are good ways to make a read-heavy news feed fast? (Select all that apply)

    hard

    1. Cache popular feeds in memory
    2. Precompute (fan out) feeds when posts are written
    3. Paginate with cursors instead of large offsets
    4. Run a full table scan on every request

    Answer: A. Cache popular feeds in memory; B. Precompute (fan out) feeds when posts are written; C. Paginate with cursors instead of large offsets

    Explanation: Fan-out-on-write suits most users; very popular accounts are often merged at read time instead. Cursor pagination stays fast deep into a feed.

Play the Daily Quiz at 4 PM IST