DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Where the Model Stops and the Code Starts: Lessons From an AI Procurement Agent
  • Crash-Proof Agents: Durable Execution for Long-Running AI Systems
  • Deny by Default: Policy-as-Code Guardrails for Agents That Act
  • 7 Failure Modes Every Production AI Agent Should Be Tested Against

Trending

  • How (and Why) to Build Dynamic Data Pipelines
  • Introducing TypeSafe Jev: Typed Judgments as Programming Primitives
  • An Overview of Data Pipeline Architecture
  • Every Generation Fears the Machine. How Does the AI Job Panic End?

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Testing Asynchronous Systems, Part 1: Mapping the System and Classifying Its Asynchrony

Testing Asynchronous Systems, Part 1: Mapping the System and Classifying Its Asynchrony

Learn how to design tests for distributed asynchronous systems by mapping components, classifying timing models, and identifying testing requirements.

By 
Stelios Manioudakis
DZone Core CORE ·
Dec. 01, 26 · Analysis
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
573 Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Ask ten QA engineers what it means to "test an async system," and you will get ten different answers. Most answers are incomplete in the same way: mock the queue, add a retry, assert eventual consistency with a sleep-and-poll loop, ship it. This works until it does not, usually in production, usually under load, and usually in a way that is expensive to diagnose. And that's because the failure was never reproduced in a controlled environment.

The problem is not a lack of effort. It is a lack of a model. You cannot design a comprehensive test strategy for a distributed, asynchronous system without first answering three questions, in order: 

  • What components and networks are actually involved? Not the logical architecture diagram, but the real one, including the queue, the load balancer, the connection pool, the DNS layer, and every hop a message takes.
  • How asynchronous is the system? Is it synchronous with tight SLAs and occasional hiccups, or genuinely asynchronous with no meaningful timing guarantees at all? These need entirely different test strategies.
  • What failure modes are structurally possible at each layer? Not "what has broken in production before" but what can break, given the components and the degree of asynchrony you just established.

Most test plans skip the first two questions and jump to failure scenarios taken from incident postmortems. That produces a suite that is reactive and incomplete: you are testing the failures you have already witnessed, not the failures your architecture makes possible.

This article builds the framework in that order. Part 1 (this part) maps the system and classifies its asynchrony through three concrete scenarios. Part 2 enumerates the failure space. Part 3 looks at what a message can actually promise and what observability testing needs. A fundamental checklist is provided that you can lift into a test plan. Part 4 wraps up into a technique-by-level test strategy.

Mapping the System Under Test

A distributed system is a set of concurrent components that communicate by sending and receiving messages over a network. Each component owns its local state exclusively; no component can directly observe another's state. The network has state too: messages in flight, buffers, retries.

Components, Network, and Local State

This has an important practical consequence: you cannot write a correct test for a distributed interaction by reasoning about one component's code. A unit test that mocks the network as a reliable, instantaneous pipe is not testing the distributed behavior. It is testing the sequential logic that happens to run on top of it. Both kinds of test are necessary; neither is sufficient alone.

Before writing a single async test, produce an inventory:

  • Components. Every service, process, thread pool, or actor that independently executes steps. A single service with an internal job queue is itself a distributed system with two components (the request handler and the worker) and a network (the queue).
  • Networks. HTTP calls, gRPC streams, Kafka topics, Redis pub/sub, an in-memory event bus, a database replication stream. Each is a distinct network with different loss, duplication, and reordering characteristics, and each must be modeled separately.
  • Local state ownership. What does each component hold that nothing else can see directly? This tells you where race conditions are even possible and where component-level isolation is needed in tests.

Choosing Your Unit of Composition

Components are rarely atomic. A "payment service" is usually a composition: an API layer, a queue consumer, a database, maybe a cache. Whether you treat it as one black box or as four interacting parts is a modeling choice, not a fact about the system, and it determines testing boundaries.

A practical rule: pick the coarsest grain that still lets you inject the specific failure you are testing for. To test "what happens when the payment service is unreachable", treat it as atomic and inject faults at its network boundary. To test "what happens when the payment service crashes between debiting and confirming", you need the white-box view.

The Running Example

One scenario recurs throughout the article: an order-processing pipeline. A client places an order through an API gateway, which publishes an OrderPlaced event to Kafka. An inventory service consumes it and reserves stock, publishing StockReserved. A payment service consumes that and charges the customer's card, publishing PaymentCompleted. A notification service consumes that and sends a confirmation email. It is four components, several networks, and a lot of ways to go wrong. The next section shows how this pipeline behaves according to three different system models depending on where you draw its boundary.

