Testing Asynchronous Systems, Part 2: A Taxonomy of Failure, Detection, and Mitigation
With the system mapped and its asynchrony classified, this part works through everything that can actually fail, and how to test for detecting and recovering from it.
Having mapped the system and classified its asynchrony, it's time to move on to the failures that we can expect, their detection, and mitigation. This is the technical core of the article. Ideally, a comprehensive test suite walks every cell of the taxonomy below for every component and network pair in the system map, rather than enumerating failures ad hoc.
Safety and Liveness: The Two Properties Behind Everything That Follows
The notion of the correct software is notoriously fuzzy: obviously, a system is correct if it does what it is supposed to do. However, this gives no objective criteria for determining whether a system is correct. We need to be able to think rigorously about the system’s guarantees, capabilities, and limitations. We will focus on liveness and safety as described by Leslie Lamport.
Every failure in this part matters for one of two reasons: it can make the system do something it must never do, or it can stop the system from doing something it must eventually do. Distributed systems theory gives these two ideas names, and the rest of this part leans on them. It is worth fixing them with simple examples before the taxonomy begins.
A safety property says that something bad never happens. A liveness property says that something good eventually happens. The two are independent: a system can satisfy one and violate the other.
| example | safety: Something bad never happens | Liveness: something good eventually happens |
|---|---|---|
|
Traffic light at a crossing |
The lights never show green in both directions at once. |
Every direction eventually gets a green. |
|
Elevator |
The doors never open while the cabin is between floors. |
Every pressed call button is eventually answered. |
|
Order pipeline |
A customer's card is never charged twice for one order, and never charged without the stock being reserved. |
Every order eventually ends up confirmed or cancelled. |
You need both, because each is trivially satisfied by giving up the other. A traffic light stuck on red in every direction is perfectly safe, and useless. An elevator that moves the moment any button is pressed, doors or no doors, is as responsive as it gets, and dangerous. A pipeline that rejects every order never double-charges anyone; a pipeline that retries blindly until something succeeds makes progress and sometimes charges a card twice. Ideally, we want to build systems where every possible system behavior satisfies both properties.
Why the Distinction Matters for Testing
The two properties are tested in different ways, and confusing them is a common problem. A safety violation can be caught in a finite observation: at some specific moment, two charges exist for one order, and an assertion or invariant check can point at it. Safety tests therefore tend to be exact, and they can run continuously alongside any other test as an invariant.
A liveness violation cannot be caught that way. "Eventually" has no deadline, so no finite observation can prove that the good thing will never happen; the system may simply be slow. In practice, a liveness test is always a bounded approximation, such as "the order is confirmed within 30 seconds." The three regimes from Part 1 show how this plays out. In the partially synchronous core, a calibrated bound is meaningful. With a weak notion of time, it is only a suspicion. With no notion of time, it is a business policy about when to escalate to a human, which is why that regime relies on reconciliation rather than on waiting.
How Failure Forces a Choice
When a failure hits, a system often cannot keep both properties. It can keep safety and give up liveness by stopping rather than risk a mistake. It can keep liveness and give up safety by carrying on and accepting that it may misbehave for a while. Or, at the best and most expensive end, it can hide the failure entirely and keep both. Section 2.3 names these three outcomes (fail-safe, nonmasking, and masking) and explains how to write assertions that match the contract a component actually provides. Section 2 also uses the two properties as its organizing lens: failure detection is what protects safety, because a system that notices trouble can stop doing dangerous things. Failure mitigation is what restores liveness, because it lets the system resume making progress.
Failure Modes
1. Component Failure Modes
Crash stop, omission, and crash recovery will be covered here. Byzantine failures are not covered but are only mentioned in the table below for completeness.
| failure type | description | test implication |
|---|---|---|
|
Crash-Stop |
The component halts permanently and performs no further steps. |
The simplest to test: kill the process and verify that the rest of the system degrades or routes around it correctly. |
|
Omission |
The component pauses for an arbitrary duration, then resumes exactly where it left off with no state lost. |
Test with process suspension (SIGSTOP and SIGCONT, or docker pause), not process kill. It is a meaningfully different failure and is often untested. |
|
Crash-Recovery |
The component pauses, resumes, and may have lost some volatile state while keeping durable state. |
Kill and restart with a controlled subset of state wiped, for example an in-memory cache cleared while the disk volume is intact. This is where "did we persist what we thought we persisted" bugs live. |
|
Byzantine |
The component behaves arbitrarily, including sending contradictory or deceptive messages to different peers. |
Relevant only where not every participant is trusted (e.g., cryptocurrency). |
To test for component failures, we could use, for example, fault injection. Stopping, suspending, and restarting components, or exhausting their resources, shows how the rest of the system reacts. Component tests against real dependencies show whether durable state really survives a restart. Transactional-integrity tests check that a write and the message announcing it cannot be separated by a crash. State-transition tests check that a recovering component does not accept events its state machine should refuse. Recovery and failover testing measures how long recovery takes and what, if anything, is lost. Part 4 maps each of these to the level where it is cheapest.
2. Network Failure Modes
- Message loss: the network does not deliver.
- Message duplication: the network delivers more than once.
- Message reordering: the network delivers out of order.
A network that exhibits any of these is an unreliable network. An unreliable network is the default assumption for everything except same-process function calls. The model assumes the network does not lie: if it delivers a message, some component in the system really sent it.
The three network failures map naturally to families of tests. Duplication is addressed by idempotence and duplicate-delivery tests, which feed the same message to a handler several times. Reordering is addressed by permutation tests, which feed a short event sequence in every order, and by property-based tests, which generate far more orderings than anyone would write by hand. Loss is addressed by reconciliation checks, which compare what was sent with what was acknowledged, and by tests of the retry behavior around it. Network-level fault injection, which adds latency, drops, duplicates, and reorders traffic between components, then confirms in a running system that these defenses hold. Contract tests complement all of this by checking that both sides agree on what a message means in the first place. For more details, the section on examples for message handlers (Part 3, section 1.6) could be useful.
3. Spatial and Temporal Classification
Spatial: application-level versus platform-level. A failure is application-level if the application layer is the lowest layer that can meaningfully interpret and resolve it (for example, InsufficientFunds). It is platform-level if a lower layer can and should resolve it (for example, CouldNotConnect, resolved by reconnecting). This is the end-to-end argument: handle a failure at the lowest layer that can handle it correctly and completely. It also tells you where the corresponding test belongs:
- Application-level failures are tested with business-logic-level cases: does the checkout flow correctly reject and compensate on InsufficientFunds?
- Platform-level failures are tested with infrastructure-level fault injection: does the HTTP client retry correctly on connection failure, with correct backoff? This usually uses the network tooling above rather than application fixtures.
Temporal: transient, intermittent, permanent. These differ by whether a first failure makes a second one more likely, and by how they are repaired.
- Transient: no elevated recurrence probability, self-repairing quickly (a single dropped packet). Test with single-shot fault injection: fail once, verify that an immediate retry succeeds.
- Intermittent: elevated recurrence probability, self-repairing but after some delay (a flapping link, a stale routing table). Test with repeated, clustered fault injection over a sustained window. A single-shot test will never surface an intermittent failure mode, which is why soak testing and scheduled chaos matter.
- Permanent: certain recurrence, requires manual repair (an expired certificate). This is effectively an integration test with the dependency held down for the whole test: verify that the system escalates to fail-safe behavior and alerting rather than retrying forever.
Pairing with load. Recurring fault injection ("cut connectivity for 10 seconds every 2 minutes for an hour") is what intermittent failure simulation needs. It should be combined with concurrent load, because intermittent failures may only manifest under load (connection pool starvation, resource exhaustion). So the combination is usually necessary rather than optional.
4. Which Failures Dominate in Which Scenario
The taxonomy applies everywhere, but its cells are not equally important in every regime. Use this table to prioritize the first pass of a test plan.
| failure | Scenario 1: partially synchronous | Scenario 2: async, weak time | Scenario 3: async, no time |
|---|---|---|---|
|
Crash-Stop, Crash-Recovery |
High: autoscaling and rolling deploys are constant |
Medium: mostly device app kills and region outages |
Medium: the partner's batch job can crash silently |
|
Omission (pauses) |
High: GC and scheduler pauses are the main source of false failure detection |
Medium |
Low: pauses are lost in the noise of arbitrary delay |
|
Message loss |
Low to medium: broker-level durability usually covers it |
High: sync-on-reconnect and flaky links |
High: files never picked up or never returned |
|
Message duplication |
Medium: at-least-once consumers and retries |
Very high: resend-on-reconnect is by design |
High: repeated file drops and re-sent batches |
|
Message reordering |
Low within a partition; higher across partitions |
Very high: offline queues and multi-region replication |
Medium: response files can arrive out of order |
|
Clock skew and drift |
Medium: small but relevant under contention |
Very high: device clocks are untrusted |
Not applicable: no shared clock is assumed at all |
|
Transient versus permanent |
Mostly transient and intermittent |
All three, with long intermittent partitions |
Mostly permanent or human-repaired |
Detection and Mitigation as Testable Properties
Failure handling splits cleanly into two mechanisms that should be tested separately: detection (recognizing that a failure occurred) and mitigation (recovering from it). Detection is fundamentally about preserving safety: once you suspect trouble, stop doing anything dangerous. Mitigation is about restoring liveness: resume making progress once the trouble is over or has been worked around.
1. Testing Detection
Detection mechanisms follow two patterns. In a pull design, the observer polls the observed component and expects a timely answer. In a push design, the observed component emits heartbeats at a set frequency. In both, the failure witness is a timeout. A point worth internalizing, and worth communicating to stakeholders who file bugs against "flaky" tests: in a partially synchronous or asynchronous system over an unreliable network, no failure detector can be both complete (catches every real failure) and accurate (never flags a non-failure). The obstacle is structural, not an engineering gap. The detector simply cannot tell "delayed" from "lost." Practically, that means:
- Detection tests should verify tuned behavior (does the timeout or heartbeat interval match your actual SLA and network characteristics?), not perfect behavior.
- Some of the flakiness in async test suites accurately reflects this impossibility and is not evidence that the tests or the system are broken. The fix is often to make the detector's trade-off intentional and documented, not to try to eliminate all false positives.
- Ask who supervises the supervisor. Every detector is itself a component that can fail. Somewhere the chain ends in human intervention, and that hand-off should be tested too (does the alert actually fire, does the on-call runbook work?).
The thresholds of a circuit breaker or health check are testable units. Boundary-value tests with controlled time assert that the circuit opens and closes exactly at the configured thresholds. They are also kept separate from integration tests that verify end-to-end behavior once it does. Mutation testing, which deliberately breaks the comparison operators and counters in that logic, shows whether those tests would notice a regression. Alerting rules are testable too, against synthetic data, so that the hand-off to a human is checked as well.
2. Testing Mitigation
Mitigation is either backward recovery (return to a state equivalent to the initial one, via compensation) or forward recovery (push through to a state equivalent to completion, via retries). Test each explicitly:
- Backward recovery and compensation tests. Inject a failure partway through a multi-step process and assert that compensating actions (refund, release reservation) run correctly. Compensations can fail too, so they must themselves be idempotent and retriable. There must be an escalation path to a human when they cannot complete (the refund that fails is the classic example).
- Forward recovery and retry tests. Verify retry count and backoff strategy: immediate retry for an assumed transient failure, backoff and retry for an assumed intermittent one, suspend and alert for an assumed permanent one. Critically, verify that a retry does not cause duplicate side effects when the first attempt actually succeeded, but its response was lost.
Service virtualization, in which a dependency is scripted to fail N times and then succeed, is the cleanest way to test retry and backoff logic deterministically without depending on real network chaos. Component tests against real dependencies (a real broker, a real database) then close the gap between "my retry logic is unit tested" and "my retry logic works against the real client library's real failure modes."
3. Masking, Nonmasking, and Fail-Safe as a Test-Design Lens
Before writing a test against a component under fault injection, decide which of the three failure-tolerance types the component is designed to provide, and write assertions that match that contract.
| safety held | safety not held | |
|---|---|---|
|
Liveness held |
Masking: the failure is fully hidden. Assert normal behavior even during fault injection. |
Nonmasking: progress continues but may misbehave. Assert eventual correctness, not correctness during the fault window. |
|
Liveness not held |
Fail-safe: assert that the system halts or rejects rather than risking a bad state. |
Not failure tolerant. Generally unacceptable. |
The classic example is a FIFO queue. A masking queue keeps delivering in order despite the fault. A nonmasking queue keeps delivering but may reorder during the fault. A fail-safe queue stops delivering rather than risk reordering. Asserting "no errors, ever" is an unstated masking assumption that most real components do not provide, and it can keep your suite perpetually and legitimately red.
Wrapping Up
This part explained liveness and safety in software. It enumerated what can fail, at the component level and the network level. It showed how to test detection and mitigation as separate, independently verifiable properties. Part 3 turns to the messages themselves: what delivery and processing guarantees are actually achievable, how to test idempotence as its own contract, and how to turn all three parts of this series into an observability setup and a checklist you can use directly in a test plan.
Opinions expressed by DZone contributors are their own.