Skip to content
EDA (Event-Driven Architecture)

EDA (Event-Driven Architecture)

EDA

Event-Driven Architecture

1. Overview: EDA, an architecture that breaks synchronous dependencies between services and loosely couples them via events

    flowchart LR
    A["Synchronous calls:<br/>tight coupling, failure propagation,<br/>limited scalability"] --"Event-based<br/>asynchronous communication"--> B["Event publish/subscribe<br/>Producer, Broker, Consumer"] --"Loose coupling,<br/>independent scaling"--> C["Resilient, scalable<br/>distributed system"]

    style A fill:#FFEBEE,stroke:#D32F2F,color:#000
    style B fill:#E3F2FD,stroke:#1976D2,color:#000
    style C fill:#E8F5E9,stroke:#388E3C,color:#000
  

Definition: An architectural pattern in which system components interact by producing, publishing, subscribing to, and processing events. Instead of calling each other directly, services communicate through an event broker with asynchronous, loose coupling, achieving scalability and resilience.

Characteristics: (Service independence) Event producers don’t need to know their consumers, maximizing independence between services. (Elastic processing) Asynchronous processing enables elastic handling of traffic spikes through event buffering. (Standard MSA pattern) A standard pattern for inter-service communication in microservice environments, often combined with Saga, CQRS, and Event Sourcing.


2. EDA’s core structure

A. Event-driven communication structure

    flowchart LR
    subgraph PRO["Event Producers"]
        direction TB
        P1["Order service<br/>publishes OrderPlaced"]
        P2["Payment service<br/>publishes PaymentCompleted"]
    end

    subgraph BRK["Event Broker"]
        direction TB
        B1["Topic/queue management,<br/>event buffering"]
        B2["Routing/filtering,<br/>ordering guarantees"]
    end

    subgraph CON["Event Consumers"]
        direction TB
        C1["Inventory service<br/>deducts stock"]
        C2["Notification service<br/>sends email/push"]
        C3["Shipping service<br/>starts delivery"]
    end

    PRO --> BRK --> CON

    style PRO fill:#E3F2FD,stroke:#1976D2,color:#1E3A5F
    style BRK fill:#1E3A5F,stroke:#1E3A5F,color:#fff
    style CON fill:#E8F5E9,stroke:#388E3C,color:#1B5E20
  
ComponentRoleRepresentative technology
Event ProducerCreates and publishes an event when a business event occursSpring ApplicationEvent, Kafka Producer
Event BrokerReceives, stores, routes, and delivers eventsApache Kafka, RabbitMQ, AWS EventBridge
Event ConsumerSubscribes to events of interest and executes business logicKafka Consumer, Spring @EventListener
Event SchemaStandardizes event structure and manages backward compatibilityAvro, JSON Schema, Protocol Buffers

Comparing event delivery styles

StyleCharacteristicsSuitable use case
Simple EventNotifies only the fact of a state change (minimal information)Notifications, triggers
Event-Carried State TransferThe event carries the changed state dataData synchronization between services
Event SourcingStores every state-change event in sequenceAudit logs, time travel

B. Event Sourcing and CQRS patterns

    flowchart TD
    subgraph CMD["Command Side (writes)"]
        direction LR
        C1["Command<br/>request to create an order"]
        C2["Aggregate<br/>applies business rules"]
        C3["Event Store<br/>persists events"]
        C1 --> C2 --> C3
    end

    subgraph QRY["Query Side (reads)"]
        direction LR
        Q1["Read Model<br/>view table for queries"]
        Q2["Query Handler<br/>handles queries"]
        Q1 --> Q2
    end

    C3 --"Publishes event,<br/>updates Read Model"--> Q1

    style CMD fill:#E3F2FD,stroke:#1976D2,color:#1E3A5F
    style QRY fill:#E8F5E9,stroke:#388E3C,color:#1B5E20
  

Event Sourcing vs. traditional state storage

ComparisonEvent SourcingTraditional state storage
Storage approachAccumulates state-change events in sequenceOverwrites current state (snapshot) with the latest value only
History trackingFull change history can be replayedHistory is hard to preserve or query
AuditBuilt-in, complete audit trailRequires a separate audit log table
ComplexityRequires event design and replay logicSimple CRUD pattern

Core CQRS principles

PrincipleDescriptionBenefit
Separate Command and QuerySeparate models/stores for data changes (Command) and reads (Query)Each can be optimized independently
Write ModelAn Aggregate centered on business rules and invariantsGuarantees consistency and integrity
Read ModelA denormalized view table optimized for query performanceFast reads without complex joins
Eventual consistencyAllows slight delay in Write → Read model synchronizationAchieves high scalability and availability

3. Expected benefits and practical application of EDA

CategoryKey expected benefitPractical application
Loose couplingChanges or failures in one service don’t propagate to othersConvert inter-service communication in MSA from REST calls to events
ScalabilityScale throughput horizontally by increasing consumer countUse Kafka Consumer Groups for parallel processing per partition
Audit & traceabilityEvent Sourcing preserves the full history of state changesMeet audit-trail requirements in regulated domains like finance and healthcare
Real-time processingReal-time analysis and response based on event streamsImplement real-time anomaly detection and alerting with Kafka Streams/Flink