Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🛒 E-Commerce Microservices Platform

A production-style E-Commerce backend built using Spring Boot 3.5, Java 21, and a full Microservices Architecture. Services communicate asynchronously via Apache Kafka and are discovered through Eureka Service Registry, with all traffic routed through a centralized Spring Cloud API Gateway with Circuit Breaker fault tolerance.


📋 Table of Contents


🏗 Architecture Overview

                        Client
                           │
                           ▼
              ┌────────────────────────┐
              │     API Gateway        │  ← Port 5000
              │  Spring Cloud Gateway  │
              │  + Resilience4j CB     │
              │  + Redis Rate Limiting │
              └────────┬───────────────┘
                       │  Load Balanced (Eureka lb://)
          ┌────────────┼────────────┐
          │            │            │
          ▼            ▼            ▼
  ┌──────────────┐ ┌──────────┐ ┌──────────────┐
  │Product Service│ │  Order   │ │   Payment    │
  │   Port 6002  │ │  Service │ │   Service    │
  │              │ │ Port 6001│ │  Port 6003   │
  └──────┬───────┘ └────┬─────┘ └──────┬───────┘
         │              │               │
         │         Kafka Events         │
         │    ┌─────────┴──────────┐    │
         │    │   Apache Kafka     │    │
         │    │  order-events      │◄───┘
         │    │  payment-events    │────►Order Service
         │    └────────────────────┘
         │
         ▼
    ┌─────────────────────────┐
    │   Eureka Discovery      │  ← Port 8761
    │   Server                │
    └─────────────────────────┘

  Each service → Own MySQL Database

🧩 Microservices

Service Port Responsibility
API Gateway 5000 Single entry point, routing, circuit breaker, fallback
Discovery Server 8761 Eureka service registry — all services register here
Product Service 6002 Product & category CRUD, stock management
Order Service 6001 Place orders, manage order status, inter-service calls
Payment Service 6003 Process payments, listen to order events via Kafka

🛠 Tech Stack

Layer Technology
Language Java 21
Framework Spring Boot 3.5.0
API Gateway Spring Cloud Gateway (WebFlux)
Service Discovery Netflix Eureka
Messaging Apache Kafka
Fault Tolerance Resilience4j Circuit Breaker
Caching Redis (API Gateway)
Database MySQL (per service)
ORM Spring Data JPA / Hibernate
Inter-service Calls RestTemplate + Load Balancer
Build Tool Maven

⚡ Event-Driven Flow

User Places Order
       │
       ▼
  Order Service
  (saves order with PENDING status)
       │
       │ publishes → [order-events] topic
       ▼
  Payment Service
  (listens to order-events via @KafkaListener)
  (processes payment automatically)
       │
       │ publishes → [payment-events] topic
       ▼
  Order Service
  (listens to payment-events via @KafkaListener)
  (updates order status → CONFIRMED / FAILED)

Kafka Topics:

  • order-events — Order Service → Payment Service
  • payment-events — Payment Service → Order Service

📡 API Reference

All requests go through the API Gateway at port 5000 with prefix /api/v1/

📦 Products — /api/v1/products

Method Endpoint Description
POST / Create a new product
GET / Get all products
GET /{productId} Get product by ID
PATCH /{productId}/stock Update stock quantity
DELETE /{productId} Delete product

🗂 Categories — /api/v1/categories

Method Endpoint Description
POST / Create a new category
GET / Get all categories
GET /{id} Get category with products

📋 Orders — /api/v1/orders

Method Endpoint Description
POST / Place a new order (triggers Kafka event)
GET /{orderId} Get order by ID
GET /customer/{customerId} Get all orders for a customer
PATCH /{orderId}/status Update order status

💳 Payments — /api/v1/payments

Method Endpoint Description
POST / Process a payment manually
GET /order/{orderId} Get payment details by order ID

🚀 Getting Started

Prerequisites

  • Java 21Download
  • Maven 3.9+
  • MySQL 8.0+
  • Apache KafkaDownload
  • Redis
  • Docker (optional but recommended)

Run Locally — Step by Step

Step 1 — Start Zookeeper & Kafka

# Start Zookeeper
bin/zookeeper-server-start.sh config/zookeeper.properties

# Start Kafka
bin/kafka-server-start.sh config/server.properties

Step 2 — Start Redis

redis-server

Step 3 — Start Discovery Server first

cd discovery-server
./mvnw spring-boot:run
# Visit http://localhost:8761 to see Eureka dashboard

Step 4 — Start all services (in any order)

# Terminal 1
cd product-service && ./mvnw spring-boot:run

# Terminal 2
cd order_service && ./mvnw spring-boot:run

# Terminal 3
cd payment_service && ./mvnw spring-boot:run

# Terminal 4 — Start Gateway last
cd apigateway && ./mvnw spring-boot:run

Step 5 — All traffic via API Gateway

http://localhost:5000/api/v1/products
http://localhost:5000/api/v1/orders
http://localhost:5000/api/v1/payments

🔐 Environment Variables

Set these for each service before running:

# Order Service / Payment Service / Product Service
DB_URL=jdbc:mysql://localhost:3306/your_db_name?createDatabaseIfNotExist=true
DB_USERNAME=root
DB_PASSWORD=yourpassword

# Kafka
KAFKA_BOOTSTRAP_SERVERS=localhost:9092

# Redis (API Gateway)
SPRING_REDIS_URL=redis://localhost:6379

🧩 Design Patterns

Pattern Where Used Purpose
API Gateway apigateway Single entry point for all clients
Service Discovery Eureka + all services Dynamic service registration & lookup
Event-Driven Kafka + Order/Payment Async, decoupled inter-service communication
Circuit Breaker API Gateway (Resilience4j) Prevents cascade failures, returns fallback
Load Balancing lb:// in gateway routes Client-side load balancing via Spring Cloud
Database per Service All services Each microservice owns its own data

🗂 Project Structure

springBoot-Microservices/
├── apigateway/               # Spring Cloud Gateway + Circuit Breaker + Redis
│   └── config/
│       ├── RedisConfig.java
│       └── FallbackController.java
│
├── discovery-server/         # Netflix Eureka Service Registry
│
├── product-service/          # Product & Category management
│   ├── controller/
│   ├── service/impl/
│   ├── entity/
│   ├── mapper/
│   └── exception/
│
├── order_service/            # Order management + Kafka Producer
│   ├── controller/
│   ├── service/
│   ├── events/               # OrderCreatedEvent, PaymentCompletedEvent
│   ├── listener/             # PaymentEventListener (Kafka Consumer)
│   └── config/KafkaConfig.java
│
└── payment_service/          # Payment processing + Kafka Consumer/Producer
    ├── controller/
    ├── service/
    ├── events/
    └── listener/             # OrderEventListener (Kafka Consumer)

👨‍💻 Author

Amar Deep Java Backend Developer


📄 License

This project is licensed under the MIT License — see the LICENSE file for details.


Built with ❤️ using Spring Boot 3.5 · Java 21 · Apache Kafka · Spring Cloud

About

E-Commerce Microservices backend built with Spring Boot 3.5, Java 21, Apache Kafka, Spring Cloud Gateway, and Eureka — featuring event-driven order & payment flow with Circuit Breaker pattern.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages