Scalability

Horizontal vs vertical scaling, load balancing, and statelessness

Scalability

Scalability is a system's ability to handle increased load. Vertical scaling (adding more CPU/RAM) has limits. Horizontal scaling (adding more machines) is preferred for large systems but requires statelessness and data distribution.

Scaling Strategies

Load Balancing Algorithms

  • Round Robin: Distribute requests sequentially
  • Weighted Round Robin: Heavier servers get more traffic
  • Least Connections: Route to server with fewest active connections
  • IP Hash: Same client IP always hits same server (session affinity)
  • Consistent Hashing: Distribute across nodes minimizing redistribution on change

Statelessness

For horizontal scaling, servers must be stateless — no local session data. Store sessions in Redis/DynamoDB and use JWT tokens. Any server should handle any request.