Lessons › From one user to millions
Pay for nothing when nobody comes
A side project with 20 requests a second at its busiest, and almost nothing overnight. Two servers sit idle for most of the day, and you pay for every hour of it.
Play this levelFree with an account. It runs in your browser: build the design, press Run, and watch what breaks.
The lesson
A server costs the same whether anyone uses it or not. A function like AWS Lambda only charges when it runs: $0.20 per million calls, plus time and memory.
The catch is the first call. A function that isn't running has to start: AWS says cold starts typically hit under 1% of calls, and last from under 100 ms to over a second.
1% sounds small until you notice that's right where p99 sits. When cold starts reach 1 call in 100, your p99 is a cold start.
You can keep functions warm and pay for them even when idle, which is how you end up paying for a server again.
What you have to achieve
20 requests a second at the busiest hour, 10% of them writes.
- No broken or illegal connections
- Use a Serverless Function
- Fewer than 0.1% of requests fail
- p99 response time under 800 ms
- Machines cost at most $200 / month
What you learn
The machine bill dropped to the database alone, and p99 jumped: that's the cold start. For a quiet app that's a great trade. Turn up the traffic in Free design and you'll find the point where a plain server gets cheaper again.
Check yourself
Why did serverless suit this app?
- It's always faster
- You only pay when it runs, and the app is mostly idle
- It has no limits
Show the answer
You only pay when it runs, and the app is mostly idle. A server costs the same when idle. Functions charge per call, which wins for quiet apps.
Why did p99 jump after the switch?
- Cold starts land right where p99 sits
- The database got slower
- More traffic arrived
Show the answer
Cold starts land right where p99 sits. When about 1 call in 100 is a cold start, your slowest 1% are the cold starts.