Cloud
Auto-scaling
Each check is O(1) — you just compare a number to two limits. The value isn't speed. It turns a manual 3am 'add more servers!' alert into an automatic rule.
The idea, in plain English
Picture a shop manager calling in more cashiers when the checkout line gets long, and sending some home when the shop is quiet. Auto-scaling does the same thing for a website. The 'cashiers' are servers — computers that run your app. The 'line length' is the load: how much traffic hits each server. A watching process checks the load on a schedule. It adds or removes servers automatically, so nobody has to watch it by hand.
How it works
- 1Keep measuring the load, such as average CPU use or requests per server, on a regular schedule.
- 2If load climbs above an upper limit, add another server, up to a set maximum. This spreads out the work so things stay fast.
- 3If load drops below a lower limit, remove a server, down to a set minimum, so you're not paying for idle machines. Between the two limits, leave things alone.
When you'd use it
Use this for any app with traffic that goes up and down — a shopping site busiest in the evening, a homework app busiest the night before it's due. You want enough servers when it's busy, and not too many wasted ones when it's quiet.
Common beginner mistakes
- Setting the limits too close together. This makes the system add and remove servers back and forth on every small wiggle in traffic ('thrashing').
- Forgetting the minimum and maximum caps. With no floor, you could scale down to zero servers and go offline. With no ceiling, a traffic spike or a bug could scale your bill sky-high.
- Reacting to one single reading instead of a trend. One noisy spike shouldn't trigger a scale-up.
Try it — edit and run
Click the code to edit · press ⌘/Ctrl+↵ to run
Editable code. Tab and Shift+Tab indent. Press Escape, then Tab, to move focus out of the editor.
load 45 -> steady, servers stay at 2
load 85 -> scaling up, servers now 3
load 92 -> already at max servers (3), can't scale up further
load 35 -> steady, servers stay at 3
load 15 -> scaling down, servers now 2
load 10 -> scaling down, servers now 1
load 10 -> already at min servers (1), can't scale down furtherNot sure this is the right topic? See the learning paths → or where this leads →