28.9. Incident Response
Table of Contents
Why Incident Response Matters
Incidents are those moments when your backend system behaves in a way that hurts users or the business. Examples:
- Your API is returning a lot of 500 errors.
- Response times jump from 100 ms to 10 seconds.
- The database is overloaded and queries time out.
- A deployment breaks authentication.
- Suspicious traffic hints at an attack.
Incident response is the structured way you detect, handle, communicate, and learn from these events.
Good incident response does three things:
- Minimize impact on users and the business.
- Restore service quickly and safely.
- Produce learning so the same problem is less likely next time.
Important rule
Do not treat incidents as random bad luck. Treat them as signals about weaknesses in your system and process. Every significant incident must produce some form of improvement.
This chapter focuses on how to handle incidents in production, not on how to fully prevent them. Prevention and resilience are covered by other chapters like Monitoring Production Systems, Fault Tolerance, and High Availability.
What Is an Incident?
Incident vs Bug vs Outage
- Bug
A defect in code or configuration. It might or might not cause visible harm.
Example: A function calculates a discount incorrectly, but customers do not notice yet.
- Incident
A bug, failure, attack, misconfiguration, or dependency problem that actively impacts users or business goals.
Example: Checkout requests begin failing with 500 errors and orders cannot be completed.
- Outage
A severe incident where a critical service is unavailable or severely degraded.
Example: Your API gateway is down and all requests fail.
You can think of it like this:
$$\text{Incident} = \text{Problem} + \text{User / Business Impact}$$
If there is no impact yet, you are dealing with a risk or a latent bug, not an incident.
Incident Severity
Not all incidents are equal. You need a severity scale to decide how urgently to respond and who to involve.
A common 4-level scale:
| Level | Name | Typical Impact | Example |
|---|---|---|---|
| SEV1 | Critical | Major business function down, many users affected, urgent response needed | Checkout API is down, no orders can be placed |
| SEV2 | High | Important functionality broken, significant set of users affected | Payments work but are extremely slow or flaky |
| SEV3 | Medium | Degraded experience, workarounds exist, limited user group affected | Admin dashboard returns 500s for some queries |
| SEV4 | Low | Minor issues, no immediate impact, cosmetic or background processes degraded | Daily analytics job failed, no user-facing impact today |
Severity rule
Always assign a severity at the beginning of an incident and upgrade it if you are unsure. It is safer to treat an issue as more serious and downgrade later.
For a beginner-friendly rule of thumb:
- If money stops flowing in or core business stops, treat it as SEV1.
- If customers can continue but are badly hurt (timeouts, frequent errors), treat it as SEV2.
- If only internal users or non-critical features are affected, SEV3 or SEV4.
The Incident Response Lifecycle
Most organizations use a similar lifecycle:
- Detection
You notice something is wrong. Often via alerts or monitoring. - Triage
You assess severity and decide whether this is an incident, and which type. - Containment
You stop things from getting worse. Sometimes you disable features or roll back. - Mitigation / Remediation
You fix or work around the root cause to restore service. - Recovery
You return systems to the normal, stable state and confirm they are healthy. - Post‑incident review
You analyze what happened and create follow‑up actions.
You can visualize it as a simple state machine:
$$
\text{Healthy} \rightarrow \text{Incident Detected} \rightarrow \text{Investigating} \rightarrow \text{Mitigated} \rightarrow \text{Learning}
$$
At beginner level, the key idea is: you follow a structured process every time, not random improvisation.
Detection and Alerting
You cannot respond to incidents you do not notice. Detection depends on monitoring and alerts.
Sources of Detection
Typical signals:
- Automated alerts
- High error rate in an endpoint.
- High CPU or memory usage.
- Increased response latency.
- Database connection pool exhaustion.
- User reports
- Support tickets.
- Emails from customers.
- Internal reports
- Colleagues notice something on dashboards.
- Security systems
- Suspicious login patterns.
- Large spike in failed authentication attempts.
If you have good monitoring, most incidents should be detected by alerts before users report them.
Good Alert Design
You want alerts that are useful and actionable, not noisy. Examples:
| Bad Alert | Good Alert |
|---|---|
| "CPU > 80% for 5 minutes" | "Checkout API p95 latency > 2s for 5 minutes for more than 10% of traffic" |
| "Database connections > 80% used" | "Database 'orders' connection pool exhausted, 5% of requests failing" |
| "Error rate increased" | "500 error rate on POST /orders > 2% for 10 minutes" |
Actionable alert rule
Every alert should have a clear owner and lead to a specific action. If no one knows what to do when an alert fires, you should not have that alert.
Triage and Classification
Once something suspicious is detected you perform triage:
- Is this a real incident or just noise?
- A single 500 might not be an incident.
- 10% of requests failing for 5 minutes likely is.
- What is the severity?
- Use your severity table and decide SEV1 to SEV4.
- What is the scope?
- Which services, endpoints, or regions are affected?
- Is this affecting internal users, external users, or both?
- Who needs to be involved quickly?
- On-call backend engineer.
- Database specialist.
- Security or networking person, if needed.
Example Triage Scenario
You see an alert:
"500 error rate for POST /orders is 12% for last 10 minutes."
You check logs and confirm:
- Error codes:
psycopg2.OperationalErrorfor database timeouts. - Only POST /orders is affected. GET /products and GET /cart are fine.
- Traffic volume is high but not higher than expected.
Triage outcome:
- This is a real incident.
- For an e-commerce system, checkout is core revenue, so treat as SEV1.
- Scope is the orders service, likely database layer.
- You notify the on-call engineer and start the incident response process.
Roles During an Incident
Even in small teams, it helps to separate roles so people are not doing everything at once.
Typical roles:
| Role | Responsibility |
|---|---|
| Incident Commander (IC) | Owns the response process, makes decisions, keeps track of progress, manages communication |
| Subject Matter Experts | Investigate technical causes, try fixes, gather data |
| Scribe / Note taker | Records timeline, actions taken, and important observations |
| Communications owner | Updates stakeholders (support, product, management, maybe public status page) |
In a very small team, one person might play several roles. But you should still think in roles:
- One person leads and decides.
- Others focus on debugging and remediation.
- Someone explicitly keeps track of what is happening and when.
Role rule
During a serious incident, avoid "everyone debugs everything". Assign an Incident Commander and let them coordinate so work is not duplicated and communication is clear.
First Steps: Stabilize and Contain
When you notice an incident, your first goal is not to find the deep root cause. Your first goal is to stop the bleeding.
Containment Strategies
Examples of containment actions:
- Roll back the last deployment if error rate jumped right after a release.
- Disable a problematic feature with a feature flag.
- Redirect traffic away from a broken region.
- Rate limit or block certain requests if they are overloading the service.
- Scale up instances temporarily, if you suspect capacity issues.
- Temporarily block external integrations that are misbehaving.
Example
After a new version of the Orders API is deployed:
- Error rate for POST /orders jumps from 0.1% to 15%.
- Logs show new validation logic throwing unexpected exceptions.
The safest containment step is:
- Roll back to the previous stable version.
You can then debug the new validation logic offline, in a staging environment.
Gathering Information Safely
After containment or in parallel, you need data to understand the incident. Key sources:
- Logs
- Error messages, stack traces, structured context (user IDs, order IDs, correlation IDs).
- Metrics
- Error rates, latencies, CPU, memory, number of requests, queue lengths.
- Traces
- Distributed traces through services, helpful when microservices are involved.
- Recent changes
- Recent deployments, configuration changes, database migrations, feature flag changes.
- External dependencies
- Cloud provider status pages.
- Payment processors, email providers, etc.
You should:
- Confirm when the problem started.
- Check what changed around that time.
- Identify which components are affected.
Do no harm rule
During an incident, be careful with experiments. Never run dangerous scripts or schema changes directly in production as a "test". Always ask, "Could this make things worse?"
Fixing the Incident
After containment, you move to mitigation and remediation.
- Mitigation
Action that reduces impact or makes the system usable again, even if the root cause still exists.
Example: Temporarily disable a heavy report feature to reduce database load.
- Remediation
Action that removes or corrects the actual root cause.
Example: Fixing a missing database index that caused timeouts.
Example: Database Connection Exhaustion
Symptoms:
- Many requests failing with "too many connections" or timeouts.
- Metrics show the connection pool at max capacity.
Mitigation:
- Increase connection pool size slightly, if safe.
- Scale out application servers carefully if they are under capacity.
- Apply rate limiting on the heaviest endpoints.
Remediation (after the fire is under control):
- Identify endpoints that open too many connections or leak connections.
- Add or fix connection pooling in the ORM or driver.
- Review and reduce long-running queries.
- Add or improve database indexes.
Communication During Incidents
Technical work is only half of incident response. Communication is the other half.
Internal Communication
You need to keep:
- Engineers aligned on symptoms, hypothesis, and actions.
- Product/operations/management informed about impact and progress.
- Support teams able to answer customer questions.
Good internal updates have:
- Current state: "Orders API is failing for about 20% of requests."
- Scope: "Affects EU region only."
- Current action: "Rolled back to previous version, monitoring."
- Expected next update: "Next update in 15 minutes."
Avoid:
- Guessing the root cause too early.
- Saying "it is fixed" before you have confirmed stability.
External Communication
For user-facing incidents, you might:
- Update a status page.
- Post in support channels.
- Send targeted emails to affected customers for severe incidents.
Even a beginner team can write short, clear messages:
We are currently experiencing elevated error rates for order creation affecting some users in the EU region. Our team is investigating and working on a fix. We will provide an update in 30 minutes.
Later, after mitigation:
We have rolled back a recent change and error rates have returned to normal. We are monitoring the system closely and will publish a detailed summary after our investigation.
Post‑Incident Review (Postmortem)
The most valuable part of incident response is what you do afterward.
A post‑incident review (often called a postmortem) is a structured document and meeting where you:
- Reconstruct the timeline
- When did it start?
- When was it detected?
- What actions were taken and when?
- Explain technical cause
- What precisely failed?
- Why did this cause the specific symptoms?
- Understand impact
- Which users or systems were affected?
- How many requests failed?
- How long did it last?
- Analyze the response
- What went well?
- What delayed detection or response?
- Were alerts and runbooks helpful?
- Decide improvements
- Code or configuration changes.
- Monitoring and alerting improvements.
- Process changes or training.
- Documentation or runbook updates.
Blameless rule
Post‑incident reviews must be blameless. Focus on systems, processes, and incentives, not on blaming individuals. This is essential for honest learning.
Example Post‑Incident Questions
- What signals did we ignore or miss?
- Could better dashboards or logs have reduced time to resolution?
- Should we add a safe "rollback" button for deployments?
- Could automated tests have caught this before production?
Runbooks and Playbooks
A runbook is a step‑by‑step guide for handling a known incident type.
For example, a runbook for "Database connection exhaustion" might include:
- Check database connections metric.
- Check application instance count and traffic pattern.
- Temporarily reduce heavy batch jobs.
- If needed, increase pool size by a small, predefined amount.
- Notify database owner if pool has been increased.
- After the incident, schedule index/optimization review.
Runbooks help:
- New team members respond more confidently.
- Reduce response time.
- Standardize safe actions.
You can have runbooks for:
- "High error rate after deployment."
- "Unusually high latency on a specific endpoint."
- "Cache cluster unavailable."
- "Payment provider outage."
- "Redis under heavy load."
For each runbook, include:
| Field | Description |
|---|---|
| Name | Short name of the incident type |
| Symptoms | What you see in alerts, dashboards, logs |
| Quick checks | Fast checks to confirm or rule out this problem |
| Safe actions | Low‑risk steps for immediate mitigation |
| Escalation | Who to contact if safe actions do not work |
| Follow‑up | Items to check after the incident ends |
Coordinating with Other Production Practices
Incident response interacts with several other production topics from this course:
- Monitoring Production Systems
Good monitoring is your "nervous system" for incident detection and analysis. - Health Checks
Health endpoints and readiness checks help you detect failing instances and remove them from load balancers. - Graceful Shutdown
Avoids making incidents worse during deployments or restarts. - Retry Strategies and Circuit Breakers
Can automatically reduce the impact of some failures by preventing cascading outages. - High Availability
Reduces the scope of incidents, for example only one region instead of the whole system.
Incident response does not replace these topics. It is what you do when all your protective mechanisms are not enough.
Building an Incident Response Culture
Even small backend teams can establish a minimal incident response culture:
- Define what "incident" means
For example, any issue that impacts users for more than 5 minutes or blocks purchases is an incident. - Define severity levels
Create a simple SEV1 to SEV4 table that fits your product. - Define ownership
Decide who is on‑call or who is responsible for responding to which systems. - Improve after every incident
Always produce at least one improvement, such as: - Better logs.
- A new or improved alert.
- A small code change.
- A new runbook step.
- Practice
Occasionally simulate incidents in a test environment, for example: - "The database is down, what do we do?"
- "The payments provider is timing out, how do we handle this?"
Over time, your incident response will become faster, more confident, and more predictable, which is exactly what a production backend needs.
Views: 7
KAHIBARO