123DevOps··6 min read

Chaos Engineering and Resilience: how to break your system on purpose (and safely)

Steady-state hypotheses, blast radius, abort conditions, and resilience patterns: a practical guide to starting chaos experiments without taking down production.

SRE

Every distributed system fails — the only question is whether you’ll find out how it fails on a Tuesday at 2 p.m., with the team ready, or on a Saturday at 3 a.m., with customers complaining. Chaos Engineering is the discipline of triggering controlled failures so you can learn from them before they happen on their own.

It’s not about “going around shutting down servers.” It’s an experimental method, with a hypothesis, measurement, and a stopping criterion. Done right, it’s one of the cheapest ways to improve reliability.

The principles

The community has settled on a few principles that separate chaos from mayhem:

  1. Define the steady state. Before injecting any failure, pick metrics that represent normal behavior from the user’s point of view: request success rate, p99 latency, orders completed per minute.
  2. Form a hypothesis. “If latency between checkout and payments rises to 300 ms, the checkout success rate stays above 99.5%.”
  3. Simulate real-world events. Node loss, network latency, failing DNS, full disk, a slow external dependency, an expired certificate.
  4. Minimize the blast radius. Start small: one pod, one zone, a percentage of traffic.
  5. Automate and repeat. An experiment that runs once is a demo; one that runs every week is a guarantee.

Anatomy of an experiment

Use a simple template and document every run:

Field Example
Hypothesis With 300 ms of latency on payments, checkout keeps a 99.5% success rate
Steady state Success rate ≥ 99.5% and p99 < 800 ms over the last 30 min
Injection 300 ms (±50 ms) network delay on app=payments pods
Blast radius Staging only; then 10% of pods in production
Abort condition Success rate < 99% for 2 minutes, or a burn rate alert fires
Duration 10 minutes
Result Hypothesis disproved: the HTTP client timeout was 30 s and the queue got stuck
Actions 2 s timeout + circuit breaker; rerun the experiment

The most important field is the abort condition. If you don’t know when to stop, you’re not ready to start.

Hands-on: network latency with Chaos Mesh

On Kubernetes, tools like Chaos Mesh and LitmusChaos let you declare experiments as cluster resources. The example below injects 300 ms of delay into every pod of the payments service for 10 minutes:

apiVersion: chaos-mesh.org/v1alpha1
kind: NetworkChaos
metadata:
  name: payments-delay
  namespace: checkout
spec:
  action: delay
  mode: all
  selector:
    namespaces: [checkout]
    labelSelectors:
      app: payments
  delay:
    latency: "300ms"
    jitter: "50ms"
    correlation: "25"
  duration: "10m"

In the cloud, managed services such as AWS Fault Injection Service (FIS) do the same for EC2 instances, ECS tasks, EKS nodes, and entire availability zones — with the advantage of supporting stop conditions tied to CloudWatch alarms. For local and integration testing, Toxiproxy simulates latency, packet loss, and dropped connections between the application and its dependencies.

What experiments usually uncover

After a few game days, the same problems show up on almost every team:

  • Missing or overly long timeouts. Many HTTP clients default to waiting forever — or 30 seconds. One slow dependency turns into a pile of stuck threads.
  • Retries that amplify the failure. Three layers making three attempts each add up to 27 requests to a service that’s already struggling.
  • “Optional” dependencies that aren’t optional. The recommendations service goes down and the entire product page returns a 500 error.
  • Alerts that don’t fire. The experiment wrecked the user experience and nobody got notified.
  • Outdated runbooks. Step 3 tells you to open a dashboard that no longer exists.

Resilience patterns you’ll need

Timeouts on every network call

Set timeouts based on the request’s latency budget, not the “default value.” If checkout has to respond within 1 s, the call to payments can’t have a 30 s timeout.

Retries with exponential backoff and jitter

Retrying immediately only adds load. Wait longer between each attempt and add randomness so thousands of clients don’t all retry at the same instant:

import random
import time


def call_with_retry(fn, attempts=4, base=0.1, cap=2.0):
    for i in range(attempts):
        try:
            return fn()
        except TransientError:
            if i == attempts - 1:
                raise
            # "full jitter": random wait between 0 and the exponential backoff
            time.sleep(random.uniform(0, min(cap, base * 2 ** i)))

Only retry idempotent operations (or use idempotency keys), and restrict retries to a single layer of the stack.

Circuit breaker

When a dependency fails repeatedly, stop calling it for a while and respond quickly with a fallback. This protects both your service and the dependency, which gets room to recover. Service meshes like Istio and Linkerd provide this without code changes (outlier detection).

Bulkheads and load shedding

Isolate resources (connection pools, queues, threads) per dependency or client type, so a noisy neighbor can’t exhaust everything. Under overload, reject some requests early (HTTP 429/503) instead of accepting everything and answering everything slowly.

Graceful degradation

Define what the product does when each dependency goes down: show cached recommendations, hide the shipping estimate, accept the order and process the payment later. These are product decisions, not just engineering ones — and they need to be made before the incident.

Game days: the human side of chaos

Not every experiment needs to be automated. A game day brings the team together to run a scheduled scenario — for example, “we lost the us-east-1a availability zone” — and observe not only the system but also the people:

  • Did the alert reach the right person?
  • Did anyone know where the runbook was?
  • Did communication with support and the status page work?
  • How long did it take to decide on a failover?

Always wrap up with a retrospective in the blameless postmortem format, with action items, owners, and deadlines.

A maturity roadmap

  1. Level 0 — Theoretical: list a critical service’s dependencies and what happens when each one fails. That alone reveals gaps.
  2. Level 1 — Game days in staging: manual, scheduled experiments with the whole team watching.
  3. Level 2 — Production with a limited blast radius: one pod, a percentage of traffic, automatic abort conditions tied to SLOs.
  4. Level 3 — Continuous: scheduled experiments or experiments in the CD pipeline, verifying resilience on every release.

Checklist before your first experiment

  • Enough observability to see the impact in real time
  • Steady state and hypothesis written down
  • Abort condition defined — and a tested stop button
  • Stakeholders notified (support, product, on-call)
  • Minimal blast radius for the first test
  • Business hours, with the team available

Confidence in a system doesn’t come from it never having failed. It comes from having seen it fail — and recover.

Get updates on new posts and stay in the loop!