Lessons › From one user to millions
When one service takes you down
6,000 req/s. Every request now checks who the user is, and every page asks a Recommendations service what to show. Recommendations crashed last night, and the whole site went with it.
Play this levelFree with an account. It runs in your browser: build the design, press Run, and watch what breaks.
The lesson
Splitting code into services lets a team deploy and scale alone. It also means every request now depends on machines it never used to. Add up those calls: each adds time, and each can fail.
Auth sits on every request, so it needs about as much capacity as your app. It can't fail softly either: if you can't tell who someone is, you can't answer them.
Recommendations is different. A page without them is still a page. A circuit breaker watches the calls and, when too many fail, stops making them for a while. Callers answer at once with a simpler page.
Without a breaker, failures are retried, retries add load, and a small fault spreads. That's a cascading failure. In this simulator the breaker sits on the service. In real code it wraps the call.
What you have to achieve
6,000 requests a second at the busiest hour, 5% of them writes.
- No broken or illegal connections
- Use an Auth Service with at least 2 instances
- Use an Internal Service
- No component is overloaded
- If every Internal Service machine dies, under 0.1% of requests fail
- Fewer than 0.1% of requests fail
- p99 response time under 250 ms
What you learn
Crash Recommendations now: users get a simpler page instead of an error. A breaker only helps with calls you can live without. You can't put one on Auth, so that's the one to keep redundant. Before you split a service, ask what happens to everyone else when it dies.
Check yourself
Where does a circuit breaker belong?
- On calls you can live without, like recommendations
- On auth
- On the database
Show the answer
On calls you can live without, like recommendations. A page without recommendations is still a page. You can't answer without knowing who the user is.
What is a cascading failure?
- Two machines failing at the same time
- Failures retried until a small fault spreads
- A slow deploy
Show the answer
Failures retried until a small fault spreads. Retries add load, the load causes more failures, and one service's fault takes down everyone who calls it.