Skip to content

Lesson 5 of 9 · 27m

Fault Injection Mechanics: Latency, Loss, Failure, and Resource Pressure

Choose fault types that reproduce realistic dependency behavior without confusing implementation artifacts for resilience lessons.

Not all faults teach the same lesson. Killing a process tests restart behavior, but many real dependencies do not disappear; they become slow, inconsistent, partially unavailable, or return successful-looking responses with bad data. The best fault injection resembles production failure closely enough that the response generalizes, while remaining controlled enough to remove cleanly.

Latency is usually the highest-value fault

Latency exposes timeout mismatches, queueing, retry amplification, thread starvation, and misleading dashboards. On Linux, network emulation can add controlled delay:

sudo tc qdisc add dev eth0 root netem delay 350ms 75ms distribution normal
sudo tc qdisc show dev eth0
sudo tc qdisc del dev eth0 root

The exact interface varies in containers and cloud environments, but the principle matters: jitter is realistic because dependencies rarely degrade to one perfectly constant number. Test both moderate latency and latency just above a timeout threshold; boundary behavior often reveals cascading failure.

Failure injection should match the trust boundary

You can inject at several layers:

process termination     restart, supervision, health checking
network partition       failover, quorum, discovery behavior
DNS failure             resolver, caching, endpoint discovery
HTTP 500/429/timeout    client retry and circuit behavior
message delay/loss      queueing, ordering, idempotency
disk/CPU pressure       resource isolation and saturation

Do not claim DNS resilience because you killed an application process. Conversely, do not kill processes when the question is whether a client handles 429 correctly. Match the fault to the hypothesis.

Use service-level injection where possible

A dependency stub or proxy can return precise responses without damaging infrastructure:

@app.post("/payments/authorize")
def authorize():
    if chaos_enabled():
        time.sleep(1.8)  # just above the client timeout
        return Response(status_code=504)
    return real_authorize()

This is artificial, but precise. The purpose is not to prove the real provider fails this exact way; it is to verify your service's behavior when any payment path exhibits this failure signature.

Resource pressure is a different beast

CPU, memory, disk, file descriptors, and connection pools fail nonlinearly. Use small increments and strong limits. A memory leak test can trigger the OOM killer in unrelated processes if cgroup boundaries are sloppy. Disk-fill experiments can corrupt write-ahead logs or block unrelated services. Prefer dedicated nodes, namespaces, or synthetic tenants until resource isolation is proven.

Field notes

  • Remove injection even when the experiment errors; cleanup failure is part of blast radius.
  • Record clock time precisely. Latency effects often appear only after queues saturate.
  • Artificially instant failures can hide queueing behavior that real slow failures expose.
  • Do not inject randomness everywhere and then claim causality. Precision beats chaos for learning.

Was this lesson helpful?

Sign in to rate