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.
What does a load balancer do?
easy
- Stores user sessions
- Spreads incoming requests across several servers
- Compresses images
- 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.
Horizontal scaling means:
easy
- Buying a bigger server
- Adding more servers
- Adding more columns
- 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.
What is a CDN used for?
easy
- Running database queries
- Serving static content such as images and scripts from servers close to users
- Sending email
- 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.
Why add a cache like Redis in front of a database?
easy
- To store data permanently
- To serve frequently read data from memory, faster and with less load on the database
- To replace the database
- 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.
What is database sharding?
medium
- Making backups
- Splitting data across several databases by a key, such as user id, so each holds a part
- Adding indexes
- 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.
Why use a message queue (Kafka, RabbitMQ, SQS) between services?
medium
- To make requests synchronous
- To decouple producers from consumers, absorb traffic spikes and process work asynchronously with retries
- To store images
- 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.
What does rate limiting protect against?
medium
- Slow disks
- Clients sending too many requests, whether by accident, abuse or attack
- SQL syntax errors
- 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.
What is eventual consistency?
medium
- Data is never consistent
- Replicas may briefly disagree but converge to the same value if no new writes arrive
- Every read sees the latest write immediately
- 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.
How would a URL shortener generate short, unique codes at scale?
hard
- Random 2-character strings
- Encode a unique id (from a counter or distributed id generator) in base62
- Use the full URL as the key
- 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.
What is consistent hashing used for?
hard
- Password storage
- Spreading keys across cache or storage nodes so adding or removing a node moves only a small share of keys
- Encrypting traffic
- 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.
What does an idempotent API operation guarantee?
hard
- It is fast
- Repeating the same request has the same effect as doing it once, so retries are safe
- It needs no authentication
- 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.
Which are good ways to make a read-heavy news feed fast? (Select all that apply)
hard
- Cache popular feeds in memory
- Precompute (fan out) feeds when posts are written
- Paginate with cursors instead of large offsets
- 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.