How Asynchronous Is the System? Three Scenarios

Not every part of a distributed system is asynchronous to the same degree. Conflating them is one of the most common mistakes in async test design. The theory offers a useful vocabulary:

  • Synchronous. Components share a clock (or one with a known maximum deviation), and messages arrive within a known bound. A missing message means a failure, with certainty. A timeout is a reliable witness.
  • Asynchronous, no notion of time. No component has any clock, and events take arbitrary time. Timeouts cannot be used at all. This is mostly a theoretical model, but it is a description of interactions with no timing contract whatsoever.
  • Asynchronous, weak notion of time. Components have local clocks that are not synchronized and have unknown deviation. Events take arbitrary time. Timeouts can be set, but a timeout firing means only "nothing arrived in my window", not "something failed".
  • Partially synchronous. Synchronous most of the time and asynchronous some of the time. This is a popular model for production systems.

Purely synchronous systems do not exist in practice, so the interesting testing problems live in the other three. The same order pipeline falls into each of them, depending on the deployment and integration context. For each scenario below, we do four things: First, we describe the setup. Second, we classify its timing characteristics precisely. Third, we walk through some basic edge cases that follow from that classification. Finally, we note the testing implications that Part 4 lays out level by level.

Each diagram uses a consistent visual language. Teal marks the core region (scenario 1), purple marks the multi-region and mobile edge (scenario 2), coral marks the partner batch integration (scenario 3), gray marks neutral components, and amber marks the timing hazard specific to that scenario. Solid arrows are normal calls or messages; dashed arrows are links with no timing guarantee.

Scenario 1: Partially Synchronous, the Pipeline Inside One Cloud Region

The whole pipeline runs inside a single AWS region and VPC: an API gateway, a Kafka cluster, and inventory, payment, and notification services, spread across availability zones with autoscaling and NTP-synchronized clocks. The client talks to the gateway synchronously. Everything after that is asynchronous over Kafka: the gateway publishes OrderPlaced; inventory consumes it and publishes StockReserved; payment consumes that and publishes PaymentCompleted; notification consumes that and sends the email. The double-headed arrows in the diagram mark services that both consume and publish.

Scenario 1

Figure 1. Scenario 1: the full order pipeline inside a single region. Timing is well-behaved almost all the time.


Classification

Mostly synchronous. The p99 gRPC latency is well bounded (say, under 200 ms). Consumer lag is usually sub-second, and clock skew is in the tens of milliseconds. But it periodically and unpredictably degrades: garbage-collection pauses, autoscaling events, one availability zone having a bad five minutes, a noisy neighbor stealing CPU. It is synchronous almost all the time and asynchronous-like at unpredictable moments. Those unpredictable moments matter disproportionately because happy-path tests never visit them.

Edge Cases and Difficulties

  • The timeout-tuning tension. Too tight, and legitimate load spikes are misclassified as failures, triggering retries that add load to an already stressed system. Too loose, and real failures take too long to detect, holding connections and threads open. There is no universally correct value. It must be derived from the actual latency distribution of the dependency, not chosen as a round number.
  • Retry storms. Because the system is usually fast, clients are not designed for widespread simultaneous slowness. When a real degradation hits, many clients cross their timeout at about the same moment and retry at about the same moment, a thundering herd that arrives exactly when the system can least absorb it. This failure mode requires concurrent load and partial degradation together; neither alone produces it.
  • Partial, localized degradation. One AZ slow while the others are fine disappears in an aggregate p99 metric across the fleet. Tests that assert on aggregate SLAs miss it entirely.
  • Momentary asynchrony from pauses. A stop-the-world GC pause turns a normally synchronous call into something that briefly behaves like the weak-time model below: the caller genuinely cannot distinguish "slow" from "dead" during that window, even though this pair of components behaves synchronously 99.9% of the time.
  • Small but nonzero clock skew. It is precisely during the stressful moments above, when skew-sensitive ordering logic is exercised under contention, that a "small" skew stops being negligible.

What This Means for Testing

Because timeouts are meaningful here, the central testing questions are whether they are calibrated and whether the system stays stable when load and degradation arrive together. Cheap, deterministic tests can check the boundary logic of timeouts and retries. Whether retry storms and cascades appear can be answered at the system level, with realistic load and partial degradation combined. Calibration has to be re-validated in production, because the latency distribution drifts.

