Emre Şahin

Ġurnal tal-Inġinerija

Closing the Chaos Loop

Why most chaos tools stop at injection, and how I designed an event-driven loop that observes, remediates and scores every experiment.

Emre Şahin ·

Most chaos engineering tools are very good at one thing: breaking something on purpose. You pick a target, choose a fault, set a duration, and press the button. A pod dies, a network link slows down, a disk fills up.

Then the tool's job is done. What happens next is your problem.

That is the gap I kept running into, and it is the reason I started building FaultMesh. This post is about the architecture I chose to close that gap, and the trade-offs behind it.

Injection is the easy part

An experiment is a hypothesis: "if the payment service loses 30% of its pods, checkout latency stays under 800 ms and nothing pages anyone." Injecting the fault is only the setup. The interesting questions come after:

  • Did we notice? How long did it take?
  • Did anything fix it, automatically or by hand? How long did that take?
  • Was the system better or worse at this than last month?

If a tool stops at injection, all of that lives in someone's head, a Grafana screenshot, and a postmortem doc. That doesn't compound. You cannot trend a screenshot.

So the design goal was simple to state: one experiment, one closed loop. Inject, observe, remediate, score. Every step recorded against the same experiment, so detection time and recovery time are data, not anecdotes.

The loop as events

I modelled the loop as a chain of integration events on RabbitMQ, using MassTransit:

 Control plane            Observation           Remediation           Scoring
 ─────────────            ───────────           ───────────           ───────
 ExperimentStarted
        │
        ▼
 FaultInjected ─────────► (watching metrics,
   InjectedAt              traces, logs)
                                │
                                ▼
                          AnomalyDetected ────► policy check,
                            DetectedAt          execute actions
                                                      │
                                                      ▼
                                              RemediationCompleted ──► ScoreCalculated
                                                CompletedAt                  │
                                                                             ▼
                                                                   ExperimentCompleted

Each plane only knows about the events it consumes and the events it publishes. The observation plane has no idea a remediation plane exists. It sees a fault was injected, watches the signals, and announces an anomaly when it finds one. Whoever cares can react.

This matters more than it looks. The remediation plane is the part an enterprise customer is most likely to want switched off, or replaced with their own runbook automation. Because it is just a consumer of AnomalyDetected, turning it off does not break detection or scoring. The loop degrades into "inject, observe, score", which is still more than most tools give you.

MTTD and MTTR as first-class fields

The two numbers I wanted every experiment to produce are mean time to detect and mean time to recover. They fall straight out of the event timestamps:

MTTD = DetectedAt  - InjectedAt
MTTR = CompletedAt - DetectedAt

They are not computed at report time from logs. They live on the experiment's saga state as fields, written when the corresponding event arrives. That sounds like a small decision. It isn't. If MTTD is a derived value in a dashboard query, it is fragile: someone changes a label, the query silently returns nothing, and you discover it a quarter later. If it is a field on the aggregate, it is either there or it is visibly missing.

There is a subtlety here worth stating. MTTD in a chaos experiment measures your detection pipeline, not your service. If the anomaly detector is tuned badly, MTTD goes up while the service is fine. I consider that a feature. Your detection is part of your resilience, and it deserves a number.

Why a saga

An experiment is a long-running process with real state: it can be waiting for injection, waiting for detection, remediating, scoring, aborted. Events can arrive late, out of order or twice. Something has to own the answer to "where is this experiment right now?"

I used a MassTransit saga state machine for that. It correlates every event to the experiment by correlation id, holds the timestamps, and decides what is a valid transition. An AnomalyDetected for an experiment that is already completed is ignored, not acted on. A RemediationCompleted that arrives before the saga has recorded detection is a bug I want to see, not paper over.

The alternative I considered was choreography only: let each service react to events and reconstruct state from an event log when needed. It is simpler to start with. It is much harder to answer an operator's question at 3 a.m. With a saga, the state is one row, and its history is in the event store.

Delivery guarantees: outbox, retries, dead letters

A loop like this is only as trustworthy as its weakest delivery path. Three mechanisms carry most of the weight.

Transactional outbox. When the control plane records that a fault was injected, the database write and the FaultInjected publish must succeed or fail together. Otherwise you get the classic split brain: the fault is live in the cluster, but nobody downstream knows. The outbox writes the message into the same transaction as the state change, and a relay publishes it afterwards. I pay a little latency for that. I accept it.

Delayed redelivery. Transient failures are normal: the Kubernetes API is busy, Prometheus is slow, a downstream is restarting. Consumers retry with delayed redelivery at 1, 5 and 15 minutes. Immediate tight retries tend to hammer a system that is already struggling, which is a bad look for a chaos tool.

Dead letter queues. After retries are exhausted, a message goes to its _error queue. Nothing is dropped silently. An experiment stuck because a message is dead-lettered is visible, inspectable and replayable. Silent loss is the one failure mode I designed against hardest, because in this domain a lost "cleanup" message can mean a fault left running.

cfg.ReceiveEndpoint("scoring-anomaly-detected", e =>
{
    e.UseDelayedRedelivery(r => r.Intervals(
        TimeSpan.FromMinutes(1),
        TimeSpan.FromMinutes(5),
        TimeSpan.FromMinutes(15)));
    e.UseMessageRetry(r => r.Immediate(2));
    e.ConfigureConsumer<AnomalyDetectedConsumer>(ctx);
});

Why a modular monolith first

FaultMesh has five planes: Platform (tenants, auth, licensing), Control (experiments and fault providers), Observation (anomaly detection), Remediation and Scoring. On a whiteboard those look like five services. I did not start with five independently deployed systems.

Each bounded context is built the same way: Core, then Infrastructure, then an API layer (Carter, MediatR, FluentValidation), then a Worker for background processing. Contexts talk to each other only through integration events and published contracts, never through each other's tables. They sit behind a YARP gateway, so the external surface is already one API.

That gives me the seams of microservices without paying for all of their operational cost on day one. The seams are what matter. If the observation plane later needs to scale independently, because anomaly detection is CPU-heavy and the control plane is not, it can be split out without rewriting how it communicates. It already speaks only in events.

The trade-off is discipline. A modular monolith only stays modular if nobody takes a shortcut into another module's data. Architecture tests that enforce layer and dependency rules are part of that; so is code review. I would rather enforce boundaries in a monolith than discover in production that my "microservices" share a database anyway.

What this design does not solve

Closing the loop does not make an experiment safe. Safety is a separate concern: blast radius limits, abort conditions, approval for production, a kill switch. Some of those were still in progress in August 2026, and I will write about them separately. A closed loop with weak guardrails is a faster way to cause an incident.

It also does not make the scores meaningful by itself. A score is only as good as the SLIs and detection it is built on. The loop gives you consistent measurement. Whether you measure the right things is still a judgement call.

The takeaway

If I had to compress this into one sentence: a chaos experiment that does not measure detection and recovery is a demo, not an experiment.

The architecture follows from that. Events, because each stage should be replaceable. A saga, because someone has to own the state. An outbox and dead letters, because losing a message in this domain has real consequences. A modular monolith, because I wanted clean boundaries before I wanted more deployables.

FaultMesh is a personal product under active development. You can see where it is going at faultmesh.com.