A comprehensive microservices-based order processing system built with Kafka, TypeScript, and Node.js. This project demonstrates real-world event-driven architecture patterns used in production systems.
This system simulates a real-world e-commerce order processing pipeline where:
- Orders are created via REST API
- Events flow through Kafka topics
- Multiple microservices process orders asynchronously
- Each service has a specific responsibility (payment, inventory, notifications)
Perfect for learning:
- Event-driven architecture
- Kafka producer/consumer patterns
- Microservices communication
- Async message processing
- Consumer groups and partitioning
βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββ
β Client βββββΆβ Order API βββββΆβ order-events β
β (Postman) β β Service β β (Kafka) β
βββββββββββββββ βββββββββββββββ βββββββββββββββββββββββ
β
ββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββ
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Payment Service β βInventory Serviceβ βNotification Svc β
β (Consumer) β β (Consumer) β β (Consumer) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β payment-events β βinventory-events β βnotification-evtsβ
β (Kafka) β β (Kafka) β β (Kafka) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- Runtime: Node.js 18+
- Language: TypeScript
- Framework: Express.js
- Message Queue: Apache Kafka
- Containerization: Docker
- Data Storage: JSON files (for learning purposes)
- Development: nodemon, ts-node
- Node.js 18+ and npm
- Docker and Docker Compose
- Postman or curl for API testing
- Basic knowledge of JavaScript/TypeScript
- Understanding of REST APIs
git clone https://github.com/jigarBorde/kafka-order-system.git
cd kafka-order-systemnpm installdocker-compose up -d# Create the main topics
docker exec -it kafka-container kafka-topics.sh --create \
--topic order-events \
--partitions 3 \
--replication-factor 1 \
--bootstrap-server localhost:9092
docker exec -it kafka-container kafka-topics.sh --create \
--topic payment-events \
--partitions 3 \
--replication-factor 1 \
--bootstrap-server localhost:9092
docker exec -it kafka-container kafka-topics.sh --create \
--topic inventory-events \
--partitions 3 \
--replication-factor 1 \
--bootstrap-server localhost:9092
docker exec -it kafka-container kafka-topics.sh --create \
--topic notification-events \
--partitions 3 \
--replication-factor 1 \
--bootstrap-server localhost:9092# Development mode
npm run dev
# Production mode
npm run build
npm startThe server will start on http://localhost:3000
POST /api/v1/orders
Content-Type: application/json
{
"customerId": "customer-123",
"productId": "product-A",
"quantity": 2
}Response:
{
"message": "Order event sent",
"event": {
"id": "order_abc123",
"customerId": "customer-123",
"productId": "product-A",
"quantity": 2,
"createdAt": "2024-01-15T10:30:00.000Z"
}
}| Topic | Purpose | Partitions | Consumers |
|---|---|---|---|
order-events |
New order creation | 3 | Order Consumer |
payment-events |
Payment processing | 3 | Payment Consumer |
inventory-events |
Stock management | 3 | Inventory Consumer |
notification-events |
User notifications | 3 | Notification Consumer |
- Order Created β
order-eventstopic - Payment Processed β
payment-eventstopic - Inventory Updated β
inventory-eventstopic - Notification Sent β
notification-eventstopic
{
"id": "order_abc123",
"customerId": "customer-123",
"productId": "product-A",
"quantity": 2,
"status": "pending",
"createdAt": "2024-01-15T10:30:00.000Z"
}- File:
src/consumers/order.consumer.ts - Responsibility: Process incoming orders, save to storage
- Consumer Group:
order-events - Triggers: Payment processing
- File:
src/consumers/payment.consumer.ts - Responsibility: Process payments, update order status
- Consumer Group:
payment-events - Triggers: Inventory check
- File:
src/consumers/inventory.consumer.ts - Responsibility: Check stock, reserve items
- Consumer Group:
inventory-events - Triggers: Notification service
- File:
src/consumers/notification.consumer.ts - Responsibility: Send order confirmations
- Consumer Group:
notification-events - Triggers: Email/SMS notifications (simulated)
# Check consumer group status
docker exec -it kafka-container kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group order-events
# Check consumer lag
docker exec -it kafka-container kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group payment-events- β Producers and Consumers
- β Consumer Groups
- β Partitioning Strategy
- β Event-Driven Architecture
- β Microservices Communication
- β Async Message Processing
# Install dependencies
npm install
# Run in development mode
npm run dev
# Build for production
npm run build
# Run tests (when added)
npm test- Built for learning Kafka and event-driven architecture
- Inspired by real-world microservices patterns
Happy Learning! π If you found this helpful, please β star the repository and share it with other developers learning Kafka!