When Event-Driven Architecture Pays Off
Engineering

When Event-Driven Architecture Pays Off

A decision table for each service link, an event design checklist, and the outbox, idempotency and saga patterns that stop asynchronous work from losing or repeating an order.

Short answer

Event-driven architecture pays off when several independent consumers must react to the same business fact and the caller does not need their results to continue: notifications, invoicing, analytics, stock updates. Keep a direct request wherever the caller needs an immediate answer, such as payment authorisation, or where services must agree at the same moment. Adopt events only if you will also build an outbox, idempotent consumers, replay and dead-letter handling.

What is event-driven architecture, and when does it pay off?

Event-driven architecture pays off when several independent parts of a system need to react to the same business fact and the person who triggered it does not have to wait for all of them. In this style, a producer publishes an event such as "order placed", a channel carries it, and any number of consumers act on it without the producer knowing who they are. Microsoft's architecture guide lists where it fits: several subsystems processing the same events, real-time processing with little lag, pattern matching over time windows, high-volume data such as IoT, and producers and consumers that need to scale and fail independently.

The same guide is just as clear about where it does not fit: simple request-response flows where synchronous calls already meet latency and throughput needs, business transactions that need strong consistency across services, and teams with no experience operating asynchronous systems. That last point is easy to underestimate. Events replace one visible call chain with many small, independent reactions. Martin Fowler's overview of event-driven patterns warns that a flow built from event notifications can be hard to see, because it is not written down in any one program. You gain decoupling and pay for it in consistency, ordering, duplicate handling and tracing. Make the decision link by link, not for the whole system at once.

Request or event: how do you decide for each link?

Ask first whether the caller needs the outcome before it can continue; if it does, keep a direct request. Then work through the remaining questions for every interaction between two services. Most systems end up with both styles, and that is a sign of deliberate design rather than inconsistency.

QuestionPoints to a direct requestPoints to an event
Does the caller need the result to continue?Yes: payment authorisation, credit check before confirmingNo: receipt email, loyalty points, reporting
How many parties react?One known receiverSeveral, and more are expected later
Must every party agree at the same moment?Yes: account balance, seat allocationA visible delay of seconds or minutes is acceptable
Will anyone need to replay history?NoYes: a new consumer catches up, or data is reprocessed after a bug fix
What does the load look like?Steady, and the receiver keeps upBursts the receiver cannot absorb directly
Can the team operate it?No procedure for retries, dead letters or replayOn-call, monitoring and reprocessing procedures exist

Read the table as a short decision tree:

  1. If the caller needs the result now, use a request. Messaging can imitate this with a request queue and a reply queue, but the dependency is still synchronous.
  2. If exactly one receiver will do the work later, a queued command ("reserve stock for order 123") is often enough; you do not need publish-subscribe.
  3. If several receivers react to the same fact, or new ones will appear, publish an event.
  4. If receivers must also see past events, choose an event stream rather than plain publish-subscribe. Microsoft's guide notes that publish-subscribe does not keep delivered events in a durable log, so new subscribers cannot see them, whereas a stream is durable, ordered within a partition and replayable.
  5. If the work spans several services and a later failure must undo earlier steps, design it as a saga, described below.

What should a well-designed event contain?

A good event records one business fact that has already happened and been committed, named in the past tense: OrderPlaced, InvoiceIssued, ShipmentDelayed. Avoid generic messages such as RecordUpdated whose meaning depends on private database columns; they turn your table structure into a public contract. Fowler also warns against events that are really "passive-aggressive commands": if the sender expects one particular receiver to act, send that receiver a command.

Decide how much data the event carries. Microsoft describes two approaches: put every attribute consumers need into the payload, or send only keys and let consumers fetch the rest. Full payloads spare consumers a lookup but multiply copies of the data and make versioning harder; key-only events keep one system of record but add load to it. For the envelope, the CloudEvents specification is a practical baseline. It requires id, source, specversion and type, says producers must keep source plus id unique for each distinct event, and lets consumers treat two events with the same pair as duplicates. Optional attributes such as time, subject and dataschema cover most of the rest.

For every event type, write down:

  • Owner: the team that publishes it and approves changes.
  • Key and ordering scope: for example, events for one order are ordered; events across orders are not.
  • Schema version: including what a consumer does with a version it does not recognise.
  • Retention: how far back events can be replayed.
  • Sensitive fields: events are often visible to many components, so leave out personal data a consumer does not need.
  • Correlation ID: so logs from every consumer can be joined into one trace.

How do you avoid losing or duplicating events?

Write the event into the same database transaction as the business change, publish it from there, and make every consumer safe to run twice. The first half solves the dual-write problem: if a service commits an order and crashes before publishing, the event is lost; if it publishes first and the commit fails, consumers react to an order that does not exist. The transactional outbox pattern stores the outgoing message in an outbox table inside the same transaction, and a separate relay sends it to the broker. Messages are then sent if and only if the transaction commits. The relay can still send a message twice if it crashes after publishing but before recording that it did, so the pattern assumes idempotent consumers.

The second half is not optional either. Microsoft's Idempotent Consumer pattern points out that most brokers, including Azure Service Bus, Event Hubs, Kafka and RabbitMQ, deliver at least once, and that exactly-once delivery across a distributed system is impractical. The consumer records a stable deduplication key, such as the CloudEvents source and id, in the same transaction as its side effect, and a uniqueness constraint decides which of two concurrent copies wins. Keep those records at least as long as the broker can redeliver, and longer if operators can resubmit messages from a dead-letter queue. Deduplication does not restore order: if a consumer depends on sequence, carry a version number and reject messages older than the state it already holds.

