System Design (50 Qs)•Part 1: Foundational Distributed Systems Concepts & Trade-offs (1 - 10)
Horizontal vs Vertical Scaling: Architectural Trade-offs and Bottlenecks.
In Simple Words:
- Vertical Scaling (Scale-Up): Adding more CPU, RAM, or NVMe disk capacity to a single physical or virtual machine.
- Horizontal Scaling (Scale-Out): Adding more discrete commodity instances into a distributed pool behind a load balancer.
| Parameter | Vertical Scaling (Scale-Up) | Horizontal Scaling (Scale-Out) |
|---|---|---|
| Complexity | Minimal (no distributed systems logic) | High (requires load balancing, statelessness, discovery) |
| Hardware Limit | Hard physical ceilings (e.g., AWS u-24tb1.112xlarge) | Practically infinite linear capacity |
| Availability | Single Point of Failure (SPOF) during hardware fault | Highly fault-tolerant (node failures auto-healed) |
| Network Overhead | Zero network latency (inter-thread IPC) | Network serialization, latency, and RPC overhead |
| Cost Curve | Exponential cost for high-end enterprise hardware | Linear cost using standard commodity compute |
typescript
// Architectural Rule: Designing Stateless Compute Services for Infinite Horizontal Scale
interface UserSession {
userId: string;
roles: string[];
expiresAt: number;
}
// ❌ Anti-pattern: In-memory session state breaks horizontal scaling
const inMemorySessionStore = new Map<string, UserSession>();
// ✅ Optimal Pattern: External shared distributed session store or stateless JWT
export async function getSession(sessionId: string, redisClient: any): Promise<UserSession | null> {
const data = await redisClient.get(`session:${sessionId}`);
return data ? JSON.parse(data) : null;
}