Event-Driven Architecture
Event-Driven Architecture (EDA) replaces tight synchronous chains with facts on a log.
Introduction
Event-Driven Architecture (EDA) replaces tight synchronous chains with facts on a log. Orders emits OrderPlaced; billing, inventory, notification, and analytics react without Orders importing their clients.
On Boot 3 this usually means domain events + Kafka (or Rabbit), plus the outbox pattern so the database write and the broker publish stay consistent.
Version events, tolerate additive fields, and route poison messages to a dead-letter topic.
This lesson reframes TechLearningPRO Orders integrations as reactions to events rather than nested HTTP calls.
Purpose of this lesson
Apply EDA to Orders: emit events, decouple consumers, and use outbox/DLQ practices on Boot 3.
Understanding the topic
Producers publish facts; consumers decide reactions — loose coupling with replay.
- domain event: something that happened (
OrderPlaced). - fan-out: many consumers, one topic.
- outbox: transactional write of event intent with business data.
- versioning: additive changes; consumers ignore unknown fields.
- DLQ: isolate poison messages for repair.
Step-by-step explanation
- Define
OrderPlacedas a versioned record (ids + totals, minimal PII). - Write order + outbox row in one
@Transactionalmethod. - Run a publisher that ships outbox rows to Kafka and marks them sent.
- Add independent consumers for billing and notification with DLQ configuration.
Syntax reference
Synchronous chain vs event-driven Orders fan-out.
# Synchronous (tight coupling)Order ──► Billing ──► Inventory ──► Notificationx any failure breaks the chainx each new consumer = code change in Order# Event-driven (loose coupling)Order ──► Kafka [order.placed] ──► Billing└──► Inventory└──► Notification└──► Analytics+ add consumers without touching producer+ retries, dead-letter queues, replay from log# Outbox (same DB transaction)orders table + outbox table ──► relay ──► Kafka
Real-world use
Adding a fraud-scoring partner used to mean changing Orders to call yet another HTTP API inside the purchase path. With EDA, fraud subscribed to order.placed and published order.flagged without a Orders redeploy for every new detector.
Security implications
Events travel farther than a single HTTP response.
- Minimize personal data in events; use opaque ids.
- Encrypt clusters in transit; ACL topics per team.
- Treat replay environments carefully — they can re-trigger side effects.
Best practices
- Outbox or change-data-capture for reliable publish.
- Contract tests for event schemas; document versions.
- Always configure DLQ and alert on depth.
Common mistakes
- Dual-write: commit order then publish — crash loses the event.
- Huge event payloads that embed entire aggregates and PII.
- Chatty event storms without aggregation or idempotent handlers.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1IntermediateQuestionWhat problem does the outbox pattern solve?+
Answer
2BeginnerQuestionWhy is EDA looser coupling than sync HTTP?+
Answer
3IntermediateQuestionWhat is a dead-letter queue/topic for?+
Answer
Hands-on exercise
Lab. Implement place-order with an outbox table. Publish to Kafka from a relay. Add a notification listener that fails once then succeeds, and confirm the business order remains committed while the event retries.
Summary
Event-driven architecture turns TechLearningPRO Orders into a producer of facts: outbox to Kafka, many consumers, safer evolution than synchronous chains.