Horizontal vs Vertical Scaling in System Designing
medium · System Designing
Scaling is the strategic process of allocating compute capacity to handle increasing volume (more concurrent users, data volume, or transaction throughput). Deciding between Vertical and Horizontal scaling is one of the most critical structural pivots you will make when architecting a system. 1. Vertical Scaling (Scaling Up) Vertical scaling means adding more raw computing power—such as upgraded CPUs, additional RAM, or faster NVMe Solid-State Drives—to a single physical or virtual server . The Mechanism: You take your application process running on an instance with 2 CPU cores and 4GB of RAM and migrate it to a larger machine with 32 CPU cores and 128GB of RAM. Pros: * Zero Code Changes: Your software architecture remains exactly the same. You don't need to rewrite code to support distributed networking. Low Complexity: No need for load balancers or distributed data sync strategies. Cons: The Hardware Ceiling: Every machine has an ultimate physical limit. You cannot buy a single server with infinite RAM or CPU cores. Single Point of Failure (SPOF): No matter how powerful that machine is, if its motherboard fails or its data center loses power, your entire system goes dark. Exponential Costs: Doubling a machine's power near the high end can cost 10x more than buying two mid-tier machines. 2. Horizontal Scaling (Scaling Out) Horizontal scaling means adding more individual machines (nodes) to your application pool, connecting them over a local network, and using a load balancer to distribute the incoming traffic evenly among them. Pros: Infinite Theoretical Scale: If your current cluster of 5 servers gets overwhelmed, you simply add a 6th, 7th, or 100th server to the pool. Built-in Redundancy (High Availability): If one server crashes, the load balancer instantly detects the failure and routes traffic to the remaining healthy nodes. Your users experience zero downtime. Cons: High Architectural Complexity: Requires network routing infrastructure (Load Balancers, Service Meshes). Data Inconsistency Risks: Synchronizing data across many machines introduces network delays, forcing trade-offs under the CAP Theorem. 3. The Horizontal Requirement: Stateless Design You cannot scale an application horizontally unless your application tier is completely Stateless . The Problem with State: If Server A handles a user's login and stores their session data locally in its RAM, and the user's next click is routed by the load balancer to Server B, Server B won't know who they are and will force them to log in again. The Stateless Solution: In a stateless design, the application servers do not store any session context locally. Instead, session states are either stored on the client (e.g., using signed JWTs) or offloaded to a shared, high-speed centralized data store like Redis . This ensures that any server in your pool can pick up and process any incoming request at any moment. 4. Dynamic Capacity: Auto-Scaling Groups (ASGs) Traffic is rarely constant; an e-commerce platform might see minimal traffic at 3:00 AM but massive surges at 12:00 PM. Keeping 50 servers running 24/7 to handle peak hours is incredibly wasteful and expensive. An Auto-Scaling Group (ASGs) is a cloud infrastructure feature (like AWS EC2 Auto Scaling) that dynamically adjusts the number of active server instances in your cluster based on real-time traffic demand. How it works: Define a Policy: You establish scaling triggers based on health metrics, such as: "If the average CPU utilization of the server pool exceeds 70% for more than 3 minutes, launch 2 new instances." Scale Out: During a massive traffic spike, the ASG automatically provisions new virtual machines, registers them with the Load Balancer, and begins distributing the load. Scale In: When traffic drops and CPU utilization falls below 30%, the ASG safely terminates the extra instances, preventing you from paying for idle compute power. 5. Structural Comparison Feature Vertical Scaling (Up) Horizontal Scaling (Out) Scaling Limit Limited by hardware availability (Hard ceiling) Theoretically infinite Fault Tolerance Low (Single Point of Failure) High (Redundancy across multiple nodes) System Complexity Very low High (Requires load balancers and stateless code) Cost Efficiency Linear at first, then exponentially expensive Highly efficient when combined with Auto-Scaling