What it is
In an event-driven architecture, services communicate mainly by publishing events (records that something happened, such as OrderPlaced) and reacting to events published by others, instead of calling each other and waiting. A broker (topic, log or bus) sits between producers and consumers, stores the events and delivers them to every interested subscriber.
Why it exists
Synchronous call chains couple services in three ways: in time (the callee must be up now), in latency (the caller waits for the sum of all calls) and in knowledge (the caller must know every callee and its API). Adding a new reaction to an order means changing and redeploying Checkout. Events remove those couplings for work that does not have to happen before the caller can answer: confirmation emails, loyalty points, analytics, search indexing, notifications.
How it works
Events vs commands.
| Event | Command | |
|---|---|---|
| Meaning | A fact: something happened | A request: please do something |
| Naming | Past tense: OrderPlaced |
Imperative: CapturePayment |
| Owner of the contract | Publisher | Receiver |
| Receivers | Zero, one or many; publisher doesn't know | Exactly one logical handler |
| Can be rejected? | No, it already happened | Yes |
| Typical channel | Topic / log with subscriptions | Queue owned by the receiver |
Delivery. Brokers deliver at least once: a consumer that does not acknowledge in time (crash, timeout) gets the message again. Consumers must therefore be idempotent, for example by storing processed message ids in the same transaction as their effect (inbox pattern). Producers publish reliably with a transactional outbox so the database change and the event cannot diverge.
Event types. Domain events are internal to a bounded context; integration events are published contracts for other services and must be versioned like public APIs. Event notifications carry an id and invite consumers to call back for details; event-carried state transfer carries the data so consumers need no callback.
Choreography vs orchestration. In choreography, each service reacts to events and publishes its own; the process emerges from the subscriptions. In orchestration, a coordinator (saga orchestrator, workflow engine such as Temporal, Azure Durable Functions or a MassTransit/NServiceBus saga) sends commands step by step and tracks process state, including compensations.
// MassTransit-style consumer: an event handler that is safe to run twice
public sealed class AwardPoints(LoyaltyDb db) : IConsumer<OrderPlaced>
{
public async Task Consume(ConsumeContext<OrderPlaced> ctx)
{
var id = ctx.MessageId!.Value;
if (await db.Processed.AnyAsync(p => p.MessageId == id)) return; // duplicate delivery
db.Points.Add(new PointsEntry(ctx.Message.CustomerId, ctx.Message.Total));
db.Processed.Add(new ProcessedMessage(id));
await db.SaveChangesAsync(); // effect + marker, one transaction
}
}
When to use it
- Work that reacts to something that already happened and need not finish before the user gets an answer.
- Several independent consumers of the same fact, owned by different teams.
- Consumers that must survive producer or consumer outages (durable subscriptions absorb them).
- Integration across bounded contexts where you want to avoid synchronous dependencies.
- Feeding read models, search indexes, caches and analytics.
When not to
- The caller needs the result to continue: stock checks, card authorisation, permission checks.
- Strong, immediate consistency across services is a hard requirement.
- Simple systems where a function call or one synchronous request is clearer.
- When the team cannot yet operate a broker, idempotent consumers and distributed tracing.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Events instead of sync calls | Shorter request path, availability isolation, open for new consumers | Eventual consistency, duplicates, harder debugging |
| Choreography | No central coordinator; services stay autonomous | Process is implicit; changes span teams; hard to answer "where is X?" |
| Orchestration | Explicit, observable process with compensations | A central component that knows every step |
| Fat events (state transfer) | Consumers need no callbacks | Larger contracts, more coupling to the publisher's data |
| Thin events (notifications) | Small, stable contracts | Callbacks put load and coupling back on the publisher |
Alternatives
- Synchronous request/response (HTTP, gRPC): simplest when the caller needs the answer.
- Command queues (point-to-point): asynchronous but with one known receiver; good for work distribution.
- Shared database: tempting, couples schemas; avoid across service boundaries.
- Batch/ETL: for analytics where minutes or hours of latency are fine.
Failure modes
- Invisible failures. A slow or broken consumer causes no error at the producer; the lesson's Checkout shows zero errors while Loyalty redelivers and double-awards points.
- Duplicates and reordering. At-least-once delivery and retries produce duplicates; partitions and retries reorder. Idempotent handlers and per-key ordering address them.
- Poison messages. A message that always fails blocks or loops; cap deliveries and send it to a dead-letter queue.
- Event chains nobody understands. Deep choreography makes changes risky; document flows and consider orchestration for long processes.
- Commands disguised as events.
SendWelcomeEmailon a topic couples the publisher to one consumer's behaviour. - Dual writes. Committing to the database and publishing separately loses events on crashes; use an outbox.
In production
Choose the broker by semantics: queues/topics with subscriptions (Azure Service Bus, Amazon SNS+SQS, RabbitMQ) or a log (Kafka, Azure Event Hubs) when replay and ordering per key matter. In .NET, MassTransit, NServiceBus, Wolverine or Brighter handle retries, outbox and sagas. Carry a correlation id and W3C trace context in message headers so OpenTelemetry traces span producer and consumers. Monitor per subscription: backlog size, age of the oldest message, redelivery and dead-letter rates. Version integration events and keep them backward compatible.
Common misconceptions
- "Event-driven means real-time." It means asynchronous; consumers may lag by milliseconds or hours.
- "Events make services fully independent." They still depend on the event contract and its meaning.
- "The broker guarantees exactly once." End-to-end effects are at least once unless consumers are idempotent.
- "Event-driven = event sourcing." One is about communication between services, the other about persistence inside one.
Interview angle
Draw the synchronous chain first, point out the latency sum and the availability product, then move non-essential work behind an event. Name the delivery semantics and how you make consumers idempotent, how you publish reliably (outbox), and how you observe the flow (correlation ids, tracing, lag alerts). Contrast choreography and orchestration and say which you would pick for a long, multi-step process with compensations (usually orchestration). Keep the steps the user waits for synchronous.
Model assumptions
The simulation is a simplified model, not a benchmark. Orders arrive as a Poisson stream (40/s, later 60/s in the challenge). Checkout has 64 workers and 15 ms of work; the orders database writes in ~8 ms. Synchronous services have 16 workers each (Email 80 ms, Loyalty 40 ms, Analytics 30 ms, lognormal cv 0.3) and are called in sequence. The topic copies each published event into one subscription per consumer; each subscription delivers to its own workers and redelivers messages not acknowledged within 1 s. The degraded Loyalty worker takes 30 times longer per message. The choreography chain (PaymentCaptured, Shipping, ShipmentDispatched) is a scripted illustration, because simulated workers do not publish further events. Numbers show behaviour and orders of magnitude only.