Lesson 9 of 9 · 27m
Diagnosing Saturation: Reading Production Failure Modes
Connect symptoms to mechanisms: queueing, retries, thread exhaustion, memory reclaim, disk stalls, and the cascading failures they create.
Production failures rarely arrive labeled. You see elevated p99 latency, health-check flaps, a queue backing up, or a deploy that 'suddenly' cannot handle normal traffic. Operating system knowledge pays off when you translate those symptoms into mechanisms. The mechanism tells you whether adding capacity helps, whether backpressure is missing, or whether a small configuration limit is strangling the service.
Saturation creates queues before it creates errors
A thread pool with 50 workers and 500 incoming requests per second does not 'handle' overload gracefully. It queues. Queueing inflates latency before utilization reaches 100%, and users experience the queue as slowness. If clients time out and retry, the queue receives duplicate work — a retry amplification loop.
Useful production signals:
accepted connections / active workers / queued tasks / oldest queued taskOldest task age is often the best leading indicator. A queue length can look stable while age rises because throughput and arrival rate are both high. Systems fail at the margin, not at the average.
Thread exhaustion masquerades as dependency failure
Suppose every request calls a downstream API synchronously and holds a thread while waiting. When the downstream slows from 20 ms to 2 seconds, in-flight requests multiply by a hundred. Your service has no CPU problem, but every worker is parked in read() or poll() waiting for sockets. New work queues behind them. Dashboards then show 'dependency latency' and 'thread pool exhausted' as separate events; they are one mechanism.
The fixes are layered: timeouts, bounded concurrency, circuit breaking, and bulkheads. The OS insight is simple: blocked threads are cheap individually but expensive as a coordination pattern.
Memory reclaim can look like an application freeze
When memory pressure rises, the kernel scans and reclaims pages. Processes may fault pages back in, write dirty pages, or stall in direct reclaim. You see latency spikes with moderate CPU and no obvious application error. PSI memory pressure, major faults, and OOM logs connect the dots.
JVMs and large allocators make this more interesting because the runtime responds to pressure by collecting garbage, which itself consumes CPU. The system enters a feedback loop: memory pressure causes GC, GC uses CPU, latency rises, retries add work, and memory pressure worsens. Treat the resource loop as one system.
Disk stalls have outsized blast radius
Storage latency affects more than file-heavy apps. Logging, access logs, metrics spooling, local queues, TLS session tickets, temporary files, journal writes, and container layers all touch storage. A disk stall can freeze seemingly unrelated services.
iostat -x 1
cat /proc/pressure/ioIf device await jumps from 1 ms to 200 ms and IO pressure rises, trust the evidence. Do not let a low %util talk you out of it; distributed or parallel devices can have low utilization with bad tail latency.
Cascades are usually retry and timeout mismatches
If downstream timeout is 30 seconds but upstream client timeout is 2 seconds, upstream gives up while downstream keeps doing expensive work. Retries multiply it. The downstream sees load even though no useful responses are being consumed. Align timeouts so work can be canceled early, propagate cancellation, and bound retries with jitter.
At the OS boundary, cancellation often means closing a socket. If applications ignore cancellation and continue work anyway, kernel sockets close but CPU and memory burn continues. Correct behavior requires cooperation above the syscall layer.
Capacity changes behavior, not just volume
Adding replicas can reduce CPU per node but increase pressure on shared databases, conntrack tables, DNS resolvers, and connection pools. Adding memory can delay OOM while increasing cache dependence. Faster disks can shift the bottleneck to CPU. Measure the next bottleneck after every change; capacity work is queueing theory with invoices.
Field notes
- Treat timeouts as resource protection, not error cosmetics. Every blocking wait needs a deliberate deadline.
- Retries without jitter synchronize failures. Thundering herds are often self-inflicted.
- A health check that exercises the same saturated workers can turn overload into a full outage. Use shallow and deep checks deliberately.
- During a cascade, reduce incoming work first. Restarting everything often resets connection warm-up and makes the burst worse.
- Write down the mechanism in the incident review: 'thread pool exhausted waiting on downstream' beats 'service was slow' every time.
Was this lesson helpful?