Pidoku

Archive

This learning material is in the archive. It is not currently maintained and has not been updated with the latest information, so tool versions, prices and dates may be out of date.

Chaos Engineering

Module 10 Lesson 10.a 45 min Difficulty 3/5

Prerequisites 6.c, 7.a

The idea in one minute#

Chaos engineering is running controlled experiments that inject real failures — kill an instance, add latency to a dependency, fill a disk, partition a network, lose a zone — to check that the system behaves as you believe it will. It is not “breaking things randomly”. Each experiment states a steady-state hypothesis (“checkout success stays above 99.9% while one zone’s pods are killed”), limits the blast radius, has abort conditions that stop it automatically, and ends with something learned.

Netflix popularised the idea with Chaos Monkey (randomly terminating production instances, 2011) so that engineers would build services that survive it. The discipline has since matured into tools (Chaos Mesh, LitmusChaos, AWS Fault Injection Service, Azure Chaos Studio, Gremlin, Steadybit, Toxiproxy) and a method.

An analogy#

A vaccine: a small, controlled exposure to the thing you fear, so the body learns to handle the real one. Nobody vaccinates by injecting the full disease at full strength.

A picture#

flowchart LR
  SS[":i-gauge: <b>Steady state</b><br/><small>SLIs: success rate, p99</small>"] --> H["<b>Hypothesis</b><br/><small>'stays within SLO when X fails'</small>"]
  H --> SC["<b>Scope</b><br/><small>blast radius: 1 pod → 1 zone</small>"]
  SC --> RUN[":i-zap: <b>Inject fault</b><br/><small>Chaos Mesh, Litmus, FIS</small>"]
  RUN --> OBS[":prometheus: <b>Observe</b>"]
  OBS -->|"abort condition hit"| STOP[":i-hand: <b>Stop + roll back</b>"]
  OBS --> LEARN[":i-file-text: <b>Learn</b><br/><small>confirmed or a bug found</small>"]
  LEARN --> SS
  class SS memory
  class H,SC queue
  class RUN warn
  class OBS io
  class STOP warn
  class LEARN compute

How it really works#

The principles#

From the Principles of Chaos Engineering (principlesofchaos.org):

  1. Build a hypothesis around steady-state behaviour — measurable output (SLIs), not internal attributes.
  2. Vary real-world events — the failures that actually happen: instance loss, latency, dependency errors, clock skew, full disks, traffic spikes.
  3. Run experiments in production — eventually; staging differs from production in ways that matter.
  4. Automate experiments to run continuously — a one-off experiment proves things only about that day.
  5. Minimise blast radius — start tiny, expand only with confidence.

Designing an experiment#

Experiment: checkout survives the loss of one zone's pods
Steady state:   checkout success ≥ 99.9% and p99 < 800 ms (5-minute windows)
Hypothesis:     killing all checkout pods in zone eu-west-1a keeps steady state; traffic shifts
                to the other zones within 30 s; HPA adds capacity within 3 min.
Blast radius:   staging first; then production, one zone, 10:00 Tuesday, 15 minutes.
Abort if:       success < 99.5% for 1 minute, or p99 > 2 s, or any SEV declared elsewhere.
Rollback:       stop the experiment (pods are recreated by the Deployment automatically).
Observers:      SRE on call (aware), payments on call (aware), IC rotation (aware).
Result:         [confirmed / refuted] + findings + action items.

What to inject#

CategoryFaultsTests
ComputeKill pod / instance / node; CPU or memory stressRedundancy, autoscaling, PDBs, scheduling
NetworkLatency, packet loss, partitions, DNS failure, bandwidth limitTimeouts, retries, breakers, failover
DependenciesErrors or latency from one downstream, blackholing itDegraded modes, bulkheads
StorageDisk full, I/O latency, read-only filesystemAlerting, graceful failure
StateDatabase failover, replica lag, cache flushFailover handling, cold-cache behaviour (6.e)
TimeClock skewToken validation, ordering
InfrastructureZone loss, region evacuationDR plans (9.b)
TrafficSpikes, replayed burstsLoad shedding, rate limits

