System Design Fundamentals¶
System design is about designing scalable, reliable, and maintainable systems. Key building blocks: Load Balancers (distribute traffic), Caches (reduce latency), CDNs (serve static content globally), Message Queues (decouple services), Databases (storage), Proxies (forward/reverse). Approach: clarify requirements → estimate scale → design high-level → drill into components → discuss trade-offs.
Key Concepts¶
Deep Dive: System Design Interview Framework
Step 1 — Requirements Clarification (3-5 min) - Functional requirements (what does the system do?) - Non-functional requirements (scale, latency, consistency) - Constraints (budget, tech stack, team size)
Step 2 — Estimation (3-5 min) - Users: DAU, peak concurrent users - Traffic: requests per second (RPS) - Storage: data size, growth rate - Bandwidth: bytes per second
Step 3 — High-Level Design (10 min) - Draw the architecture diagram - Identify major components - Show data flow
Step 4 — Detailed Design (15 min) - Dive into 2-3 critical components - Database schema - API design - Algorithms
Step 5 — Trade-offs & Bottlenecks (5 min) - Identify single points of failure - Discuss alternatives - How to scale further
Deep Dive: Back-of-the-Envelope Estimation
Key numbers to remember: | Metric | Value | |--------|-------| | 1 day | 86,400 seconds ≈ 100K | | 1 month | ~2.5 million seconds | | QPS from 1M daily users | ~12 QPS (1M / 86400) | | 1 char | 1 byte | | 1 int | 4 bytes | | 1 long/double | 8 bytes | | 1 KB | 1,000 bytes | | 1 MB | 1,000 KB | | 1 GB | 1,000 MB | | 1 TB | 1,000 GB |
Latency numbers: | Operation | Time | |-----------|------| | L1 cache | 1 ns | | L2 cache | 4 ns | | RAM | 100 ns | | SSD random read | 100 μs | | Network round-trip (same DC) | 500 μs | | HDD seek | 10 ms | | Network round-trip (cross-country) | 50 ms | | Network round-trip (cross-continent) | 150 ms |
Deep Dive: Load Balancing
Distributes traffic across multiple servers.
Algorithms: | Algorithm | Description | |-----------|-------------| | Round Robin | Rotate sequentially | | Weighted Round Robin | More traffic to powerful servers | | Least Connections | Route to server with fewest connections | | IP Hash | Same client → same server (sticky sessions) | | Random | Random server selection |
Layers: - L4 (Transport) — routes based on IP/port (TCP/UDP). Faster. - L7 (Application) — routes based on HTTP headers, URL, cookies. Smarter.
Tools: Nginx, HAProxy, AWS ALB/NLB, Cloud Load Balancers.
Deep Dive: CDN (Content Delivery Network)
Serves static content from servers geographically close to users.
Push vs Pull CDN: - Push: You upload content to CDN. Good for static, rarely-changing content. - Pull: CDN fetches from origin on first request, caches it. Good for dynamic content.
Cache with CDN headers:
Deep Dive: Proxies
Forward Proxy — sits between client and server, hides the client.
Use: VPN, content filtering, anonymity.Reverse Proxy — sits between client and server, hides the server.
Use: Load balancing, SSL termination, caching, compression.Nginx is the most common reverse proxy.
Common Interview Questions
- How would you approach a system design interview?
- What are the key components of a scalable system?
- Explain load balancing algorithms.
- What is a CDN? How does it work?
- What is the difference between forward and reverse proxy?
- How do you estimate the scale of a system?
- What latency numbers should you know?