A scalable event-driven microservices architecture that enables real-time order processing and inventory management using Apache Kafka for reliable message streaming and event handling.
This project implements a distributed system of microservices that communicate asynchronously through Kafka events. The architecture consists of four core services - Order, Inventory, Payment and Notification - that work together to process customer orders while maintaining data consistency and system reliability.
The system leverages Apache Kafka's pub/sub messaging to decouple services and enable independent scaling. Key features include:
- Event-driven architecture with Kafka for reliable message streaming
- Containerized microservices using Docker and Docker Compose
- Real-time order status updates and inventory management
- Kafdrop UI for Kafka topic monitoring and management
- Configurable services with environment-based settings
.
├── docker-compose.yml # Main Docker Compose configuration for all services
├── kafka-infra/ # Kafka infrastructure setup
│ └── docker-compose.yml # Kafka and Zookeeper configuration
├── order-service/ # Order processing service
│ ├── src/ # Source code for order management
│ └── Dockerfile # Container build instructions
├── inventory-service/ # Inventory management service
│ ├── src/ # Source code for inventory tracking
│ └── Dockerfile # Container build instructions
├── payment-service/ # Payment processing service
│ └── src/ # Source code for payment handling
└── notification-service/ # Notification handling service
└── src/ # Source code for notifications
- Java Development Kit (JDK) 17 or later
- Docker and Docker Compose
- Maven 3.6.x or later
- Git
- Clone the repository:
git clone <repository-url>
cd <repository-name>- Build the services:
# Build each service
cd order-service && ./mvnw clean package
cd ../inventory-service && ./mvnw clean package
cd ../payment-service && ./mvnw clean package
cd ../notification-service && ./mvnw clean package- Start the infrastructure:
docker-compose up -d- Verify services are running:
docker-compose ps- Access Kafdrop UI:
- Open http://localhost:9000 in your browser
- View Kafka topics and messages
- Create a sample order:
curl -X POST http://localhost:8081/api/orders \
-H "Content-Type: application/json" \
-d '{"orderId":"123","userId":"user1","status":"PENDING"}'- Monitor order processing:
# Watch Kafka topics
docker-compose logs -f kafka
# Check inventory service logs
docker-compose logs -f inventory-service- Scale services:
# Scale inventory service
docker-compose up -d --scale inventory-service=2Common Issues:
- Services fail to start
- Check if Kafka is running:
docker-compose ps - Verify ports are not in use:
netstat -an | grep PORT - Review service logs:
docker-compose logs SERVICE_NAME
- Messages not being processed
- Check Kafka topics in Kafdrop UI
- Verify consumer group status
- Review consumer service logs
- Connection issues
- Ensure all containers are on same network
- Verify bootstrap server configuration
- Check network connectivity between services
The system processes orders through a series of event-driven interactions between services, maintaining data consistency through Kafka events.
[Order Service] --> (order-created) --> [Kafka] --> [Inventory Service]
|
+--> [Payment Service]
|
+--> [Notification Service]
Component Interactions:
- Order Service publishes order events to Kafka
- Inventory Service consumes order events and updates stock
- Payment Service processes payment for valid orders
- Notification Service sends updates to relevant parties
- All services communicate asynchronously through Kafka topics
- Each service maintains its own data store
- Kafdrop provides monitoring and management UI
Kafka Infrastructure:
- Zookeeper: Coordination service (port 2181)
- Kafka Broker: Message broker (port 9092)
- Kafdrop: Web UI for Kafka monitoring (port 9000)
Application Services:
- Order Service: Port 8081
- Inventory Service: Port 8082
- Payment Service: Internal
- Notification Service: Internal
Prerequisites:
- Docker environment
- Network access to container registry
- Sufficient system resources
Deployment Steps:
- Configure environment variables
- Deploy Kafka infrastructure
- Deploy application services
- Verify service health
- Monitor system metrics