Auto scaling means the system itself, by looking at metrics such as CPU usage percentage, number of requests or queue length, decides whether to add or remove servers. This way you have enough capacity at peak load and don't pay during quiet hours.

How does it work?#

You define a rule: for example, "If average CPU usage exceeds 70 percent, add two instances; if it falls below 30 percent, remove one." The system monitors, creates a new instance from a template, attaches it to the load balancer, and removes it in quiet times.

Example#

A food-ordering app gets many requests at lunch and dinner and is nearly empty in the middle of the night. With auto scaling, the number of instances is high at midday and in the evening and low at night. Cost stays proportional to usage.

Prerequisites#

  • The application must be stateless; sessions and files are kept outside the server.
  • A new instance must become ready quickly and automatically (a ready image or container).
  • A load balancer and monitoring are needed.

Limits#

  • Starting a new instance takes from a few seconds to a few minutes, so sudden spikes may be missed.
  • Databases usually don't scale this easily.
  • Without a proper cap, an attack or a bug can create unexpected costs.

Always define a minimum and maximum number of instances and set up cost alerts.