Bugpit

Lessons › Keep it running

Pay for the peak only at the peak

Traffic peaks at 20,000 req/s for one hour each evening, and is under half that the rest of the day. Four servers melt at the peak. Twelve would cope, but you'd pay for twelve all night while they sit idle.

Play this level

Part of Bugpit Pro. It runs in your browser: build the design, press Run, and watch what breaks.

The lesson

Traffic has a shape. Open **A day of traffic**: the peak is one hour, and at 4 am you have 4% of it. A fixed number of machines is either too few at 8 pm or too many at 4 am.

Autoscaling watches a number, usually how busy the CPUs are, and adds machines when it rises and removes them when it falls. You set the most it may run, and pay for what actually ran.

Set **Machines** to what the peak needs, then tick **Autoscale**. The bill drops to the average, not the peak.

It isn't magic. A new machine takes a minute or more to start, so a spike faster than that still hurts. Keep some headroom, scale out early and scale in slowly. This simulator works hour by hour, so it can't show that delay: here, autoscaling always arrives in time.

What you have to achieve

20,000 requests a second at the busiest hour, 3% of them writes.

What you learn

The app servers now cost well under half as much, and the peak is still covered. Autoscaling only works because the servers hold no state: any machine can answer any request, so machines can come and go.

Check yourself

A TV advert sends traffic from 2,000 to 20,000 req/s in ten seconds. New machines take two minutes to start. What happens?

Show the answer

Requests fail until the new machines are ready. Autoscaling reacts, so it's always a little late. For spikes you can predict, add machines beforehand (scheduled scaling) or keep headroom.

Why can app servers be autoscaled easily, but a primary database can't?

Show the answer

App servers hold no data of their own, so any of them can come or go. A stateless server can be added or removed freely. A database holds the data, so adding one means copying or splitting that data first.

Try it yourself

More in Keep it running

← The cache that took down the database When retries make it worse →