Skip to content

About

A distributed e-commerce backend with services for checkout, inventory, orders, and payments. Uses Spring Boot, PostgreSQL, Redis, and Kafka for inventory events. This project emphasizes correctness, low latency, and operability on a developer laptop with Docker. A minimal frontend in html and javascript to visaluze the backedn APIs.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Commerce Services

Distributed e-commerce backend handling checkout, inventory, orders, and payments. Built with Spring Boot, PostgreSQL, Redis, and Kafka.

Overview

Transactional microservices platform with SAGA orchestration for distributed transactions, optimistic concurrency control, and event-driven inventory updates.

Architecture

Features

  • 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

Architecture

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

Quick Start

Docker Compose (Recommended)

git clone https://github.com/QHarshil/Commerce-Services.git
cd Commerce-Services
./build.sh
docker compose up --build

Access:

  • 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.

Local Development

./build.sh
./start-local.sh

# Stop
./stop-local.sh

API

Inventory Service (Port 8081)

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

Checkout Service (Port 8084)

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"
}

Frontend Dashboard

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

Testing

mvn clean test

Integration tests (CheckoutIntegrationTest) cover:

  • Checkout SAGA success path with stubbed inventory, order, and payment services
  • Failure and compensation when inventory is unavailable
  • Checkout health endpoint

Development

Run Services Individually

# 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

Tips

# 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.

License

MIT

About

A distributed e-commerce backend with services for checkout, inventory, orders, and payments. Uses Spring Boot, PostgreSQL, Redis, and Kafka for inventory events. This project emphasizes correctness, low latency, and operability on a developer laptop with Docker. A minimal frontend in html and javascript to visaluze the backedn APIs.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages