Skip to content

jayforge-dev/e-commerce-microservices

Repository files navigation

E-Commerce Microservices Platform

A production-style event-driven microservices system built with Kafka, Outbox Pattern, and resilient retry mechanisms-designed for scalability, consistency, and fault tolerance.


✨ Highlights

  • ⚡ Fully event-driven architecture
  • 🔁 Reliable delivery using Outbox Pattern
  • 🧠 Idempotent consumers (no duplicate side effects)
  • 📉 Exponential retry with jitter
  • 🔒 JWT-based authentication
  • ⚡ Event-driven JWT token invalidation using Redis
  • 🧩 Clean service boundaries (no shared DB)
  • 🐳 Dockerized setup

🏗️ Architecture

flowchart LR
    C[Client] --> O[Order Service]

    O -->|write| DB[(Order DB)]
    O -->|write event| OB[(Outbox)]

    OB -->|publish| K[(Kafka)]

    K -->|consume| I[Product Service]
    K -->|consume| P[Payment Service]

    I -->|STOCK_*| K
    P -->|PAYMENT_*| K

    K -->|update state| O
Loading

Order Service uses the Outbox Pattern to reliably publish events to Kafka.
Product and Payment services consume events and emit results back to Kafka, which drives the order lifecycle.

Note: Product Service also manages inventory (stock reservation).


🔄 Core Flow

✅ Success Path

sequenceDiagram
    participant C as Client
    participant O as Order
    participant K as Kafka
    participant I as Product
    participant P as Payment

    C->>O: Create Order
    O-->>K: RESERVE_STOCK

    K->>I: Check stock
    I-->>K: ✅ STOCK_RESERVED

    K->>O: Stock reserved
    O-->>K: INITIATE_PAYMENT

    K->>P: Process Payment
    P-->>K: ✅ PAYMENT_SUCCESS

    K->>O: Payment success
    O->>O: Mark COMPLETED
Loading

❌ Failure Path

👉 See details: Failure handling


📬 Key Events

  • RESERVE_STOCK
  • STOCK_RESERVED / RESERVATION_FAILED
  • INITIATE_PAYMENT
  • PAYMENT_SUCCESS / FAILED
  • RELEASE_STOCK

👉 See details: Event Design


📦 Outbox Pattern

Order Service uses the Outbox pattern to ensure reliable event publishing.

👉 See details: Outbox Design


🔁 Retry Strategy

Events are retried with exponential backoff and jitter.

👉 See details: Retry Strategy


📁 Project Structure

e-commerce-microservices/
├── api-gateway/
├── auth-service/
├── user-service/
├── product-service/
├── order-service/
├── payment-service/
├── eureka-server/
├── security/
├── dependency-platform/
└── docs/

🧩 Services

Service Responsibility
auth-service Authentication & token management
user-service User management
product-service Product & Inventory management
order-service Order lifecycle
payment-service Payment processing

📁 Module Overview

Each module contains a dedicated README with responsibilities and design details.


🔐 API Access

  • All client requests go through API Gateway
  • Internal services are not exposed externally

🗄️ Database

  • Schema managed via Flyway migrations

⚙️ Tech Stack

  • Backend: Java + Spring Boot
  • Messaging: Kafka
  • Cache: Redis
  • Database: PostgreSQL
  • Build: Gradle (KTS)
  • Infra: Docker

🧪 Run Locally

./gradlew build
docker compose -f docker-compose.yml up -d

Run a service in local for debugging:

docker compose up - For DB, Kafka (runs with override exposing ports) stop required services.

cd order-service
./gradlew bootRun

📸 System Demo

See system behavior and failure handling:

👉 View Demo

Note: System behavior is validated through end-to-end flows and failure simulations instead of formal unit tests.


About

Event driven e-commerce microservices platform

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors