System Design Core Principles
Scalability
Section titled “Scalability”The system should handle increasing traffic without degrading performance.
Horizontal Scaling
Section titled “Horizontal Scaling”Increase the number of application instances.
Load Balancer / | \ App1 App2 App3Advantages
- High availability
- Fault tolerance
- Better scaling
Vertical Scaling
Section titled “Vertical Scaling”Increase machine resources.
4 CPU↓
8 CPU
↓
16 CPUAdvantages
- Simpler architecture
Disadvantages
- Hardware limits
- Single point of failure
Availability
Section titled “Availability”The system should remain operational.
Techniques
- Replication
- Failover
- Load balancing
- Multi-region deployment
Reliability
Section titled “Reliability”The system should consistently produce correct results.
Common techniques
- Retry
- Timeout
- Circuit Breaker
- Monitoring
- Logging
Fault Tolerance
Section titled “Fault Tolerance”The system continues operating even if components fail.
Examples
- Kafka replication
- Database replicas
- Kubernetes self-healing
- Auto restart
Loose Coupling
Section titled “Loose Coupling”Services should depend minimally on each other.
Communication methods
- REST APIs
- Kafka
- RabbitMQ
- Events
Benefits
- Independent deployment
- Easier maintenance
- Better scalability
High Cohesion
Section titled “High Cohesion”Related functionality should remain together.
class UserService {
createUser();
updateUser();
deleteUser();}Avoid mixing unrelated responsibilities.
CAP Theorem
Section titled “CAP Theorem”Distributed systems can guarantee only two of the following:
- Consistency
- Availability
- Partition Tolerance
graph TD CAP --> Consistency CAP --> Availability CAP --> PartitionTolerance
Eventual Consistency
Section titled “Eventual Consistency”Data becomes consistent over time rather than immediately.
Examples
- Cassandra
- DynamoDB
- Event-driven microservices
Generic Backend Architecture
Section titled “Generic Backend Architecture”flowchart LR Client --> LB[Load Balancer] LB --> API[API Servers] API --> Cache[(Redis)] API --> DB[(MySQL)] API --> MQ[Kafka/RabbitMQ]
System Design Practice Problems
Section titled “System Design Practice Problems”- URL Shortener
- Payment System
- Rate Limiter
- Notification Service
- Chat Application
- Ticket Booking
- Distributed Cache
- API Gateway
- Email Service
- Video Streaming
Key Takeaways
Section titled “Key Takeaways”- Scale horizontally (more instances) for availability and fault tolerance; scale vertically (more resources) only as a simpler stopgap since it hits hardware limits and remains a single point of failure.
- Loose coupling and high cohesion work together: services depend minimally on each other, while related functionality stays grouped within a service.
- CAP theorem forces a trade-off during a network partition: a distributed system can only guarantee two of Consistency, Availability, and Partition Tolerance at once.
- Eventual consistency (Cassandra, DynamoDB, event-driven microservices) trades immediate consistency for availability and partition tolerance.