Event-Driven Architecture Flow π‘
This document explains how ShopVerse uses an event-driven architecture (EDA) with Apache Kafka to achieve loose coupling, scalability, and resilience across microservices.
Event-driven communication is used for non-critical, asynchronous workflows such as notifications, analytics, and recommendations.
π― Why Event-Driven Architecture?β
In a microservices system, direct synchronous calls can cause:
- Tight coupling
- Cascading failures
- Poor scalability
ShopVerse uses Kafka-based events to ensure:
- Services remain independent
- Failures do not propagate
- New consumers can be added without changing producers
π§ Core Ideaβ
Services publish events about what happened.
Other services react to those events independently.
No service directly calls another service for side effects like notifications or analytics.
πΊοΈ High-Level Event Flowβ
Core Services β Kafka Topics β Consumer Services
Core services produce events.
Consumer services subscribe and react.
ποΈ Event-Driven Architecture Diagram (Mermaid)β
π¦ Events in ShopVerseβ
Each event represents a business fact.
Common Event Types:β
USER_REGISTEREDUSER_LOGINPRODUCT_CREATEDPRODUCT_UPDATEDORDER_PLACEDPAYMENT_SUCCESS
Events are immutable and append-only.
π‘ Kafka Topics Designβ
| Topic Name | Purpose |
|---|---|
auth-events | User login & registration |
product-events | Product lifecycle changes |
order-events | Order placement & updates |
payment-events | Payment status changes |
analytics-events | Aggregated analytics data |
π§© Event Payload Structureβ
All services follow a standardized event schema:
{
"eventType": "ORDER_PLACED",
"service": "ORDER_SERVICE",
"userEmail": "user@example.com",
"entityId": "ORD123",
"amount": 2499.00,
"timestamp": "2026-01-21T10:30:00",
"metadata": {
"paymentMode": "UPI"
}
}
Why Standardization?β
- Easy to consume
- Easier debugging
- Future-proof
- Analytics-friendly
π Event Publishing Flowβ
Example: Order Placementβ
π Consumer Groups & Scalingβ
- Each consumer service runs in its own consumer group
- Kafka distributes partitions across instances
- Consumers can scale horizontally
Example:β
notification-service-group
analytics-service-group
recommendation-service-group
π‘οΈ Idempotency & Reliabilityβ
Challenges:β
- Duplicate events
- Consumer restarts
- Network failures
Solutions:β
- Unique event identifiers
- Idempotent consumer logic
- Offset commits after successful processing
- Retry & dead-letter strategies (future-ready)
β οΈ Failure Scenariosβ
β Consumer Downβ
- Kafka retains events
- Consumer resumes from last offset
β Producer Failureβ
- Transaction rollback prevents event publishing
- Partial state avoided
β Duplicate Eventsβ
- Handled using idempotent checks
π Benefits Achievedβ
| Concern | How EDA Solves It |
|---|---|
| Loose coupling | No direct service calls |
| Scalability | Independent scaling |
| Resilience | Failure isolation |
| Extensibility | Add consumers easily |
| Performance | Non-blocking flows |
π§ Why Not Everything Is Event-Driven?β
ShopVerse uses hybrid communication:
- REST β Critical, immediate responses
- Kafka β Side effects & async workflows
This balances consistency and performance.
π Summaryβ
ShopVerseβs event-driven architecture:
- Decouples services
- Improves resilience
- Enables future growth
- Reflects real-world backend design
Kafka acts as the central nervous system of the platform.