Home/Learn/System Design/Chaos Engineering

Chaos Engineering

Advanced
Observability & Operations

Chaos engineering intentionally injects failures (kill pods, introduce latency, partition networks) into production-like systems to verify that the system handles failures gracefully and build confidence in resilience.

Overview

Chaos engineering, pioneered by Netflix (Chaos Monkey), is the discipline of experimenting on a system to build confidence in its ability to withstand turbulent conditions in production. The process is: (1) Define "steady state" — what does normal behaviour look like? (metrics, SLOs). (2) Hypothesise — "if we kill 30% of pods, latency stays below 200ms because Kubernetes reschedules them." (3) Inject failure — kill pods, introduce network latency, corrupt data, exhaust disk space. (4) Observe — does the system maintain steady state? (5) Learn and fix — if the system fails, you found a weakness before customers did. Chaos experiments should start small (dev environment, non-critical services) and gradually move to production with blast radius controls. Tools include Chaos Monkey (random instance termination), Gremlin (commercial, comprehensive fault injection), Litmus Chaos (Kubernetes-native), and AWS Fault Injection Simulator.

Chaos Engineering Principles

Start with a hypothesis about system behaviour under failure. Inject controlled failures. Observe if the system maintains its steady state. Fix weaknesses found.

Conceptual — chaos engineering lifecycle
// Chaos engineering process
//
// 1. Define steady state
//    "Order API returns 200 in < 200ms for 99.9% of requests"
//
// 2. Hypothesise
//    "If we kill 2 of 5 order-service pods, Kubernetes reschedules
//     them within 30s and latency stays below 200ms because the
//     remaining 3 pods absorb the traffic"
//
// 3. Run experiment
//    Kill 2 pods at 10:00 AM
//    Monitor: request rate, error rate, p99 latency
//
// 4. Observe results
//    ✅ Pods rescheduled in 15s
//    ⚠️ Latency spiked to 350ms for 20 seconds (unexpected)
//    ✅ No 5xx errors
//
// 5. Learn and improve
//    Finding: HPA takes 30s to scale up → pre-warm extra pods
//    Action: Set minReplicas from 3 to 5

// Blast radius controls:
// Start in staging → move to production
// Start with non-critical services → then critical
// Set maximum impact: "kill at most 1 pod per service"
// Have an abort switch: stop experiment immediately if SLO breached

Tools & Experiments

Chaos Monkey kills random instances. Litmus Chaos runs Kubernetes experiments. Common experiments: pod kill, network latency, DNS failure, disk pressure, CPU stress.

Litmus YAML + Conceptual — chaos experiments
// Litmus Chaos — Kubernetes-native chaos experiments
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
  name: order-service-chaos
spec:
  appinfo:
    appns: default
    applabel: app=order-service
  chaosServiceAccount: litmus-admin
  experiments:
    - name: pod-delete
      spec:
        components:
          env:
            - name: TOTAL_CHAOS_DURATION
              value: '60'       # chaos for 60 seconds
            - name: CHAOS_INTERVAL
              value: '10'       # delete a pod every 10s
            - name: FORCE
              value: 'true'

// Common chaos experiments:
// 🔴 Pod kill:       Kill random pods → test auto-recovery
// 🟡 Network latency: Add 500ms latency → test timeouts and circuit breakers
// 🟡 Network partition: Isolate a service → test fallbacks
// 🔴 DNS failure:    Block DNS → test service discovery resilience
// 🟡 CPU stress:     Max out CPU → test auto-scaling and throttling
// 🔴 Disk full:      Fill disk → test logging and data handling
// 🟡 Zone failure:   Kill all pods in one AZ → test multi-AZ resilience

// Netflix Chaos Monkey — random instance termination
// Runs during business hours in production
// Forces engineers to build resilient services
// "If you can't survive Chaos Monkey, you can't survive production"

Key Points to Remember

  • 1Chaos engineering intentionally injects failures to verify system resilience before real failures occur.
  • 2Process: define steady state → hypothesise → inject failure → observe → learn and fix.
  • 3Start small (staging, non-critical) and gradually move to production with blast radius controls.
  • 4Common experiments: pod kill, network latency, DNS failure, disk pressure, zone failure.
  • 5Tools: Chaos Monkey (Netflix), Litmus Chaos (K8s), Gremlin (commercial), AWS FIS.

Interview Questions

Sign in to ask Aria
1

What is chaos engineering and why is it important?

EasyTCS
2

Describe the steps of a chaos engineering experiment.

MediumAmazon
3

What blast radius controls should you have for chaos experiments in production?

MediumGoogle
4

What failures would you test for in a microservices e-commerce platform?

HardFlipkart
5

Design a chaos engineering program for a company running 200 microservices on Kubernetes.

HardNetflix

Ask Aria about Chaos Engineering

Your personal AI tutor — ask anything about this concept

Revision Status

Personal Notes

Sign in to save personal notes for this topic.

Discussion

Sign in to join the discussion.

Loading discussion…