ordergo
Event-driven order system using Saga Choreography (Kafka + Go). The repo contains four services and shared contracts/libraries. Services communicate via Kafka and maintain their own databases.
Services
- ordersvc: accepts orders, persists, emits order.created, updates status
- inventorysvc: reserves stock, emits inventory.reserved or inventory.failed
- paymentsvc: processes payment, emits payment.completed or payment.failed
- notificationsvc: stores notifications, emits notification.sent
Event flow
order.created -> inventory.reserved | inventory.failed inventory.reserved -> payment.completed | payment.failed payment.* -> notification.sent inventory.failed -> order.cancelled
Requirements
- Docker + Docker Compose
- Go 1.22 (only needed if you run services on host)
Quick start (Docker)
- Start Kafka + databases + AKHQ UI
make infra-up
- Create Kafka topics
make kafka-topics
- Build and run services
make services-up
- Open AKHQ
Ports
- ordersvc HTTP: 8080
- AKHQ UI: 8088
- Kafka host listener: 9094
- orders-db: 5433
- inventory-db: 5434
- payments-db: 5435
- notifications-db: 5436
HTTP API (ordersvc)
Create order
curl -X POST http://localhost:8080/orders \
-H 'Content-Type: application/json' \
-d '{
"customer_id": "C123",
"items": [{"sku":"SKU-1","qty":2,"price":10000}],
"total_amount": 20000
}'
Kafka topics
- order.created
- order.cancelled
- inventory.reserved
- inventory.failed
- payment.completed
- payment.failed
- notification.sent
Config files
- Host mode:
*/config/config.yaml(Kafka brokerlocalhost:9094) - Docker mode:
*/config/docker.yaml(Kafka brokerkafka:9092)
Make targets (selected)
make infra-up/make infra-downmake kafka-topicsmake services-up/make services-downmake services-logsmake akhq-logs
Runbook
See docs/runbook.md for step-by-step scenarios and event expectations.
Notes
- Inventory seed data lives in
scripts/seed/inventory.sql. - Idempotency is handled with a
processed_messagestable per service.