Tools#

ToolWhereNotes
Chaos Mesh (CNCF)KubernetesCRDs for pod, network, stress, I/O, time, DNS, HTTP faults; workflows and schedules
LitmusChaos (CNCF)KubernetesExperiment hub, probes for steady state, a web UI (“ChaosCenter”)
AWS Fault Injection ServiceAWSEC2, ECS, EKS, RDS, network, AZ power-interruption scenarios; stop conditions on CloudWatch alarms
Azure Chaos StudioAzureService- and agent-based faults
Gremlin, SteadybitCommercial, multi-platformSafety controls, scheduling, reporting
ToxiproxyAnywhere (a TCP proxy)Latency, bandwidth, timeouts between app and dependency — great in CI
Istio / Envoy fault injectionService meshDelay or abort a percentage of HTTP requests

A Chaos Mesh network delay:

YAML
apiVersion: chaos-mesh.org/v1alpha1
kind: NetworkChaos
metadata: { name: pricing-latency, namespace: payments }
spec:
  action: delay
  mode: all
  selector:
    namespaces: [payments]
    labelSelectors: { app: pricing }
  delay: { latency: "400ms", jitter: "100ms", correlation: "50" }
  duration: "10m"

An Istio fault on 10% of requests to a dependency:

YAML
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata: { name: reviews }
spec:
  hosts: [reviews]
  http:
    - fault:
        abort: { percentage: { value: 10 }, httpStatus: 503 }
      route: [{ destination: { host: reviews } }]

Safety#

  • Start in staging, then a canary cell or one zone in production, in business hours, with the owning team aware.
  • Automatic abort conditions on SLIs — tools support stop conditions tied to alarms.
  • Never during an incident or a peak event; check the error budget first (an exhausted budget means no experiments, 2.c).
  • A tested off switch. If stopping the experiment depends on the thing you broke, it is not an off switch.

Maturity path#

  1. Game days in staging, by hand (10.c).
  2. Automated experiments in staging, in CI or nightly.
  3. Small, scheduled experiments in production with abort conditions.
  4. Continuous, automated production experiments as part of the release process.

A worked example#

Hypothesis: “If the reviews service returns 503 for all requests, the product page still loads within the latency SLO, without reviews.”

  • Run 1 (staging, Istio abort 100%): the product page returns 500. The reviews client has no fallback for 503 — only for timeouts. Hypothesis refuted: a bug, found safely.
  • Fix: treat any reviews error as “render without reviews”; add a degraded-response metric.
  • Run 2 (staging): page loads in 180 ms without reviews. Confirmed.
  • Run 3 (production, 5% of requests, 15 minutes): confirmed; degraded-response rate matches the injected 5%.
  • Automate: the staging experiment runs nightly; the production one monthly.

The program in 10.b shows how to inject exactly these faults inside a Go service.

Remember this#

  • Chaos engineering is experiments, not random breakage: steady-state hypothesis, real-world fault, limited blast radius, abort conditions, learning.
  • Start small and in staging; graduate to production with stop conditions.
  • Inject what really happens: instance loss, latency, dependency errors, disk full, failover, zone loss, spikes.
  • Tools: Chaos Mesh, LitmusChaos, AWS FIS, Azure Chaos Studio, Gremlin, Toxiproxy, mesh fault injection.
  • No experiments during incidents, peaks or with an exhausted error budget.

Try it#

  1. Write an experiment plan (using the template) for one dependency of a service you know.
  2. Install Chaos Mesh in a kind cluster and run a pod-kill experiment against a two-replica Deployment without a PDB. Watch the Service endpoints.
  3. Put Toxiproxy between a local app and its database; add 500 ms of latency. What breaks first?

Check yourself#

  1. What makes a chaos experiment different from just breaking things?
  2. Why should the hypothesis be about steady-state SLIs, not about internal details?
  3. Name three abort conditions for a zone-loss experiment.
  4. Why must the off switch not depend on the component under test?

Sources#

↑↓ navigate↵ openesc close

100% drag to pan · scroll or pinch to zoom · double-click to zoom in