System Design — Complete Guide & Notes

System Design is the process of defining the architecture, components, modules, interfaces, and data flow of a system to satisfy specified business and technical requirements. It focuses on engineering software systems that are scalable, reliable, available, and maintainable.


📚 Topics Covered

Core Fundamentals

Topic Description
Networking Fundamentals URL breakdown, HTTP/HTTPS, TCP vs UDP, DNS, REST, WebSockets, Latency numbers
Client-Server Architecture Client-server model, Stateless vs Stateful, Vertical vs Horizontal scaling, Monolith vs Microservices

Data & Scaling

Topic Description
Databases Relational SQL, NoSQL types, ACID properties, Indexes, SQL vs NoSQL selection
Database Scaling Replication (Primary-Replica), Sharding strategies, CAP Theorem, Consistency models
Caching Cache strategies (Cache-aside, Write-through), Redis data structures, Eviction policies, Stampede/Penetration
Storage Block vs File vs Object storage, AWS S3 storage tiers, Selection guide
CDN Edge delivery, Push vs Pull CDN, Cache invalidation strategies, Performance impacts

System Infrastructure & Messaging

Topic Description
Load Balancers Layer 4 vs Layer 7, Balancing algorithms, Health checks, Reverse proxy comparison
Message Queues Asynchronous processing, Apache Kafka architecture, Pub/Sub vs Point-to-Point, Dead Letter Queues
Distributed Systems 8 Fallacies of distributed computing, Consensus (Paxos/Raft), Distributed locks (Redlock), Idempotency
Microservices API Gateways, Service discovery, Circuit breaker pattern, Saga distributed transactions

Resilience, Security & Operations

Topic Description
Reliability & Fault Tolerance High availability SLAs (The Nines), Failover strategies, Exponential backoff with jitter
Rate Limiting Token Bucket, Leaky Bucket, Sliding Window Counter, Redis distributed concurrency
Security AuthN vs AuthZ, OAuth 2.0 flow, JWT vs Sessions, TLS handshake, API security checklist
Observability Logs, Metrics, Distributed Tracing, Four Golden Signals, Prometheus/Grafana stack, Alerting best practices
Interview Framework 4-step interview structure, System building blocks cheat sheet, Scalability estimation

🏗️ High-Level System Architecture Example

A typical large-scale web application (like Instagram or Twitter) combines these building blocks:

User Request (Web / Mobile)
     ↓
   DNS → Resolves domain to closest Edge IP
     ↓
   CDN → Serves static assets (images, videos, JS, CSS)
     ↓
 Load Balancer (L4 / L7) → Distributes traffic across API servers
     ↓
 API Gateway → Routing, Authentication, Rate Limiting, SSL Termination
     ↓
 ┌─────────────────┬──────────────────┬───────────────────┐
 ↓                 ↓                  ↓                   ↓
Auth Service    Feed Service     Upload Service     Notification Service
     ↓                 ↓                  ↓                   ↓
  User DB         Feed Cache        Object Store       Message Queue
(PostgreSQL)        (Redis)             (S3)              (Kafka)
                                                              ↓
                                                      Background Workers

🧭 Core System Design Principles

  1. Eliminate Single Points of Failure (SPOF): Add redundancy at every layer (multiple LB instances, primary-replica DBs, multi-region failover).
  2. Design for Statelessness: Keep app servers stateless by offloading state to distributed caches (Redis) and databases.
  3. Decouple Components with Queues: Use asynchronous message brokers (Kafka/RabbitMQ) for heavy operations (video processing, email dispatch).
  4. Cache Aggressively & Invalidate Safely: Cache data close to the user (CDN) and close to the app (Redis) to protect the database layer.
  5. Scale Horizontally: Build systems that scale by adding commodity machines rather than relying on hardware upgrades.

🎯 4-Step System Design Interview Framework

  1. Step 1: Understand Requirements (5 mins): Clarify functional scope, non-functional requirements (scale, latency, availability, consistency), and perform back-of-the-envelope calculations.
  2. Step 2: High-Level Design (10 mins): Draw core components (Clients, LB, API Gateway, Services, Databases, Storage) and specify API contracts and data models.
  3. Step 3: Deep Dive (20 mins): Scale bottlenecks, design caching strategies, choose replication/sharding methods, and handle failure scenarios.
  4. Step 4: Wrap Up & Trade-offs (5 mins): Review trade-offs, discuss observability, identify future bottlenecks, and summarize decisions.