InfraSim system design guide

Why autoscaling is too slow for a spike

Traffic went to four times normal in one second. The autoscaler noticed right away. The new instances arrived 29 seconds later.

Autoscaling adds servers when load goes up. It does that in two steps: first it has to see the load, then the new servers have to start. The second step is the slow one. A new virtual machine has to boot, start your app, and pass a health check before it takes a single request. For a gradual rise that is fine. For a spike that arrives all at once, every second of that start-up is a second the extra traffic has nowhere to go.

The experiment

A gift shop runs on three small servers, taking 480 requests a second, with plenty of room. Thirty seconds in, the advent-calendar email lands in every inbox at once: traffic goes to four times normal within a second, and stays there. We ran five setups with the same seed.

Share of requests failing, around the spike

  • Autoscaling from 3 instances
  • Autoscaling from a floor of 8
0% 20% 40% 60% 80% 20s 30s 40s 50s 60s 70s 80s Seconds into the run (traffic goes to 4× at 30)
InfraSim, Advent of Outages door 1, seed 261201. Sampled every 2 simulated seconds.
SetupErrors, first 30 s of the spikeErrors after thatCost / month on a quiet day
3 fixed instances73.9%74.4%$550
Autoscaling, 3 to 1669.9%0.3%$550
Autoscaling, floor of 82.9%0.3%$710
9 fixed instances0.95%0.96%$742
Containers, 12 to 64 tasks18.1%4.1%$586

Costs are the simulated monthly bill before the spike, which is what you pay on every day the spike does not come.

The 29-second gap

The autoscaler did its job. The moment traffic jumped, it asked for more instances. They arrived at 0:59, 29 seconds later, and from then on errors were 0.3%. Before they arrived, the shop failed 70% of requests: three instances were trying to serve four times what they were sized for.

Autoscaling did not make the spike hurt less. It made it end. Averaged over the whole run, the autoscaled shop still lost 36% of requests, almost all of them in that gap.

InfraSim gives a pool of virtual machines a 28-second start-up time. Real numbers vary from seconds to minutes, depending on the image, the app's own start-up and the health check. The shape is the same: the time to start capacity is the time you are short of it.

Buying your way out of the gap

A higher floor. Autoscaling with a minimum of eight instances (aiming to keep them 55% busy) meant the spike landed on capacity that was already running. Errors in the first 30 seconds: 2.9%. The autoscaler still added instances at 0:59, but now as headroom rather than rescue. The price is $160 a month more on a quiet day.

Just provision for it. Nine fixed instances failed under 1% throughout, for $742 a month on a quiet day. That is simpler, slightly more expensive at rest, and does not grow if the spike turns out bigger than you planned.

There is no free option here, only a cheaper one. Spare capacity costs money every day. The gap costs requests on the day it matters.

Faster units

Containers start much faster than whole machines; InfraSim gives a task about 6 seconds. Autoscaling containers, the shop was back on its feet by 0:37 instead of 0:59. It then hit a different wall: 41 small tasks each holding database connections wanted 410 of them, and the database allows 300. Errors settled at 4.1% instead of 0.3%. Scaling out fast moves the bottleneck to whatever everything scales into, which is very often the database.

Serverless functions start faster still, but a function that has to start from cold adds that start-up time to the request that woke it. Keeping some instances warm removes it and, like a higher floor, costs money while idle.

The cheapest fix of all

Someone sent that email. A spike you know about can be met with capacity scheduled ahead of it: raise the floor an hour before the campaign, lower it after. Autoscaling is for the load you did not see coming. For the load you scheduled, schedule the capacity too.

About these numbers

They describe InfraSim's simulation, which models traffic as flows per tick, with a fixed seed so every run repeats exactly. Start-up times and costs are the game's, chosen so the trade-offs rank the way real ones do, not to match any provider.

Break it yourself

This is Advent of Outages door 1, "Doors Open": the same three servers and the same email. It is free in your browser with no account, and it is already open.

In the InfraSim app, Launch Day (chapter 2, Scale Compute, free) quadruples traffic the moment you ship, and Cold Start in the same chapter is the serverless version of the problem.

New to InfraSim? The first five campaign levels play in your browser right now. No install, no account.

Get InfraSim: System Design Game

InfraSim is a system-design game: drag load balancers, caches, databases and queues onto a canvas, deploy, and watch simulated live traffic flow through what you built. Then survive traffic spikes, zone outages and bot swarms across a guided campaign, endless Survival runs and a Daily Challenge. Tutorial and 15 levels free, with optional InfraSim Pro.

More about InfraSim