How zakariaalla/event-driven-architecture-kafka works
Project Type and Purpose
• This is an event-driven, microservices-based system built with Spring Boot and Apache Kafka.
• Four deployable units:
• Order Service (produces events)
• Stock Service (consumes and processes events, persists to PostgreSQL)
• Email Service (consumes events and sends emails)
• Base-domains Service (shared DTOs and domain types library)
Main Components
• Kafka Cluster (one or more brokers)
• Topic: “orders” (or similar)
• Microservices (Spring Boot apps)
• Order Service
• Stock Service
• Email Service
• Shared Library
• Base-domains (contains Order, OrderEvent DTOs)
• Database
• PostgreSQL (used by Stock Service)
Relationships & Data Flow
1. Client or external system → Order Service REST API (OrderController)
2. Order Service → serializes OrderEvent → publishes to Kafka topic
3. Kafka topic → fan-out to consumers (Stock Service & Email Service)
4. Stock Service consumes the event → maps DTO to Entity → persists OrderEntity in PostgreSQL
5. Email Service consumes the event → sends email to customer
6. All services depend on Base-domains for shared types
Architectural Patterns & Principles
• Microservices: Each service runs in its own process, has its own codebase and data store (only Stock Service uses a DB).
• Event-Driven: Asynchronous communication via Kafka topic; loose coupling between producer and consumers.
• Shared Kernel (Domain Library): Base-domains is a shared module for keeping DTOs in sync.
• Single Responsibility: Each service focuses on one bounded context (orders, stock, email).
Technologies & Frameworks to Call Out
• Spring Boot (embedded server, auto-configuration)
• Spring Kafka (KafkaTemplate for producer, @KafkaListener for consumer)
• Spring Data JPA / Hibernate (in Stock Service)
• Apache Kafka (message broker, topics, producers, consumers)
• PostgreSQL (relational store for Stock Service)
• Maven (build, manage dependencies)
Essential Elements Checklist
• [ ] Kafka cluster & “order-events” topic