Event-Driven Architecture (EDA) — architectural style where services communicate via publish/subscribe events rather than direct API calls. Producer emits event → message broker (Kafka, RabbitMQ, AWS SNS) delivers → consumers react. Loose coupling: producer doesn't know consumers. Use cases: order processing, notifications, analytics pipelines. Contrast: synchronous REST/gRPC.
Below: details, example, related terms, FAQ.
// Producer
producer.send('order.placed', {
orderId: 'ord-123',
customerId: 'c-456',
total: 99.99
});
// Consumer (OrderService reads)
consumer.on('order.placed', async (event) => {
await sendEmail(event.customerId);
await updateInventory(event.items);
});EDA — async, decoupled. RR — sync, tight coupling. EDA scales better, RR easier to debug. Most systems — hybrid (EDA cross-service, RR inside service).
Kafka — high-throughput streams, long retention, replay. RabbitMQ — queues with routing rules. Kafka for analytics/logs, RabbitMQ for task queues.
UI shows optimistic updates + reconciles later. APIs return pending state. For banking — use saga pattern with compensating actions.