Distributed e-commerce backend handling checkout, inventory, orders, and payments. Built with Spring Boot, PostgreSQL, Redis, and Kafka.
Transactional microservices platform with SAGA orchestration for distributed transactions, optimistic concurrency control, and event-driven inventory updates.
- Transactional Microservices: Independent services for checkout, orders, payments, inventory
- Data Consistency: SAGA orchestration with compensating transactions for distributed rollback
- Caching: Redis for hot path reads
- Event-Driven: Kafka for async inventory events (optional)
- Concurrency Control: Optimistic locking with bounded retry on write contention
| Component | Technology | Purpose |
|---|---|---|
| Services | Java (Spring Boot) | Business logic and REST APIs |
| Database | PostgreSQL | Relational data with optimistic locking |
| Cache | Redis | Reduce DB load on hot paths |
| Events | Kafka | Async inventory event publishing |
| Frontend | HTML/JS | Dashboard for testing and visualization |
git clone https://github.com/QHarshil/Commerce-Services.git
cd Commerce-Services
./build.sh
docker compose up --buildAccess:
- Frontend Dashboard:
http://localhost:3000 - Inventory API:
http://localhost:8081 - Checkout API:
http://localhost:8084
Kafka is optional. Set INVENTORY_EVENTS_ENABLED=false in docker-compose.yml to disable.
./build.sh
./start-local.sh
# Stop
./stop-local.sh| Endpoint | Method | Description |
|---|---|---|
/api/v1/inventory/products |
GET | List all products with stock |
/api/v1/inventory/products/{id} |
GET | Get product inventory |
/api/v1/inventory/reserve |
POST | Reserve stock for order |
/api/v1/inventory/value |
GET | Total inventory value |
| Endpoint | Method | Description |
|---|---|---|
/api/v1/checkout/process |
POST | Process checkout with SAGA |
Request:
{
"customerId": "customer-uuid",
"items": [
{
"productId": "7a2d4f61-9c3b-4e8a-b1d5-6f0e2c9a4b13",
"quantity": 1
}
],
"paymentMethod": "CREDIT_CARD"
}Dashboard at http://localhost:3000 provides:
- Live Inventory: Real stock levels from PostgreSQL
- Checkout Testing: Process orders, watch inventory update in real-time
- Performance Metrics: Actual response times per request
- Health Monitoring: Service status with 30s refresh
mvn clean testIntegration tests (CheckoutIntegrationTest) cover:
- Checkout SAGA success path with stubbed inventory, order, and payment services
- Failure and compensation when inventory is unavailable
- Checkout health endpoint
# Start infra
docker run -d -p 5432:5432 -e POSTGRES_DB=commerce -e POSTGRES_USER=commerce -e POSTGRES_PASSWORD=commerce123 postgres:15-alpine
docker run -d -p 6379:6379 redis:7-alpine
# Run a service
cd services/inventory-service
mvn spring-boot:run
# Start frontend
cd frontend
python3 server.py# Tail logs
docker compose logs -f <service>
# Rebuild single service
docker compose build <service>
docker compose up -d <service>Service-to-service calls use Compose names (e.g., http://payment-service:8080). Host access uses localhost ports.
MIT
