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.
- Architecture Overview
- Microservices
- Tech Stack
- Event Flow
- API Reference
- Getting Started
- Environment Variables
- Design Patterns
- Author
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
| 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 |
| 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 |
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 Servicepayment-events— Payment Service → Order Service
All requests go through the API Gateway at port 5000 with prefix
/api/v1/
| 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 |
| Method | Endpoint | Description |
|---|---|---|
POST |
/ |
Create a new category |
GET |
/ |
Get all categories |
GET |
/{id} |
Get category with products |
| 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 |
| Method | Endpoint | Description |
|---|---|---|
POST |
/ |
Process a payment manually |
GET |
/order/{orderId} |
Get payment details by order ID |
- Java 21 — Download
- Maven 3.9+
- MySQL 8.0+
- Apache Kafka — Download
- Redis
- Docker (optional but recommended)
Step 1 — Start Zookeeper & Kafka
# Start Zookeeper
bin/zookeeper-server-start.sh config/zookeeper.properties
# Start Kafka
bin/kafka-server-start.sh config/server.propertiesStep 2 — Start Redis
redis-serverStep 3 — Start Discovery Server first
cd discovery-server
./mvnw spring-boot:run
# Visit http://localhost:8761 to see Eureka dashboardStep 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:runStep 5 — All traffic via API Gateway
http://localhost:5000/api/v1/products
http://localhost:5000/api/v1/orders
http://localhost:5000/api/v1/payments
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| 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 |
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)
Amar Deep Java Backend Developer
- 💼 LinkedIn: amar-maurya-backend
- 🐙 GitHub: @amar-deep-2025
- 🐦 Twitter/X: @TechWithAmar
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