Day-2 in System Designing
basic · System Designing
The Infrastructure Scaling Dilemma (Vertical vs. Horizontal) When your application starts growing, a single server will eventually run out of resources. To handle a massive spike in users, you have two primary options: Vertical Scaling (Scale Up) or Horizontal Scaling (Scale Out) . 1. Vertical Scaling (Scaling Up) Vertical scaling means making your single existing server stronger. It is the equivalent of upgrading your personal computer by buying a faster CPU, adding more RAM, or upgrading to a larger SSD. The Good Simplicity: Your application code remains exactly the same. No architectural rewrites or changes are required. No Network Latency: Because your web server, logic, and database still live on the exact same machine, communication between them is instantaneous. Data Consistency: Managing a database is incredibly simple because all data resides in one place, completely avoiding synchronization issues. The Bad The Hard Ceiling: Physical hardware has an absolute limit. You cannot buy a single server with infinite RAM or CPU. Single Point of Failure (SPOF): If that one massive server crashes or goes offline, your entire platform goes down instantly. Exponential Costs: High-end hardware costs grow exponentially, not linearly. A server with 4x the power can easily cost 10x as much. 2. Horizontal Scaling (Scaling Out) Horizontal scaling means adding more servers to your pool instead of making one server bigger. Instead of one giant machine, you deploy your application across a fleet of smaller, cheaper commodity servers. The Good Infinite Scale: There is no physical upper limit. If your traffic doubles, you simply spin up more instances to handle the load. High Availability: If one server crashes, the remaining servers pick up the slack. Your users won't even notice. Cost Efficiency: It allows you to use cheaper hardware and take advantage of cloud elasticity (scaling up your server count during peak hours and scaling down at night to save money). The Bad Architectural Complexity: Your application must be completely stateless . You cannot store user sessions or file uploads on a server's local drive because a user's next request might route to a totally different server. Network Overhead: Servers must now communicate with databases, caches, and each other over a network, introducing latency. 3. Quick Comparison Table Feature Vertical Scaling (Scale Up) Horizontal Scaling (Scale Out) Action Make the single machine stronger Add more machines to the network Max Capacity Restricted by hardware limits Practically unlimited Reliability Single point of failure Highly resilient (fault tolerant) Complexity Extremely simple; zero code changes Complex; requires a Load Balancer Data Consistency Easy (everything is local) Complex (data distributed across nodes) Core System Design Takeaway For modern systems, the industry standard is a Hybrid Model . Engineers choose a reasonably sized vertical baseline for their servers (e.g., an AWS instance with 4 CPUs and 16GB RAM) and then scale those servers horizontally across a fleet using a Load Balancer .