Event-driven architecture helps when one completed business fact should trigger independent work without making the original request wait. It adds risk when events become a vague substitute for clear ownership and synchronous contracts.
Most SaaS products reach a point where one action fans out into many side effects. An invoice is paid, and now the product must send a receipt, update usage limits, notify a CRM, refresh a dashboard, and call a customer’s webhook. Doing all of that inside the payment request makes it slow and fragile. Pushing all of it onto a message broker without design makes it invisible and hard to debug.
This article is how I decide where events belong in a SaaS product, how to design them so they do not lose work, and when to keep a plain function call instead.
What makes an event useful
A useful event is a past-tense business fact owned by one part of the system:
invoice.paidmember.invitedproject.archivedimport.completed
It describes something that has already happened and cannot be refused. Consumers react to it; they do not approve it.
“User service updated row 12” is not a useful event. It is an implementation detail that couples every consumer to the producer’s table structure. Commands disguised as events, such as send.welcome.email, are also a warning sign. If the producer is telling a specific consumer what to do, a direct call or a job is usually clearer.
A minimal event envelope:
| Field | Purpose |
|---|---|
id | Unique event identifier, used for idempotency |
type | The business fact, such as invoice.paid |
version | Schema version of the payload |
occurredAt | When the fact happened, in UTC |
tenantId | The owning account in a multi-tenant product |
subjectId | The record the fact is about |
correlationId | Links the event to the request that caused it |
data | The payload consumers need, and nothing internal |
Where events help
Events are a good fit when the initiating action should stay correct even if the follow-up work is delayed:
- Notifications. Emails, in-app messages, and chat integrations after a business action.
- Search and read models. Updating a search index, cache, or reporting table from source data.
- Analytics and audit. Recording that something happened without slowing the user path.
- Outbound webhooks. Delivering facts to customer systems with their own retry rules.
- Document generation. Invoices, exports, and reports produced after the fact.
- Cross-module workflows. One module reacting to another’s facts without importing its internals.
In each case, the event is a handoff between owners, not a hidden way to make required validation asynchronous. If the payment cannot be accepted without a fraud check, the fraud check belongs in the request path, not in a consumer that runs later.
Where events add risk
| Situation | Why events hurt | Better option |
|---|---|---|
| The caller needs an immediate answer | The user waits on eventual consistency or polls | Direct API or function call |
| Two changes must succeed or fail together | No shared transaction across consumers | Database transaction in one owner |
| A single team owns both sides | Indirection without independence | A plain function call inside the module |
| The flow has strict ordering across many steps | Ordering and partial failure become hard to reason about | An explicit workflow or state machine |
| No one owns retries and failures | Events disappear quietly | Do not add events until ownership exists |
The cost of events is not the broker. It is that the flow of control is no longer visible in the code. A reader cannot follow a function call from “invoice paid” to “receipt sent.” That is acceptable when the consumers are genuinely independent. It is expensive when they are steps in one business process.
Keep a single source of truth
The module or service that owns the business fact creates the event after its state change commits. Consumers own their own derived state and must be able to rebuild it by replaying events or re-reading the source.
Two rules keep this healthy:
- Consumers never reach back into the producer’s tables to reconstruct meaning. If they need more data, add it to the event or call the producer’s public API.
- The producer does not depend on consumers succeeding. If the receipt email fails, the invoice is still paid.
Publish events durably
The same gap that loses background jobs also loses events: the process commits the database change and crashes before it publishes. Use a transactional outbox. Write the state change and the event row in one transaction, then let a delivery worker publish from the outbox with retries.
flowchart LR
accTitle: Event publication through a transactional outbox
accDescr: A command handler writes business state and an outbox event in one transaction. A relay publishes events to a broker or queue, and independent consumers update their own state idempotently. Failed deliveries go to a dead-letter store that supports replay.
H["Command handler"] --> S[("Business state")]
H --> O[("Outbox")]
O --> R["Relay"]
R --> B["Broker or queue"]
B --> C1["Email consumer"]
B --> C2["Search consumer"]
B --> C3["Webhook consumer"]
C3 -->|"retries exhausted"| DL[("Dead letters")]
DL -.->|"replay"| B
You do not need a large broker to start. An outbox table plus a worker that calls in-process handlers, or a database-backed queue, covers many products for a long time. The design of background jobs that do not lose work applies directly to event delivery.
Design for the failure modes
Events fail in specific, predictable ways. Design for each from the beginning; they are not emergency features to add after the first incident.
Duplicate delivery
Delivery is at-least-once. A consumer must produce the same result when it receives the same event twice. Record processed event identifiers in the same transaction as the consumer’s state change, or rely on a unique constraint.
Out-of-order delivery
member.removed can arrive before member.invited if retries or partitions reorder them. Options include:
- carry a version or sequence number per subject and ignore older updates;
- have the consumer re-read the current state from the source of truth instead of trusting the payload;
- design consumers so the final state does not depend on order.
Schema evolution
Producers and consumers deploy independently. Treat the event schema as a public contract:
- Add fields in a backward-compatible way.
- Never change the meaning of an existing field.
- Treat removing a field as a migration: publish both shapes, move consumers, then remove.
- Include a version and keep a written description of each event type.
Poison messages
One malformed event should not block every event behind it. Bound retries, move the event to a dead-letter store with its error, alert the owner, and replay after the fix.
Debugging across boundaries
Carry the correlation identifier from the original request into the event and every consumer log. Without it, “why didn’t this customer get their receipt?” becomes a search through several systems by timestamp. The production logging and observability checklist covers the minimum signals to track for queues and consumers.
Events inside a monolith
Event-driven architecture does not require microservices. Some of the most useful event designs run inside a modular monolith: the billing module publishes invoice.paid through an outbox, and the notifications and reporting modules subscribe through in-process handlers or a queue in the same database.
This gives you decoupled modules and durable handoffs without network calls between services. If a module later needs to become a separate service, its event contracts already exist. For the broader decision, see monolith vs microservices for a growing product.
Events and APIs work together
Events do not replace APIs. A typical SaaS write flow uses both:
- The client calls a synchronous API that authorizes, validates, and commits the change.
- The same transaction records an event in the outbox.
- Consumers handle the slower, independent work.
- The client sees the immediate result and, if needed, follows progress through a status field or notification.
The API contract still defines who may do what and what the immediate result is. The backend API design checklist covers that side of the boundary.
Event-driven architecture checklist for SaaS
Before introducing a new event:
- It is a past-tense business fact with one owning module.
- The originating action is correct even if every consumer is delayed.
- It is written to an outbox in the same transaction as the state change.
- The envelope includes id, type, version, time, tenant, subject, and correlation id.
- Consumers are idempotent and do not read the producer’s internal tables.
- Ordering assumptions are written down and handled.
- Schema changes follow an additive, versioned process.
- Retries are bounded and failed events land in a visible store with replay.
- Lag, failure counts, and dead letters are monitored with a named owner.
- A direct call or transaction was considered and rejected for a stated reason.
Do not event everything
Keep a direct API call when a caller needs an immediate answer, one owner controls the operation, and a transaction is the simplest correctness mechanism. A queue does not make a workflow more reliable unless the producer, delivery path, and consumer failure states are deliberately designed.
Start with one event that removes real coupling or latency from an important request. Prove that it is delivered, observed, and replayable. Then add the next one.
Frequently asked questions
When should a SaaS product use event-driven architecture?
Use events when one completed business fact should trigger independent follow-up work, such as notifications, search indexing, analytics, webhook delivery, or document generation, and the original action remains correct even if that work is delayed.
When should you avoid events and use a direct API call?
Keep a direct call or a database transaction when the caller needs an immediate answer, one owner controls the whole operation, or the work must succeed or fail together with the original change.
What is a good domain event?
A good domain event is a past-tense business fact owned by one module, such as invoice.paid or member.invited. It carries a stable identifier, the time it happened, a schema version, and enough data for consumers without exposing the producer's internal tables.
Do I need Kafka or a message broker to start with events?
Not necessarily. A transactional outbox table in your existing database and a worker that delivers events to in-process handlers or a simple queue is enough for many products. Introduce a broker when consumer count, throughput, or retention needs justify the extra operational work.