Triaging a CPU Saturation Incident on a Customer-Facing API
System DesignModel answerLast updated
Talk through how you would scope, diagnose, mitigate and follow up when a revenue-critical public API suddenly runs near 100% CPU, and justify your choice among rollback, scaling, throttling and queues.
You are on call for a public-facing API. An alert shows that CPU is running very high across the service. You are not given the full picture up front. You may ask for any information a normal production environment provides: service and host dashboards, logs, deployment and configuration history, and the ability to profile a live instance.
Every call to this API is tied to revenue and to customer trust, so turning traffic away is expensive.
Describe how you would handle the incident from start to finish.
1. Confirm and scope. What do you check in the first minutes? How do you decide how urgent this is, and who do you inform?
2. Find the cause. Describe an investigation that branches based on what you learn, not a fixed checklist. Explain how each answer changes your next question.
3. Mitigate. Pick a mitigation and defend it. Compare:
- rolling back a change
- scaling out
- rate limiting customers (targeted or broad)
- moving some work to an asynchronous queue
Explain how you would protect downstream dependencies and avoid a retry storm.
4. Follow up. What do you do once the service is stable?
Questions you may want to ask the interviewer: Is CPU high everywhere or only on some instances? Are latency and error rates affected? Did anything change recently? Has traffic changed, and is it concentrated on a few customers or endpoints? Is the service stateless and autoscaled?
Hints
Hint 1
Start with customer impact (latency, errors, saturation of the request path), not with the CPU number itself. High CPU with healthy latency is a very different situation from high CPU with timeouts.
Hint 2
The central fork is: did the work per request go up, or did the number of requests go up? Compare CPU per request, request rate, and a deploy/config timeline against the onset of the problem.
Hint 3
Prefer the least harmful mitigation that addresses the cause: rollback for a bad change, scaling for genuine load, narrow throttling for one abusive source. Broad rate limiting is the last resort when every call is revenue, and any rejection should tell clients how to back off.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Framing
I would work impact-first and cause-second. The goal in the first minutes is to stop customer harm; the root cause can wait until the service is safe. I would also say my plan out loud and change it as answers arrive.
1. Confirm and scope (first 5 minutes)
Validate the signal. Is the metric real (not a broken exporter or a changed aggregation)? Check the customer-facing symptoms alongside it: p50/p99 latency, error rate, timeouts, queue depth, and saturation of the request path. High CPU with flat latency is a warning. High CPU with rising latency and 5xx is an active incident.
Scope it. Slice CPU by:
- instance (all or a subset), region or zone, build version, host type
- time of onset (a sudden step suggests a deploy, flag or config change; a ramp suggests traffic or data growth; a periodic spike suggests a cron job, cache expiry or batch client)
Severity call. If customers are failing or latency is breaching the SLO, declare an incident, name an incident lead, open a channel, and notify support and stakeholders. If it is only a metric with a healthy margin, treat it as urgent but not customer-impacting, and set a time limit before escalating.
2. Narrow the cause
The first and most useful branch is: per-request cost went up, or request volume went up? Compute CPU per request (CPU-seconds divided by requests per second) and compare it with the previous day or week.
Branch A: recent change (cost per request up, step change)
- Check deploys, feature flags, config, certificate or dependency changes, and data migrations near the onset.
- Compare canary or older-version hosts with new ones. If only the new build is hot, that is nearly decisive.
Branch B: traffic up (cost per request flat)
- Break traffic down by customer, endpoint, user agent, IP range and payload size.
- Concentrated on one source: a misbehaving client, a retry loop, a scraper, or an attack.
- Spread evenly: organic growth, a launch or a campaign. This is a capacity problem.
Branch C: neither obvious (data or dependency driven)
- A slow dependency can raise CPU through retries, timeouts and thread churn.
- Cache hit rate dropping (cold cache, bad key, eviction) shifts work onto the service.
- Growth in data size (large payloads, unbounded lists) makes the same code slower.
Profile a live instance. Take a CPU profile or flame graph from a hot host. Typical findings and how to recognize them:
| Pattern | Signature |
|---|---|
| Hot loop or algorithmic regression | One function dominates the flame graph |
| Regex or serialization cost | Time in regex engine or JSON/protobuf code |
| Garbage collection pressure | High GC time, allocation rate up, memory growth |
| Lock contention or thread spin | High system time, many runnable threads |
| TLS or compression overhead | Crypto/zlib frames after a config change or connection-reuse loss |
| Excess logging | Time in formatting and I/O paths |
| Retry storm | Request rate to the service inflated by client or upstream retries |
Each finding feeds the mitigation choice below.
3. Mitigate
Choose the least harmful action that matches the cause.
Rollback (or flag off). If a change correlates with onset, this is the first move. It is fast, reversible and addresses the cause, not just the symptom. Confirm CPU per request recovers.
Scale out. Right for genuine load growth or when the cause is not yet known and instances are stateless. It buys time without rejecting anyone. Limits: autoscaling lag, warm-up cost, and the risk of pushing the bottleneck to a database or downstream service. Check downstream headroom before adding instances. Scaling does not fix a regression; it only pays for it.
Targeted throttling. If one customer or client is responsible, limit that source (per-key quota, concurrency cap) and contact them. This protects everyone else and sacrifices little revenue.
Broad rate limiting. Because every call carries revenue and trust, I would reject it as a first response. It converts a performance problem into guaranteed customer-visible failures. I would use it only as a last resort to avoid total collapse, and then in a prioritized way: shed low-value or unauthenticated traffic first, protect paying and critical endpoints, return 429 with Retry-After, and prefer degrading (serve stale or cached results, disable expensive optional features) over hard rejection.
Asynchronous queueing. Good for work that does not need an immediate response (webhooks, report generation, enrichment). It smooths bursts and decouples CPU from request latency. Not suitable for synchronous calls where the client needs the answer, and it adds complexity: idempotency, ordering, backlog monitoring, and a dead-letter path. It is a medium-term design change, not a mid-incident fix, unless the endpoint is already asynchronous in nature.
Avoid a retry storm. Rejections and timeouts cause clients to retry, which raises load further. Use Retry-After, exponential backoff with jitter in client guidance, retry budgets, and circuit breakers. Also protect downstream dependencies with concurrency limits and bulkheads so extra instances do not flood them.
Decision summary: change-caused: roll back. One bad actor: throttle that actor. Organic load: scale out and degrade gracefully. Unknown: scale out for time while profiling. Broad limits: last resort.
4. After the incident
- Confirm root cause. Reproduce it in staging or with a load test, not just by correlation. Verify the fix by watching CPU per request.
- Blameless review. Timeline, detection gap, decisions made, what slowed us down. Focus on system and process fixes.
- Capacity and limits. Revisit autoscaling thresholds and warm-up time, headroom targets (for example, peak below 60 to 70 percent CPU), and per-customer quotas set to fair, documented values.
- Detection. Alert on CPU per request, not just CPU; on latency SLO burn rate; and on per-customer traffic anomalies. Add deploy-aware dashboards that overlay change markers.
- Prevention. Canary deploys with automatic CPU and latency comparison, performance regression tests in CI, and continuous profiling so a flame graph is already available next time.
Common mistakes
- Treating the CPU graph as the problem without checking customer impact.
- Scaling out immediately and never finding the regression.
- Rate limiting everyone, causing outages for paying customers and triggering retries.
- Skipping the "did something change?" question.
- Adding instances without checking database or downstream capacity.
- Ending the incident without detection and prevention work.