Video in progress
In an event-driven system (Kafka, several consumer services), how do you test end-to-end correctness?
I test each service in isolation at its own boundary, protect the message format with Schema Registry compatibility and message contracts, and at the e2e level I follow a few main flows by correlation ID and wait for them to reach the "eventual" state. You can't try every combination in e2e.
📖 Answer
What's hard here: there's no request-response, the result appears in several services at different times, and ordering, duplicates and delays are the normal state of things.
The layers:
-
Inside a service. For each consumer: the right message → the right state; the same message twice → one result; out-of-order messages (
OrderCancelledbeforeOrderCreated) → the expected behavior; a corrupted message → the DLT. For the producer: transactional atomic publishing through the outbox. -
The format agreement. Avro/Protobuf/JSON Schema and
BACKWARDorFULLcompatibility in Schema Registry. In the producer's CI the new schema is checked against the registry: a change that breaks old consumers fails the build. For semantic agreements (for example, whetheramountis in tiyin or soum), message contract tests. -
E2E. A few business-critical flows, for example "payment → subscription activates → the author's share is calculated → email". The test starts the request with a unique correlation ID and waits for each stage with Awaitility. If you have tracing (OpenTelemetry), at the end of the test you can pull the trace and show exactly which stage it stopped at, which makes analyzing an e2e failure much cheaper.
-
Reconciliation in prod. In an asynchronous system some bugs only show up with time. A daily check job: "subscriptions that are paid but not activated", "a period closed without a payout". This is also a test, just over prod data.
What I don't do: wait for the whole cluster with sleep(30s) in every e2e test. A suite like that becomes slow and flaky within a month and gets switched off.
Sign up to mark studied questions and save your progress.