Event-Driven Architecture Pitfalls: Out-of-Order Events, Duplicates, and Poison Messages

Event-driven architecture pitfalls rarely announce themselves. A system can run fine for months, then a single delayed event reopens a cancelled order, a duplicate event charges a customer twice, or one malformed message stops an entire queue. These failures share a pattern: the happy path works, and the failure modes only show up under real traffic, retries, and partial outages. This guide covers the three most common ones, out-of-order events, duplicates, and poison messages, and the design habits that keep them from turning into incidents.

Why Event-Driven Systems Fail Quietly

When services talk through events instead of direct calls, no single service sees the whole picture. A producer publishes an event and moves on. A consumer processes it minutes later, or never, and the producer never finds out. That loose coupling is the point of the pattern, and it is also what makes failures hard to spot. Logs sit in different services, the order of events is invisible, and a bug in one consumer can stay hidden until a customer reports the result.

If you are still deciding whether this pattern fits your system, start with the event-driven architecture basics before you commit to it. The rest of this article assumes you already run events in production and want to stop the failures that follow.

Event-Driven Architecture Pitfalls: Out-of-Order Events

Out-of-order events are the most common of the event-driven architecture pitfalls, and the hardest to reproduce in testing. Events rarely arrive in the order they happened. A retry delays one event, a slow consumer processes another first, or two producers publish related events at nearly the same time. The result is a consumer that applies a stale state on top of a newer one.

Take an order that is placed, paid, then cancelled within a minute. If the cancellation event arrives before the payment event, a consumer that processes events in arrival order can mark the order as paid after it was cancelled. The customer sees a charge for an order that no longer exists, and support has to untangle it by hand.

Three fixes cover most cases. First, attach a sequence number or version to every event for an entity, and have consumers ignore events with a version older than the one already applied. Second, keep related events on the same partition or shard key, such as the order ID, so a single consumer processes them in order. Third, design consumers to handle late events explicitly instead of assuming arrival order matches real order. That last point matters most: ordering guarantees from a broker are a starting point, not a substitute for version checks in your consumer.

Your choice of broker shapes how much ordering help you get. Our guide to choosing a message queue compares the ordering and delivery guarantees of the common options, which is worth reading before you pick one for an ordering-sensitive workload.

Duplicate Events and Why At-Least-Once Delivery Hurts

Most message brokers deliver at least once, not exactly once. A consumer that crashes after processing an event but before acknowledging it will receive the same event again. A producer that retries a publish can send the same event twice. Duplicates are normal in event-driven systems, so consumers must treat them as expected input, not as a rare bug.

The damage depends on what the consumer does. Sending a second welcome email is embarrassing. Charging a card twice, incrementing stock twice, or creating two shipments is a real incident. The fix is idempotency: make processing the same event twice produce the same result as processing it once. Give every event a unique ID, store processed event IDs in a table with a short retention window, and skip events you have already seen. For side effects that cannot be undone, check the stored result before acting, so a retry returns the earlier outcome instead of repeating the action.

Idempotency keys belong in the event itself, not only in the consumer. When the producer generates the key from the business operation, such as the order ID plus the action, every retry carries the same key and every consumer can deduplicate on it. A random ID generated at publish time does not help, because a retried publish gets a new ID and looks like a new event.

Poison Messages That Stall a Whole Queue

A poison message is an event a consumer can never process: a payload that fails validation, a schema version the consumer does not understand, or a message that triggers a bug in the handler every time. Without a plan for these, the consumer retries the same message forever, blocks the messages behind it, and the queue grows while the rest of the system waits.

The standard answer is a dead letter queue. After a small number of retries with backoff, move the message to a dead letter queue and keep processing the rest. That sounds simple, but two details decide whether it works. First, someone has to watch the dead letter queue. A dead letter queue without an alert is a place where failed orders go to be forgotten, so alert on every new entry and review it daily. Second, you need a way to fix and replay the message. Store the original payload, the error, and the consumer version that failed, so a developer can correct the data or deploy a fix and reprocess it without guessing.

Poison messages also reveal a testing gap. If your test suite only covers well-formed events, the first malformed event in production becomes an incident. Feed your consumers bad payloads on purpose: missing fields, wrong types, unknown enum values, and events from a future schema version. A consumer that rejects bad input cleanly and moves on is far cheaper than one that crashes on it at 2 a.m. For the on-call side of that story, see our guide to handling errors in production.

Three Design Habits That Prevent Most Failures

No single tool fixes all three failure modes, but a few habits cover most of them:

  • Version every event and every consumer. Put a schema version in each event, and make consumers reject or handle versions they do not know instead of guessing at the fields.
  • Make handlers idempotent by default. Treat duplicate delivery as normal. Store processed event IDs, and check before performing side effects that cannot be undone.
  • Give every failure a visible home. Route poison messages to a dead letter queue, alert on it, and keep the payload and error together so replays are possible.
  • Trace events end to end. Carry a correlation ID from the first event through every consumer it triggers. When a customer reports a wrong result, you can follow one ID through the whole chain instead of searching each service separately. Our guide to debugging production issues covers the tooling that makes this practical.

These habits cost little when you adopt them early. Adding them to a system that already runs in production means touching every consumer, which is why teams that skip them keep paying for the same three incidents.

How to Test for These Failures Before Production

Unit tests will not catch these problems, because each failure comes from the interaction between producer, broker, and consumer. Test at that level instead. Publish the same event twice and confirm the consumer handles it once. Publish two related events out of order and confirm the final state is correct. Send a malformed event and confirm the consumer rejects it without blocking the queue. Kill a consumer mid-processing and confirm the retry does not double-apply the effect.

Run these checks in a staging environment that mirrors production closely enough to matter: the same broker settings, the same retry limits, and the same consumer count. A staging setup with one consumer and no retries hides the ordering and duplicate problems that production will find for you.

Out-of-order events, duplicates, and poison messages are not signs that event-driven architecture was the wrong choice. They are the known failure modes of the pattern, and every team running events in production meets them sooner or later. The teams that handle them well are not the ones with the fanciest broker. They are the ones that version their events, make handlers idempotent, and give failures a place to go where someone will actually see them.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.