Event-driven architecture
Event-driven architecture separates the request a user waits for from the work that can happen afterward: emails, payment webhooks, imports, synchronization with other systems. We design the events, choose the broker and make every consumer safe to retry. The system absorbs traffic spikes and recovers from a failed step by running it again.
Event-driven architecture: an overview
Some work does not belong inside a web request: sending an invoice PDF, processing a payment webhook, resizing uploaded images, syncing an order to an ERP. When that work runs inline, the user waits for it, and if it fails halfway, the request fails with it. Moving it to a queue lets the request return quickly and gives the work its own retries.
Event-driven architecture goes a step further. A service announces that something happened and other parts of the system react without the publisher knowing who they are. That loose coupling is useful, and it has a price: the flow of a business process is no longer visible in one function, failures happen asynchronously, and the same message can arrive twice. Designing for those facts is most of the work.
The right tool is the simplest one that fits: often a background job queue, sometimes a message broker such as RabbitMQ or SQS, occasionally an event log such as Kafka. When a simple queue is enough, we say so.
What the service covers
Background jobs
Slow or fragile work such as emails, PDFs and third-party calls moves out of the web request into a job queue. Each job has retries, a timeout and a place to inspect failures.
Event design
Events are named in the past tense, carry a versioned schema and have one owning service. We decide what goes in the payload and what consumers should fetch for themselves.
Broker selection and setup
We choose between a Redis or PostgreSQL job queue, RabbitMQ, SQS and Kafka based on volume, ordering, replay needs and who will operate it. It runs as a managed service or in a container.
Reliable publishing
Producers write events to an outbox table in the same transaction as their data, and a relay publishes them. A crash between saving and publishing no longer loses an event.
Safe consumers
Consumers are idempotent, retry with backoff and send poison messages to a dead-letter queue. Replaying a message after a fix is a routine operation, not a script written in a hurry.
Webhooks and integrations
Incoming webhooks from payment providers, marketplaces or shipping services are stored first and processed asynchronously. Outgoing integrations are driven by events instead of direct calls from request handlers.
When it is the right call
- 01
Users wait on screens while the server sends emails, generates documents or calls a slow third-party API.
- 02
Webhooks from a payment provider or a marketplace are sometimes lost when your server is busy or restarting.
- 03
Several systems need to know when an order, a customer or a stock level changes, and every integration is a point-to-point call.
- 04
Background jobs fail silently, and the first report comes from a customer.
What you get
Event and message design with versioned schemas
Queues and brokers such as Kafka, RabbitMQ, SQS or Redis Streams, chosen for the load
Idempotent consumers, retries, dead-letter queues and the outbox pattern
Tracing of a message from producer to consumer
How we work on it
Step 1
List the flows
We map the business processes that cross system boundaries and mark which steps the user must wait for and which can run later. Each flow gets an owner and a description of what happens when a step fails.
Step 2
Choose the mechanism
Each need gets the simplest mechanism that covers it: a job queue, a broker or an event log. The choice and its reasons are written in an ADR.
Step 3
Design events and contracts
Event schemas live in the repository and are checked in CI. A breaking change requires a new version.
Step 4
Build producers and consumers
Producers and consumers are tested against a real broker running in a container. The tests include a crash in the middle of publishing and a duplicate delivery.
Step 5
Trace and monitor
Trace context travels with each message, so one trace shows a request and the work it triggered. Alerts watch queue depth, consumer lag and the dead-letter queue.
The outbox pattern and idempotent consumers
A common bug in event-driven systems: the code saves an order to the database, then publishes an OrderPaid event, and the process crashes between the two. The outbox pattern writes the event to an outbox table in the same database transaction as the order. A separate relay reads the table and publishes to the broker, so either both happen or neither does.
The relay, the broker and the network can all deliver a message more than once, so consumers must be idempotent: handling the same message twice gives the same result as handling it once. In practice that means a unique message ID, a table of processed IDs or a natural key with a unique constraint, and side effects such as sending an email guarded by that check.
Retries, dead-letter queues and message ordering
Retries need a limit and a growing delay. A message that fails because a third-party API is down will probably succeed later. A message that fails because its payload is invalid will fail forever. After a set number of attempts the message moves to a dead-letter queue, an alert fires, and someone can inspect it, fix the cause and replay it.
Ordering is the other common surprise. Most brokers guarantee order only within a partition or a single queue, and retries can reorder messages even there. If a CustomerUpdated event can be processed before CustomerCreated, consumers need either a key that routes all events of one customer to the same partition, or a version number on each event so a stale update is ignored. We decide per event type which guarantee is needed.
When a simple job queue is enough
If one application sends emails, generates reports and calls a few external APIs in the background, a job queue with retries, scheduling and a dashboard is the right tool. On Node.js that can be BullMQ on Redis, on Laravel the built-in queues, and on PostgreSQL alone a jobs table read with SKIP LOCKED. A message broker here would be infrastructure for a problem you do not have.
The signs that you have outgrown a job queue are specific: several services need to react to the same fact, you need to rebuild a read model or a search index by replaying past events, or the message volume turns a database-backed queue into a bottleneck. We introduce it when those needs are documented.
Methods and tools
- Monoliths and microservices
- Domain-driven design
- Architecture decision records
- C4 model
- pnpm workspaces
- Turborepo
- Nx
- PostgreSQL
- Kafka
How you can work with us
Fixed-scope project
The scope of the first version is written down, split into milestones and priced per milestone. It suits a product or a feature with a clear outline.
Dedicated team
A team works on your product over the long run, with its own planning and release cadence. It suits a product that keeps changing.
Team extension
One or more of our engineers join your team and work with your tools and routines. It suits a company that knows where it is going but lacks people or a specific skill.
Monthly support
A monthly retainer covers maintenance, updates and small changes, with an agreed response time. It suits a product in production that needs upkeep more than new features.
Questions about Event-driven architecture
Kafka, RabbitMQ or SQS: which one do we need?
For many products, none of them: when one application runs a few background tasks, a Redis-backed job queue is enough. SQS is managed and simple on AWS, RabbitMQ is good at routing messages to different consumers, and Kafka is a durable log that many consumers can read and replay. The choice depends on the volume, the delivery guarantees you need and who will operate the broker.
How do you make sure a message is not processed twice?
We design for at-least-once delivery and make processing idempotent, because no broker can promise exactly-once processing end to end. The consumer records each message ID in the same transaction as its own changes, so a duplicate is skipped. Side effects that leave the system, such as charging a card, also pass an idempotency key to the provider where it supports one.
Can you add queues to an existing application without a rewrite?
Yes. We usually start with one slow or fragile step, such as sending emails or handling webhooks, move it to a background job and add an outbox for the events it depends on. The rest of the application stays as it is, and each further step is a separate decision.
How do you debug a flow that runs across several consumers?
With tracing and correlation IDs. The trace context from the original request travels in the message headers, so OpenTelemetry shows the request, the published event and every consumer that handled it in one trace. Logs carry the same IDs, and the dead-letter queue keeps the failed message with its error.
What happens to events when we change their format?
Schemas are versioned, and changes follow compatibility rules: adding an optional field is safe, while removing or renaming a field is a new version. During a transition, producers can publish both versions while consumers move over. Contract tests in CI catch a change that would break an existing consumer before it is merged.
What drives the cost of moving to an event-driven design?
The number of flows involved, the number of systems that publish or consume, the broker you need and who will operate it, and how much existing code makes direct calls that must be replaced. Moving a few background jobs to a queue is a contained change. Introducing events between several services, with replay and schema rules, is a larger project delivered in milestones.
In the same service area
Design, build and ship your project
Describe it in three lines. We reply with specific questions and a first take on how to proceed.