Debugging Production Incidents: A Senior Engineer's Playbook
From Mid-Level to Senior · Part 10 of 18
- #incident-response
- #debugging
- #devops
- #senior-engineer
- #engineering-practices
It's 14:06 on a Thursday and the pager goes off: the checkout error ratio is at 12%. Normal is 0.2%.
Within two minutes there are nine people in the channel. One of them is pasting stack traces. Another is asking if this is related to the deploy from before lunch. Someone from support wants to know what to tell customers. Two engineers have already opened a shell in production, and neither knows what the other is about to do.
Nobody in that channel is short on skill. They're short on a process, and during an incident that shows much faster than a lack of skill does.
Part 9 was about seeing the problem: the signals that tell you something is wrong and where. This part is about the next thirty minutes. It covers what to do first, who does what, how to investigate without guessing, and what to do after it's over so the same thing doesn't page you again in three weeks.
I'll use that 14:06 incident as a running example. It's invented, but every piece of it is something that happens on real systems.
An incident has phases, and the order matters
- Detect. Is this real, and how bad is it?
- Stabilize. What's the fastest way to stop the damage?
- Diagnose. Why did it happen?
- Fix. How do we keep it from coming back?
- Learn. What did this show us about the system?
Most engineers, left alone, go from 1 straight to 3. It's the interesting part, and it's what we're trained to do: understand the bug, then fix it. In production that order costs money, because every minute you spend understanding is a minute customers spend failing.
The first two phases are on the clock. The other three usually aren't. Once users are fine again, you can diagnose with a clear head, the next morning, with coffee.
Declare it early
The first decision is admitting there's an incident. Teams lose a surprising amount of time here, with three people each looking at the problem privately and nobody saying it out loud.
Declaring costs almost nothing: a message in a known channel that says what's happening, how bad it looks, and who is in charge. If it turns out to be nothing, you close it ten minutes later and nobody is worse off. The opposite mistake, declaring twenty minutes late, is the expensive one.
Keep the severity scale short. Three levels are enough for most companies:
- SEV1: customers can't do the main thing the product exists for, or data is at risk. Everyone needed drops what they're doing.
- SEV2: an important feature is degraded or a subset of customers is affected. The on-call team works on it now.
- SEV3: something is wrong, but there's a workaround and it can wait for working hours.
Our example is card checkout failing for one in eight customers. That's a SEV1 for any business that sells things.
Stabilize before you diagnose
The question in this phase is "what's the fastest safe thing that makes this stop?". It's a different question from "what's wrong?", and you can often answer it without knowing what's wrong.
The usual menu, more or less from cheapest to most expensive:
- Roll back the last deploy.
- Turn off the feature flag for whatever was released most recently.
- Stop the thing that started: a job, a migration, a batch import, a campaign.
- Scale up or out if a resource is saturated.
- Restart instances that are stuck (after capturing evidence, more on that below).
- Fail over to a replica, another zone, or a secondary provider.
- Shed load: rate limit, or switch off a non-essential feature so the essential one survives.
To choose one, ask what changed. Most incidents are caused by a change, and the list of changes is longer than "deploys". It includes configuration, feature flags, scheduled jobs, database migrations, infrastructure, certificates that expired, a traffic pattern that's new, and a third party that changed something on their side. This is one of the best reasons to have every kind of change show up in one place, as annotations on a dashboard or messages in a channel. At 14:06 you want to read a list, not interview people.
In the example, the only visible change is a deploy of order-service
at 13:58. Rolling back takes two minutes and the previous version ran
fine for days:
kubectl rollout undo deployment/order-service
The team rolls back without proving the deploy is the cause. That's the right call. A rollback is cheap and reversible, and waiting for proof would cost more than being wrong.
They are wrong, as it happens. At 14:10 the error ratio is still 12%. We'll come back to that.
Capture evidence before you destroy it
A restart is often a perfectly good mitigation. It also erases the state you'd need to understand what happened. Before restarting a JVM that's misbehaving, spend thirty seconds on it:
jcmd <pid> Thread.print > /tmp/threads-$(date +%H%M%S).txt
jcmd <pid> GC.heap_dump /tmp/heap.hprof # if memory is the suspect
Take the thread dump two or three times a few seconds apart. Threads that are in the same place in all of them are the ones that are stuck. If you have several instances, you can also take one out of the load balancer and keep it for later instead of killing it.
Don't let this turn into an investigation, though. Thirty seconds of capture is fine. Ten minutes of reading the dump while customers fail is phase 3 work done in phase 2.
Give people roles
The nine-person channel from the opening has plenty of people and no structure. Incident response borrowed its structure from emergency services, and for a software team it comes down to four roles.
The incident commander runs the incident. They decide what the priority is, who looks at what, and when to try a mitigation. They don't debug. This is the hard part for a senior engineer, because the person who becomes commander is usually the one who knows the system best and most wants to open a terminal. But the moment the commander is reading a stack trace, nobody is watching the whole incident, and that's when two people restart the same service or the same theory gets investigated twice.
Investigators do the hands-on work: form hypotheses, run queries, make changes. They say what they're about to do before they do it, in the channel. "Restarting payment-service pod 3" takes five seconds to type.
Communications keeps everyone outside the incident informed, so that they don't come into the channel to ask. This role protects the investigators more than any other.
The scribe writes down what happens, with timestamps. It sounds like bureaucracy until you try to write a postmortem from memory and three people remember three different orders of events.
On a small team you won't have four people. With two, one investigates and the other does everything else. Alone at 3 a.m., you play all four roles in turn, and it still helps to know which one you're in: stop every ten minutes, write a line in the channel, and ask yourself whether it's time to wake someone up.
Seniority doesn't define the commander. A mid-level engineer can command an incident with the CTO as an investigator, and it works well as long as the CTO respects the role. If you're the most senior person in the channel and you aren't the commander, the most useful thing you can say is "what do you need from me?", and then do that.
Say it in one channel
One channel (or one call) per incident, where every decision and every action is announced. Side conversations in direct messages are how two people end up with different pictures of the same incident.
Status updates go out on a fixed interval, even when nothing changed. Every 30 minutes for a SEV1 is a common choice. A short template helps:
[14:20] SEV1 · Card checkout failures · UPDATE 2
Impact: ~12% of card payments failing since 14:00. Pix not affected.
Status: Cause identified, mitigation in progress.
Next: Stopping the job that's blocking the payments database.
Next update: 14:50, or sooner if something changes.
Commander: Ana
Impact comes first, in words the business understands. Don't speculate about causes in a public update, and always say when the next one comes. "No news yet, next update at 14:50" is a good update. People can handle not knowing the cause. They get anxious when nobody tells them anything.
Diagnose: one hypothesis at a time
Back to 14:10. The rollback didn't help, so the cheap mitigations based on "what changed" are used up and the team has to find out what's actually wrong.
Under pressure, people tend to do what I'd call shotgun debugging: change three things at once, restart something, and see if the graph improves. Sometimes it does, and then you don't know which of the three did it, or whether the problem just went away for a while by coincidence.
The alternative is a loop that takes a couple of minutes per turn.
- Observe. What do the signals actually show? Not what you assume they show.
- Hypothesis. One sentence that could be wrong.
- Prediction. If the hypothesis is true, what else must be true?
- Test. The cheapest check that could prove you wrong.
Step 3 is the one people skip. "The database is slow" isn't something
you can test. "If the database is slow, the p99 of every query in
payment-service went up at 14:00" is, and one dashboard settles it.
Narrow the scope first
Before forming hypotheses, cut the problem down. Three questions do most of the work:
- Who is affected? Everyone or a subset? One endpoint, one region, one customer, one payment method, one app version?
- When did it start? Exactly, to the minute. Then line that minute up against the list of changes.
- What is still working? It's as informative as what's broken.
In the example, splitting the errors by payment method takes one query,
and the result changes the investigation: every failure is a card
payment. Pix payments, which go through a different service, are fine.
So the problem isn't in order-service or in the checkout as a whole.
It's somewhere on the card path.
The example, turn by turn
Hypothesis 2: the card acquirer is failing. If so, traces of failed requests should show errors or timeouts in the spans that call the acquirer. The team opens three failed traces. The acquirer spans aren't slow. Most failed requests never reach that call at all. Rejected, in about three minutes.
But the traces show where the requests do stop: inside
payment-service, with this in the logs:
HikariPool-1 - Connection is not available, request timed out after 30000ms.
Hypothesis 3: payment-service ran out of database connections. If
so, the pool should be at its maximum, with threads waiting. This is the
USE check from Part 9, and the dashboard confirms it: active connections
at the limit of 20, and hikaricp_connections_pending at 40.
That explains the errors, but a full pool is a symptom of something else. Something is holding those connections, and the database can say what:
select pid, now() - xact_start as running_for, state,
wait_event_type, left(query, 80) as query
from pg_stat_activity
where state <> 'idle'
order by xact_start;
At the top of the list is one transaction that's been running for 19
minutes, an UPDATE on card_transactions issued by the nightly
reconciliation job. Below it are twenty short UPDATEs from
payment-service, all waiting on a lock.
The job started at 14:00. Somebody rescheduled it that morning from 02:00 to 14:00 to check a number for the finance team. Nothing was deployed, so it never showed up as a change anywhere the team was looking.
At 14:21 the commander decides to stop the job. By 14:24 the error ratio is back to 0.2%.
A few habits that speed this up
- Write hypotheses down, including the rejected ones. Otherwise the person who joins at 14:15 will suggest the acquirer again.
- Prefer tests that only read. A query or a dashboard can't make things worse. A change to production can.
- Change one thing at a time, and say what you expect to happen before you do it.
- Be suspicious of the first explanation that fits. The deploy at 13:58 fit perfectly and had nothing to do with it.
- Set a time limit per hypothesis. If ten minutes pass without progress on a theory, say so and pick another, or bring in someone else.
Mitigation is not the fix
Stopping the job ended the incident, but it fixed nothing. The job will run again tonight, at 02:00, when it will lock the same table. The only reason nobody will notice is that few people buy things at that hour.
That's the difference between the two words:
- A mitigation stops the impact. It's fast and often ugly, and it buys you time.
- A fix removes the cause, so the same trigger no longer produces the same failure.
Here, the fix has a few parts, none of them urgent at 14:25:
- Rewrite the job to update in small batches with short transactions, instead of one transaction that holds locks for twenty minutes.
- Lower the pool's connection timeout so requests fail in two or three seconds, not thirty. A fast failure is much easier on the rest of the system.
- Add an alert on pool saturation (threads waiting for more than a minute), which would have pointed at the cause straight away.
- Make schedule changes for jobs visible in the same place deploys are.
Two warnings about this phase.
Don't ship the fix during the incident unless there's no mitigation available. Writing code under pressure, skipping review, and pushing through a pipeline you're tempted to bypass is how one incident becomes two. Mitigate now and do the fix tomorrow, through the normal process from Part 8.
Don't stop at the mitigation either. After the graphs go green, everyone is tired and there's a sprint to get back to. If the fix doesn't get an owner and a date in the next day or two, the mitigation quietly becomes permanent, and you'll meet the same problem again.
Closing the incident
Before declaring it over:
- Watch the metrics for a while after they recover. Thirty minutes is reasonable for a SEV1.
- Check for damage left behind: orders stuck in an intermediate state, messages in a dead-letter queue, customers charged without an order. Recovering the error ratio doesn't recover those.
- Send a final update saying it's resolved, what the impact was, and when the postmortem will be available.
- Undo temporary changes, or write down which ones are still in place. A replica count raised by hand at 14:15 is easy to forget.
The blameless postmortem
A postmortem is a written review of the incident, done within a few days, while people still remember. Its purpose is to learn what the incident revealed about the system. It isn't there to find out who made the mistake.
"Blameless" is often misread as "nobody is accountable". What it means is that you assume people acted reasonably given what they knew at the time, and you ask why the action made sense to them.
Take the engineer who rescheduled the job. The blame version of the postmortem says "the incident was caused by an engineer running the reconciliation job during business hours", and the action item is "be more careful". That teaches the team one thing, which is to hide what they did next time.
The blameless version asks different questions. Why was it possible to reschedule a job that locks a critical table with no warning? Why did the job need one twenty-minute transaction? Why did a full connection pool take ten minutes to find? Those answers lead to changes in the system, and the changes protect the next person, who would otherwise make the same reasonable decision.
"Human error" is never a root cause. Someone will always make the mistake eventually. What you can change is how easy the mistake is to make and how much damage it does.
A structure that works:
# Card checkout failures · 2026-10-08
## Summary
Three or four sentences anyone in the company can read.
## Impact
Who was affected, for how long, how much. Numbers.
## Timeline
Times and facts, from the scribe's notes. No interpretation.
## What happened
The technical explanation, including contributing factors.
## What went well / what was hard
Detection, mitigation, communication, tooling.
## Action items
Each with an owner and a date. Few, and specific.
A few things that separate useful postmortems from ritual ones:
- Look for contributing factors, plural. Incidents in mature systems rarely have one cause. Here there were at least four: the long transaction, the 30 second timeout, the missing alert, and schedule changes nobody could see.
- Write down what went well too. The rollback was fast. The split by payment method took one query because the field was in the logs. Those are things to keep.
- Keep the action list short. Three items that get done are worth more than fifteen that sit in a backlog. An action item with no owner and no date is a wish.
- Ask how you'd have found it sooner. Time to detect and time to diagnose are usually where the easy gains are.
- Publish it. Other teams have the same kind of job, pool, and timeout. A postmortem only the affected team reads has done part of its work.
What I'd repeat on any team
I mentioned in Part 9 that SLA incidents dropped by around 40% on a team I led, and I also led that engineering organization through an M&A process with no disruption to the service. A period like that is when production is most at risk: priorities move, people are distracted, systems and processes are being changed around you. What I take from it is that staying stable has little to do with how well anyone performs during an incident. It mostly comes from boring habits that are already in place before the incident starts:
- Decide the process on a quiet day. Who is on call, what the severities mean, which channel, who can declare. At 14:06 it's too late to be designing any of that.
- Make mitigations cheap and practiced. A rollback you run every week is a tool you trust. One you last ran eight months ago is a risk, and you'll hesitate to use it at exactly the wrong time.
- Make it safe to raise a hand. The earlier someone says "I think I broke something", the smaller the incident. People only say it early if the last person who did was thanked.
- Do the action items. The drop in incidents comes from here. Each postmortem closes off a class of failure, but only if the items actually ship.
- Rehearse. Let a newer engineer be commander on a SEV3, with someone experienced next to them. Nobody should be learning the role during a SEV1.
The other thing a senior engineer brings to an incident is their own behaviour. People take their cue from the most experienced person in the room. If that person is typing fast and saying nothing, everyone gets tense. If they're asking short questions and writing things down, the room slows to a speed where people can think. You can decide to be calm in that sense, even when you don't feel calm.
What to try this week
- Find out how your team declares an incident. If the answer is "it depends", write a five-line version and propose it.
- Time a rollback on a quiet day. If it takes more than a few minutes or needs a specific person, that's your first improvement.
- Check where changes are visible. Deploys, flags, config, job schedules. Could you list everything that changed in the last hour, in one place?
- Read your last postmortem and look at the action items. How many are done?
- Write the status update template and pin it in the incident channel.
- Next time something breaks, even in staging, write the hypothesis and the prediction before running the test. It feels slow the first few times.
The short version
- An incident has an order: detect, stabilize, diagnose, fix, learn. The first two are on the clock.
- Stabilize before you understand. Ask what changed, and remember that changes aren't only deploys.
- A cheap, reversible mitigation doesn't need proof before you try it.
- Capture evidence before a restart, in thirty seconds, not ten minutes.
- Give people roles. The commander doesn't debug. Communications protects the investigators. Someone writes the timeline.
- One channel, updates on a fixed interval, impact first.
- Investigate with a loop: observe, hypothesis, prediction, test. One change at a time, and write down what you rejected.
- A mitigation stops the impact and a fix removes the cause. Don't ship the fix during the incident, and don't forget it afterwards.
- A blameless postmortem asks why the action made sense, and changes the system. "Be more careful" isn't an action item.
- Most of what makes an incident go well is decided before it starts.
A fair number of the mitigations in this part (scale out, fail over to another zone, take an instance out of the load balancer) assume you know what the platform under your service can do. That's Part 11: the cloud concepts that show up in every architecture conversation, explained once, without the provider-specific names getting in the way.
This is Part 10 of 18 in the series. The Senior Engineer Roadmap maps the whole series, with a short self-assessment and four reading orders.