Skip to main content

🏛️ System Design

"A complex system that works is invariably found to have evolved from a simple system that worked." — John Gall

System design is about making trade-offs to build systems that are scalable, reliable, and maintainable.


🎯 Core Concepts

Scalability Patterns

ApproachProsCons
VerticalSimple, no code changesHardware limits, single point of failure
HorizontalUnlimited scale, fault tolerantComplex, state management

High Availability Patterns

PatternDescriptionUse Case
Active-PassiveStandby takes over on failureDatabase failover
Active-ActiveAll nodes serve trafficWeb servers
Leader ElectionOne leader, multiple followersDistributed consensus

🔄 Distributed Systems

CAP Theorem

During a network partition, you must choose between Consistency and Availability.

BASE vs ACID

PropertyACIDBASE
ConsistencyStrongEventual
AvailabilityVariableHigh
ScalabilityLimitedHigh
Use CaseFinancial systemsSocial media, caching

🔧 Key Components

Load Balancing Strategies

AlgorithmDescriptionBest For
Round RobinSequential distributionHomogeneous servers
Least ConnectionsRoute to least busyVariable request times
IP HashConsistent per clientSession affinity
WeightedCapacity-based routingHeterogeneous servers

Caching Strategies

PatternDescriptionConsistency
Cache AsideApp manages cache/DBManual invalidation
Write ThroughWrite to cache + DBStrong
Write BehindAsync DB writesEventual
Read ThroughCache fetches on missAutomated

📝 Detailed Topics


🎨 Design Template

## Requirements
- Functional: What should the system do?
- Non-functional: Scale, latency, availability targets

## High-Level Design
- Core components and their interactions
- Data flow diagram

## Deep Dive
- Database schema design
- API design
- Algorithm choices

## Trade-offs
- Why this approach vs alternatives?
- Scalability bottlenecks

Interview Framework
  1. Clarify Requirements (2-3 min)
  2. High-Level Design (10-15 min)
  3. Deep Dive (15-20 min)
  4. Trade-offs & Bottlenecks (5-10 min)