CHAPTER DEEPREAD · SRE · CH 17

Testing for Reliability

Site Reliability Engineering · Ch 17 · Google · 2016

中文 →

What is this chapter about?

The apps on your phone update almost weekly, and the services behind them change dozens of times a day. The odd thing is how rarely an update takes everything down. Chapter 17 of Google's SRE book is about exactly that: change is unavoidable, so how do you keep change from breaking things? The answer is a whole discipline of tasting before serving.

An analogy first

Think of shipping a new version as a restaurant putting a new dish on the menu. You changed the recipe, so you don't send it straight to a full dining room. First you taste it yourself in the kitchen. Then you run the whole thing end to end — plating, timing, service. Then you serve it to one table by the window and watch how they react. Only then does it go out to everyone. And regardless of new dishes, every day you send someone in to order a plate pretending to be a customer, just to confirm the kitchen is still alive. Those steps map onto the kinds of checks this chapter describes.

Why the old way was hard

Not changing code is the safest thing you can do, and also the end of your business. The real difficulty is that things break not because someone got a line wrong, but because of the things that only exist in production — real user traffic, real configuration, the real number of machines. Everything tastes fine in the kitchen and falls apart in the dining room. Worse, many teams have exactly one move after shipping: stare at the dashboards and hope, letting users find the problem first.

The central idea: not catching bugs, but making bugs cheap

The most counterintuitive line here is this: the value of testing isn't finding a problem, it's deciding at which step the problem gets found. If a dish is too salty and the kitchen catches it, the cost is one remade plate. If the customer catches it, the cost is an apology, a refund, and your reputation. Software works the same way. A bug stopped by an automated check before release is nearly free to fix. A bug that leaks into production is a 3 a.m. page, an investigation, a rollback, and a postmortem — there goes your night.

So the lesson isn't "write more tests." It's put each gate where the cost is lowest, and be honest about what each gate misses — the kitchen can't taste the crowding in the dining room, and one table by the window doesn't speak for every customer.

So how do you choose?

A small system you can undo in a minute can afford looser gates and lean on "pull it back the moment it looks wrong." A large system that takes hours to recover has to move its gates earlier and stop bad changes before they ship. The honest cost: more gates means slower releases — and a check that passes sometimes and fails other times is worse than no check at all, because it teaches everyone to ignore red lights.

One thing to remember

Testing isn't about proving nothing is broken. It's about making sure breakage is discovered at the cheapest possible place. Taste before serving, serve one table first, and keep sending in a fake customer — three gates, each covering a different stretch, none of them optional.

Want the mechanisms, diagrams and real systems? → Switch to the deep read