Building blocks and trade-offs
Every design is assembled from the same blocks: load balancers, stateless app servers, caches, databases, queues, object storage and CDNs. Interviewers grade how you choose between them and explain what you give up.
- ScaleHorizontal scaling and load balancing.
- DataCaching, replication and sharding.
- ReliabilityQueues, rate limits and availability.
System design rounds are no longer only for senior engineers — many product companies now give freshers a simplified version. You are not expected to know one right answer. You are expected to ask good questions, sketch a sensible architecture, and explain trade-offs using the building blocks below.
1. How do you approach a system design question?
Use a steady structure: 1) Clarify requirements — functional (what it does) and non-functional (users, latency, availability). 2) Estimate scale — requests per second, storage per year. 3) Define the API and data model. 4) Draw the high-level design. 5) Deep-dive into the hardest part. 6) Discuss bottlenecks and trade-offs.
2. Vertical vs horizontal scaling?
Vertical scaling means a bigger machine — simple, but it has a ceiling and is a single point of failure. Horizontal scaling means more machines behind a load balancer — nearly unlimited and fault-tolerant, but it requires stateless services and shared storage for sessions and files.
3. What does a load balancer do?
It spreads requests across servers, removes unhealthy servers using health checks, and can terminate TLS. Algorithms include round robin, least connections and consistent hashing (for cache affinity). Layer 4 balancers route by IP and port; Layer 7 balancers route by URL, headers or cookies.
4. Explain caching strategies.
Cache-aside (most common): read from the cache, on a miss load from the database and store it. Write-through: write to cache and database together. Write-back: write to cache and flush later — fast but risky. Set a TTL, choose an eviction policy (usually LRU), and plan invalidation, the hard part. Use a CDN to cache static files and pages close to users.
get_user(id):
user = cache.get("user:" + id)
if user is null:
user = db.query("SELECT * FROM users WHERE id = ?", id)
cache.set("user:" + id, user, ttl = 10 minutes)
return user5. How do you scale a database?
In order of effort: add the right indexes and fix queries; add a cache; add read replicas for read-heavy load; partition large tables; and finally shard — split data across databases by a key such as user id. Sharding makes joins and transactions across shards hard, so delay it until you must.
6. Why use a message queue?
A queue (Kafka, RabbitMQ, SQS) decouples producers from consumers: the web request just enqueues “send welcome email” and returns immediately, while workers process jobs at their own pace. It absorbs traffic spikes, allows retries and lets several services react to the same event. Consumers should be idempotent because messages can be delivered more than once.
7. What is rate limiting and how is it implemented?
Rate limiting protects services from abuse and overload by capping requests per user or IP. The token bucket algorithm adds tokens at a fixed rate and each request spends one, allowing short bursts. In a distributed system the counters live in a shared store such as Redis; clients receive HTTP 429 with a Retry-After header.
8. What do availability numbers like 99.9% mean?
99.9% (“three nines”) allows about 8.8 hours of downtime a year; 99.99% allows about 53 minutes. You get there with redundancy at every layer (multiple servers, zones and replicas), health checks, automatic failover, graceful degradation and good monitoring.
Remember
Key points
- Requirements first
Never draw boxes before clarifying scale and features.
- Stateless services scale
Keep sessions and files in shared stores.
- Cache-aside by default
Plan TTLs and invalidation.
- Shard last
Indexes, caches and replicas come first.
Interview drill
Follow-up questions
What the interviewer asks after your first answer. Turn on practice mode, answer each one aloud, then reveal.
-
1 What is the difference between latency and throughput? Basic
Latency is how long one request takes; throughput is how many requests the system handles per second. Improving one can hurt the other (batching raises throughput but adds latency).
-
2 What is a CDN and when would you use one? Basic
A network of edge servers that cache content close to users — images, scripts, videos and even whole pages — cutting latency and origin load.
-
3 What is a cache stampede and how do you prevent it? Advanced
When a popular key expires, thousands of requests hit the database at once. Prevent it with a lock so one request refreshes the value, staggered TTLs, or serving stale data while refreshing.
-
4 What does idempotent mean and why does it matter? Intermediate
Doing an operation twice has the same effect as once. With retries and at-least-once delivery, idempotency keys prevent double payments and duplicate orders.
-
5 Monolith or microservices for a new product? Intermediate
Usually a well-structured monolith first: faster to build and run. Split into services when team size or very different scaling needs make it worthwhile.