Event-driven architecture
Событийная архитектура
In event-driven architecture, components announce what happened, and other components react to those announcements. For example, a warehouse can start preparing an order when it receives an event saying the order was paid.
Also known as: EDA
What makes an architecture event-driven?
Suppose an online store needs to start packing an order, update a dashboard, and send a receipt after payment. The payment service could call each of those systems directly. In an event-driven architecture (EDA), it publishes OrderPaid instead. Each interested component decides how to respond, and adding a new subscriber doesn't require the payment service to call it.
An event records a fact. OrderPaid says that payment already happened; ChargeOrder asks a component to make it happen. Both can travel through the same messaging infrastructure, so the presence of a broker alone doesn't make a system event-driven.
How an event moves through the system
The publisher creates a message that typically includes an event type, a unique event ID, and relevant data such as the order ID. In distributed systems, a broker such as Apache Kafka or RabbitMQ makes the event available to subscribers. With Kafka, the warehouse and analytics services can use separate consumer groups so both receive the event. Multiple workers in the warehouse group share the work rather than each handling every event.
The payment service usually doesn't wait for those consumers to finish. This makes it possible to add workers to a slow consumer without scaling the publisher, but it also means the dashboard may briefly show the old status. That delay is part of eventual consistency: downstream views can lag before they catch up.
What happens when delivery fails?
Imagine the payment service commits the new status to its database and crashes before publishing OrderPaid. The payment is on record, but the warehouse has no way to know from the event stream. A transactional outbox closes that gap: the service saves the payment and a pending event in the same database transaction, then a separate process publishes the pending event.
If that process publishes successfully but crashes before marking the event as sent, it may publish it again. Under at-least-once delivery, consumers must expect duplicates. If creating a packing task is a database operation, the warehouse can record the event ID and create the task in a single transaction. A uniqueness constraint on the recorded event ID prevents a retry from creating a second task.
When to choose it
EDA fits workflows with several independent reactions, such as order fulfillment, notifications, and search indexing. It can also run within a monolith using in-process events. If the caller needs an immediate decision, such as whether a coupon is valid, a synchronous request is often simpler. A single workflow can use both.
EDA is not the same as Event Sourcing. EDA is about how components communicate. Event Sourcing makes a stored sequence of events the source of truth for rebuilding state. A service can publish events while keeping its current state in ordinary database tables.
What interviewers look for
In a system design interview, explain which steps can lag, which ones can be retried, and where order matters. For example, Kafka guarantees record order within a partition, not across a whole topic. Keying records by order ID can route events for the same order to one partition, but the consumer still needs to avoid applying those events out of order if it processes them concurrently.