Scenario 2: Asynchronous With a Weak Notion of Time, Multiple Regions and Offline Mobile Clients

The same pipeline now runs in three regions. Each region has its own gateway, Kafka cluster, and core services, and each holds its own replica of order and inventory state. Regions replicate to one another asynchronously. The customer-facing client is a mobile app that lets someone add items and place an order while offline: actions queue on the device and sync whenever connectivity returns, which could be seconds later or, for a traveler in airplane mode, most of a day later. The app connects to the nearest region over a link that can drop at any time.

Scenario 2

Figure 2. Scenario 2: three regions running the full pipeline, replicating asynchronously, with an offline-capable mobile client.


Classification

Every component has some local clock (the phone and each region's NTP-synchronized servers). However,  nothing is meaningfully synchronized across the boundary between a phone and the backend, or reliably across regions during a partition. Delays are arbitrary. This is the weak-notion-of-time model as defined: a component can still set a local timeout and treat it as "suspiciously long". It has no basis for trusting a timestamp that crossed a component boundary. The difference from scenario 1 is not "slower". It is "no shared basis for time", which changes which techniques are even valid.

Edge Cases and Difficulties

  • Client timestamps cannot be trusted for cross-user ordering. A phone with the wrong timezone or auto-time-sync disabled attaches a timestamp that does not reflect true causal order. A naive "last write wins by timestamp" resolution silently picks the wrong winner whenever a device clock is wrong. At mobile scale, wrong device clocks are routine.
  • Sync-on-reconnect manufactures reordering and duplication by design. The client does not reliably know which queued actions synced before the connection dropped, so it must be prepared to resend. The server-side handlers must treat duplicate and out-of-order delivery as the normal case, not an edge case.
  • "Failed" and "delayed" are indistinguishable from the client's perspective. When connectivity itself is arbitrary, deciding when to show the user an error is a product decision in technical clothing. If it is not explicitly designed and tested as a UX decision, it defaults to whatever an arbitrary client-side timeout produces.
  • Replication lag is unbounded under partition. This produces the classic "I just placed the order, and it's gone" bug: a read served by a region that has not caught up appears to contradict something the user just did through another region.
  • Correct ordering requires logical, not physical, clocks. Establishing happened-before relationships (with vector clocks, CRDTs, or similar) becomes necessary. Testing "did we establish the correct causal order" is a fundamentally different exercise from testing "did we respond within N milliseconds".

What This Means for Testing 

Here the emphasis shifts. Correctness depends on logical ordering and idempotent replay rather than on clocks. Ordering and merge logic deserve exhaustive exploration instead of hand-picked examples. Clocks need to be deliberately wrong in tests, disconnections need to be long and open-ended, and replication lag and reconciliation conflicts need continuous measurement in production.

Scenario 3: Asynchronous With No Notion of Time, Batch Integration With an External Partner

Inventory fulfillment is now delegated to an external wholesale distribution partner. Inside your system, the pipeline is unchanged, but an adapter service consumes fulfillment events from Kafka and writes a batch order file to an outbound SFTP folder. The partner's batch job picks the file up whenever it happens to run. This could be minutes or several days later, and eventually may drop a response file in an inbound folder, or may not. There is no heartbeat, no shared clock, and no acknowledgment protocol beyond "a response file shows up, or it does not". A reconciliation job periodically compares what was sent with what was acknowledged.

Scenario 3Figure 3. Scenario 3: the pipeline extended with a batch file exchange to an external partner, protected by a reconciliation job.


Classification

No usable timing signal at all. Any timeout you configure here is not a technical failure-detection mechanism. It is a business policy about how long you are willing to wait before escalating. Confusing the two is the central risk when testing this category of system.

Edge Cases and Difficulties

  • Timeouts cannot serve as failure detectors in the formal sense. A test asserting "if no response file arrives within X hours the system is broken" verifies a business escalation policy, not a technical correctness property. Writing it as if it were the latter produces tests that are correct in form and wrong in what they claim to verify.
  • Four different failure states look identical from your side. The file was never picked up; the partner processed it, and a response is in transit; the partner processed it and silently rejected it; or the partner's batch job itself crashed. All four present as "no response file has appeared", and you cannot tell them apart without an out-of-band signal such as a phone call or a partner-side dashboard.
  • Message identity is the only tool you have. With no timing signal, correctness has to be established entirely through content: unique batch and transaction IDs, checksums, and periodic reconciliation, rather than through any live handshake.
  • The recovery path is often human-mediated. Someone emails the partner. The "system" under test therefore includes a human process step. The test strategy must mark where automated coverage stops and runbook verification begins instead of pretending the whole process is automatable.
  • Reconciliation is the real correctness surface. It is not any single request and response, but the periodic comparison of what was sent against what was acknowledged, flagging discrepancies. That is closer to testing a batch ETL or audit job than a live API, and must be tested as one.

What This Means for Testing

Because no timeout can serve as a failure detector, testing here centers on the file contract (including malformed, duplicate, and missing files), on the reconciliation logic, and on ongoing monitoring in production. Much of it is a permanent operational activity rather than a pre-release one.

How the Three Scenarios Compose into One System

The three scenarios are not three different systems. They are three regimes that one real system passes through. Interesting bugs live at the boundaries between them. Consider a single order. It is placed on a phone with no signal (scenario 2), queued locally, and synced to the nearest region when connectivity returns. Inside that region, it flows through the gateway, Kafka, and core services with partially synchronous timing (scenario 1). The fulfillment step then leaves your infrastructure entirely, through an adapter and a file drop, and completes whenever the partner's batch job gets to it (scenario 3).

Figure 4. The three regimes composed into one end-to-end order flow. Each boundary between zones is a place where the timing model changes.


This composition has three practical consequences for test design.

  • The end-to-end guarantee is only as strong as its weakest regime. The latency you can promise the customer is set by the scenario 3 segment, not by the fast core. The product must expose a "pending" state. Tests must verify that the pending state is reachable, stable, and correctly resolved by the reconciliation path.
  • Every boundary needs its own contract test. The handoff from device to region (idempotent replay of queued actions), from Kafka to the adapter (exactly-once processing semantics on the file write), and from partner response back to the pipeline (reconciliation and dedupe) are each a place where the model changes and the assertions must change with it.
  • A single end-to-end test cannot cover the whole path. An end-to-end test that waits synchronously for "order confirmed" is a valid test of scenario 1 only. Across the full path, use a correlation ID propagated through every hop, assert on intermediate observable states, and accept that the terminal state can only be verified by the reconciliation mechanism, not by waiting.



3.5 Summary of the three scenarios


Scenario 1: Partially synchronous

Scenario 2: Async, weak time

Scenario 3: Async, no time

Setting

Single-region microservices

Multi-region plus offline mobile

Batch or EDI partner integration

Is a timeout a valid failure signal?

Yes, if calibrated to the real latency distribution

Locally usable, untrustworthy across boundaries

No; any timeout is a business escalation policy

Primary correctness tool

Calibrated timeouts and circuit breakers

Logical or vector clocks, conflict resolution

Message identity and periodic reconciliation

Hardest bug class

Retry storms and cascading failure under load plus degradation

Silent misordering from untrusted clocks

Indistinguishable failure states with no out-of-band signal


Wrapping Up

A test strategy starts from a map: the components, the networks between them, and who owns which state, drawn at the coarsest grain that still lets you inject the fault you care about. 

This part mapped the system and classified three regimes it can fall into: partially synchronous, asynchronous with a weak notion of time, and asynchronous with no notion of time at all. That classification is the lens for everything that follows. How asynchronous a connection is determines which tests are valid. In the partially synchronous core region, calibrated timeouts are legitimate. Interesting bugs can appear when load and degradation arrive together. With a weak notion of time, client timestamps cannot be trusted, so we need logical ordering and idempotent replay. With no notion of time, a timeout is a business policy rather than a failure detector. Message identity and reconciliation are useful here. In practice, systems pass through all three regimes, so every boundary needs its own contract tests. No single end-to-end test covers the whole path.

Part 2 picks up directly from here: it takes the components and networks mapped above and walks through the full taxonomy of what can actually fail in each of them. Component by component and network hop by network hop, it then looks at how to test failure detection and mitigation as properties in their own right.

System under test systems

Opinions expressed by DZone contributors are their own.

Related

  • Where the Model Stops and the Code Starts: Lessons From an AI Procurement Agent
  • Crash-Proof Agents: Durable Execution for Long-Running AI Systems
  • Deny by Default: Policy-as-Code Guardrails for Agents That Act
  • 7 Failure Modes Every Production AI Agent Should Be Tested Against

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook