Getting everything ready for you…

Loading courses, problems and your progress. This takes just a moment.

0s

System Design Documentation

System design on one page — the interview method, key numbers, scaling, caching, databases, CAP, queues, reliability and question templates.

System design on one page: the method, the numbers, every building block with its trade-offs, and templates for common questions. New to this? Read System Design for Freshers first.

1. The Interview Method

  1. Requirements: functional (what it does) and non-functional (scale, latency, availability).
  2. Estimates: users, requests per second, storage.
  3. API: the main endpoints.
  4. Data model: tables and keys; SQL or NoSQL.
  5. High-level design: client → load balancer → servers → cache → database.
  6. Deep dive: one or two hard parts.
  7. Trade-offs: bottlenecks, failures, monitoring.

2. Numbers to Remember

Quantity Value
Seconds in a day 86,400 ≈ 10⁵
1 million requests a day ≈ 12 per second
Peak traffic About 2–3× the average
RAM read ~100 ns
SSD read ~100 µs
Same data centre round trip ~0.5 ms
India ↔ US round trip ~200 ms
Availability Downtime a year
99% 3.65 days
99.9% 8.76 hours
99.99% 52.6 minutes

Estimation example: 10 M daily users × 20 reads = 200 M reads a day ≈ 2,000 per second, so about 5,000 at peak.

3. Scaling

Vertical Horizontal
How Bigger machine More machines
Limit Hardware Almost none
Failure Single point Others keep serving
Needs Nothing Stateless servers, load balancer

Stateless servers: keep sessions in Redis or JWTs and files in object storage, so any server can take any request. See System Design Basics: Scalability.

4. Load Balancing

Algorithm How
Round robin Takes turns
Least connections To the least busy server
IP hash The same client goes to the same server
Weighted More traffic to stronger servers

L4 balances by IP and port (fast). L7 balances by URL, cookies and headers (smarter). Health checks remove dead servers. See Load Balancing.

5. Caching

Pattern How
Cache-aside App checks cache; on a miss reads DB and fills cache (most common)
Write-through Writes go to cache and DB together
Write-back Write to cache, DB later (fast, risky)

Eviction: LRU, LFU, TTL. Problems: stale data, stampede on a hot key, penetration by missing keys. CDN caches static files near users. See Caching, CDN and Databases at Scale.

6. Databases

Need Choose
Transactions, joins SQL (PostgreSQL, MySQL)
Flexible documents MongoDB
Very high write volume Cassandra
Cache, counters Redis
Relationships Neo4j
Search Elasticsearch
Files, images S3 (never in the DB)
Technique Solves
Index Slow reads
Read replicas Too many reads
Sharding Too many writes, or too much data
Denormalisation Expensive joins
Connection pooling Too many connections

Sharding: range (hot spots), hash (hard to add shards), consistent hashing (moves few keys). See Sharding and Replication.

7. CAP and Consistency

During a network partition, choose consistency or availability.

Choice Behaviour Good for
CP Refuse rather than return stale data Payments, inventory
AP Always answer, maybe stale Feeds, likes

Strong consistency: reads see the latest write. Eventual consistency: replicas catch up soon. See CAP Theorem.

8. Asynchronous Work

A message queue (Kafka, RabbitMQ, SQS) separates producers from consumers. Use it for emails, video processing, and absorbing traffic spikes.

Queue (RabbitMQ) Log (Kafka)
After reading Message removed Message kept, can replay
Good for Task jobs Event streams

Delivery is usually at-least-once, so consumers must be idempotent. See Message Queues.

9. Communication

Option Use
REST Most APIs
GraphQL Clients choosing their fields
gRPC Fast service-to-service
WebSocket Two-way real time (chat)
SSE Server-to-client stream
Polling Simple, slightly delayed updates

10. Reliability and Protection

Pattern Purpose
Redundancy Remove single points of failure
Replication + failover Survive a server dying
Rate limiting Stop abuse (token bucket, sliding window)
Circuit breaker Stop calling a failing service
Retry with backoff Recover from brief failures
Timeouts Don't wait forever
Idempotency keys Make retries safe (payments)
Monitoring Metrics, logs, traces, alerts

11. Monolith vs Microservices

Monolith Microservices
Deploy One unit Each service alone
Start Simple Complex
Scale Everything together Per service
Needs Little Gateway, discovery, tracing

Start with a monolith and split only when teams or scale demand it. API gateways handle auth, routing and rate limits. Saga handles transactions across services.

12. Question Templates

Question Key ideas
URL shortener Base62 IDs, cache, read-heavy
Chat app WebSockets, message store, presence
News feed Fan-out on write vs read, cache
Rate limiter Token bucket in Redis
Video platform Object storage, transcoding queue, CDN
Notification system Queue, workers, retries
Ride sharing Geo index, matching, live location
File storage Chunks, metadata DB, S3

Practice: explain your own project's architecture and how it would scale to 1 lakh users.

13. Interview Questions

How do you scale a read-heavy system? Cache, read replicas and a CDN.

How do you scale writes? Sharding, queues and batching.

What is a single point of failure? A part whose failure stops everything; remove it with redundancy.

What is consistent hashing? Mapping keys and servers on a ring, so changes move few keys.

Latency vs throughput? Time per request vs requests per second.

SQL or NoSQL? SQL for relations and transactions; NoSQL for flexible schemas and huge scale.

Why use a message queue? To decouple services, smooth spikes and run slow work later.

What is idempotency? Repeating an action has the same effect as doing it once.

14. Cheat Sheet & References

Method

Requirements → Estimates → API → Data → High-level → Deep dive → Trade-offs

Quick maths

1 day ≈ 10^5 s · 1M/day ≈ 12/s · peak ≈ 3× average
99.9% ≈ 8.8 h down a year · 99.99% ≈ 53 min

Fixes

Slow reads → index, cache, replicas, CDN
Slow writes → sharding, queue, batching
Spikes → queue, autoscaling, rate limit
Failures → redundancy, retries, circuit breaker

Standard architecture

Client → DNS → CDN → Load balancer → App servers → Cache → DB
                                           ↓
                                     Queue → Workers

References