Event-driven architecture

In event-driven architecture, services communicate by producing and consuming events (something happened: “OrderPlaced,” “UserSignedUp”). Producers publish to a broker (Kafka, etc.); consumers subscribe and react. This decouples producers from consumers and allows multiple consumers to react to the same event.

Flow

flowchart LR P[Order Service] -->|OrderPlaced| B[Event Bus / Kafka] B --> C1[Inventory Service] B --> C2[Notification Service] B --> C3[Analytics]

Benefits and trade-offs

BenefitTrade-off
Loose couplingEventual consistency; harder to trace
Multiple consumersOrdering and exactly-once need care
Scale consumers independentlyOperational complexity (broker, schemas)

Event vs command

Event — “Something happened” (past tense). Multiple subscribers. Command — “Do this” (imperative). Often one handler. Events are the backbone of event-driven systems; commands can be sent over queues for point-to-point work.

flowchart TB subgraph Events["Events (broadcast)"] E1[OrderPlaced] E1 --> S1[Service A] E1 --> S2[Service B] end subgraph Commands["Commands (targeted)"] C1[ProcessPayment] --> S3[Payment Service] end