Horizontal scaling serves more requests with more machines, and vertical scaling with bigger machines.
The app grows and the AWS bill becomes quite expensive. Serverless charges a premium because AWS manages the servers end to end.
Each fix creates the next problem:
- A reserved instance. The server is rented from AWS for a year at a discount.
- A bigger instance. Memory runs out, so large becomes extra large. The single server is underutilized at night and has no backup when it crashes. It gives 32 virtual computers where 32 small computers give 64 for the same money.
- Multiple smaller instances. A crashed server's requests have to be redirected, and requests have to be sent roughly evenly.
- A load balancer. AWS Elastic Load Balancer routes the requests across the EC2 instances.
Round robin is a stateless algorithm: requests go to servers 1, 2, 3 and 4 in a cyclic fashion. Least connections is stateful: with 20, 30 and 40 requests on three servers, the new request goes to the server with 20.