What happens when a step fails halfway through?

You undo the completed steps with compensating actions, because there is no single transaction to roll back across services. The saga pattern breaks the work into local transactions, each committed in its own service, and defines a compensating transaction for every step that may need reversing. It also names a pivot transaction: the point of no return, after which the remaining steps are retried until they succeed. A saga can be choreographed, with services reacting to each other's events, or orchestrated by a coordinator that holds the state. Microsoft's comparison is useful: choreography suits simple flows with few services but becomes hard to follow as steps are added, while orchestration handles complex flows and avoids cyclic dependencies at the cost of a component that must itself be reliable.

Compensation is a business decision, not a technical retry. If stock cannot be reserved, someone has to decide in advance whether the order waits, ships partially, or is cancelled with the payment released. Retrying the message will not make that decision. Compensating actions can fail as well, so give stuck sagas an owner and a queue for manual handling.

Hypothetical example: one order, four links

Consider a hypothetical B2B ordering portal. A customer places an order; payment is authorised, stock is reserved, an invoice is created, a confirmation email is sent and the sales dashboard is updated. Applying the table gives four different answers:

  • Payment authorisation stays a direct request. The customer cannot be told "order received" until the card or credit limit has been checked.
  • Stock reservation and invoicing react to an OrderPlaced event written through the outbox. An orchestrator tracks the saga: if reservation fails, it releases the payment authorisation and marks the order cancelled or back-ordered, following the rule the sales team agreed. Picking in the warehouse is the pivot; after it starts, steps are only retried.
  • The confirmation email consumes the same event. Its consumer stores the event key before sending, so a redelivered event does not trigger a second email.
  • The sales dashboard reads from the event stream and can be rebuilt by replay after a reporting bug is fixed.

Until the saga finishes, the customer sees "received, awaiting stock confirmation" rather than a premature "confirmed". The team sets an illustrative target, for instance that orders should leave the pending state within two minutes, and raises an alert for any order that stays longer. Because every event carries the same correlation ID, support can explain each order's timeline.

What should you test and monitor before go-live?

Test the failure cases that asynchronous systems create, not only the happy path:

  1. Deliver the same event twice; exactly one side effect must result.
  2. Deliver a cancellation before the matching creation; the consumer must park or reject it rather than corrupt state.
  3. Stop a consumer for an hour; afterwards the backlog must drain with nothing lost.
  4. Take the broker offline; the outbox must keep accumulating and the relay must resume cleanly.
  5. Replay a day of events into a rebuilt consumer; no customer may receive a second email or charge.
  6. Publish a new schema version; older consumers must ignore new fields, and unknown versions must go to a dead-letter queue instead of crashing the consumer.
  7. Make a compensation fail on purpose; the saga must land in a visible manual-handling queue.

In production, watch queue age or consumer lag, dead-letter counts, the time from event to business outcome, the rate of detected duplicates and the number of sagas stuck beyond their target. Give the dead-letter queue a named owner and a written reprocessing procedure.

Common mistakes

  • Moving a step the user must wait for onto a queue, then building polling screens to hide the delay.
  • Publishing events outside the database transaction and losing some of them during crashes.
  • Assuming the broker delivers exactly once and skipping deduplication.
  • Exposing raw table changes as the public event contract.
  • Adding correlation IDs and tracing after the first incident instead of in the first release.

Where should you start?

Pick one link where several consumers already poll the same data or wait for the same batch job, publish a single well-defined event through an outbox, and measure lag, duplicates and support questions for a month before converting the next link. If the underlying question is whether to split the application at all, read when to split a monolith first. To work through the decision table for your own system, you can book a free discovery call through our custom software development service.

Key takeaways

  • Decide per link: keep a direct request wherever the caller needs the result to continue.
  • Publish past-tense business facts with an owner, a unique source and ID, a schema version and a correlation ID.
  • Write events through an outbox and make every consumer idempotent, because brokers deliver at least once.
  • Agree each saga step's compensation as a business rule before go-live, including what happens after the pivot.
  • Test duplicates, out-of-order delivery, replay, broker outage and schema changes, and give the dead-letter queue an owner.

Frequently asked questions

Is event-driven architecture the same as microservices?

No. Microservices describe how a system is split into independently deployed services; event-driven architecture describes how the parts communicate. Microservices can call each other synchronously, and a single application can publish events internally. Many systems combine the two and use events only for links where several consumers react to the same fact.

What is the difference between an event and a command?

An event states that something has already happened, such as OrderPlaced, and the publisher does not know who reacts. A command asks a specific receiver to do something, such as ReserveStock. If the sender expects one particular action, send a command; disguising it as an event hides the dependency.

Does Kafka or another broker guarantee exactly-once processing?

Not end to end. Some brokers offer exactly-once semantics for operations they control, but they cannot control side effects in your consumer, such as database writes or emails. Assume at-least-once delivery and make consumers idempotent by recording a stable event key in the same transaction as the side effect.

What is the transactional outbox pattern?

It lets a service save data and publish an event without losing either. The service writes the event to an outbox table in the same database transaction as the business change, and a separate relay publishes it to the broker. Because the relay may publish twice after a crash, consumers still need deduplication.

When should a saga use orchestration instead of choreography?

Choreography is enough for short flows with few services, where each service's reaction to events is easy to follow. Choose orchestration when the flow has many steps, compensations or branches, because a coordinator holds the state and makes failures visible. The coordinator then has to be monitored and made reliable itself.

All articles