Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

🛒 E-Commerce Microservice Backend

A production-inspired E-Commerce Backend built using Java 21, Spring Boot, and a Microservices Architecture. This project demonstrates how modern distributed systems are designed by combining secure authentication, scalable communication, fault tolerance, and event-driven architecture.

The application follows industry-standard backend practices such as API Gateway, Service Discovery, OAuth2 authentication with Keycloak, Circuit Breakers, asynchronous messaging, distributed caching, and containerized deployment.

This project was built to gain hands-on experience with enterprise backend architecture and demonstrate real-world Java backend engineering skills.


🚀 Features

  • Microservices Architecture
  • API Gateway
  • Service Discovery (Eureka)
  • OAuth2 Authentication & JWT Authorization
  • Role-Based Access Control (RBAC)
  • Product Catalog Management
  • Shopping Cart
  • Secure Checkout
  • Order Management
  • Stock Reservation & Validation
  • Distributed Caching using Redis
  • Asynchronous Messaging using RabbitMQ
  • Fault Tolerance using Resilience4j
  • Dockerized Deployment
  • PostgreSQL Database
  • Centralized Configuration
  • RESTful APIs

🏗️ Microservices

API Gateway

Acts as the single entry point for all client requests.

Responsibilities:

  • Request Routing
  • JWT Validation
  • Authentication
  • Authorization
  • Load Balancing
  • Security

Eureka Server

Provides service discovery allowing microservices to communicate dynamically without hardcoding URLs.


User Service

Responsible for:

  • User Information
  • Customer Profile
  • User APIs

Authentication is handled by Keycloak, while user-related business data is managed here.


Product Service

Responsible for:

  • Product CRUD
  • Categories
  • Inventory
  • Stock Management

Provides APIs for stock validation and reservation during checkout.


Cart Service

Responsible for:

  • Add to Cart
  • Update Quantity
  • Remove Product
  • View Cart

Smart Cart Validation

When a user adds an item:

  • Product availability is checked.
  • Stock availability is verified.
  • Invalid products cannot be added.

During Checkout:

  • Cart is revalidated.
  • Out-of-stock products are automatically removed.
  • User receives updated cart before placing the order.

Order Service

Responsible for:

  • Order Creation
  • Order History
  • Order Status

Checkout Flow:

  1. Fetch authenticated user.
  2. Retrieve cart items.
  3. Validate latest inventory.
  4. Reserve stock.
  5. Create order.
  6. Save order.
  7. Publish order event.

🔐 Security

Authentication is implemented using Keycloak.

Every request follows this flow:

Client
   │
   ▼
API Gateway
   │
JWT Validation
   │
Route Request
   │
Target Microservice

Each microservice is configured as an OAuth2 Resource Server and independently validates JWT tokens.

No service trusts client-provided user IDs.


⚡ Fault Tolerance

Implemented using Resilience4j.

Patterns used:

  • Circuit Breaker
  • Retry
  • Timeout
  • Fallback Methods

Example:

Order Service
      │
      ▼
Product Service

If Product Service becomes unavailable:

Circuit Breaker Opens
↓

Fallback Response
↓

System remains responsive

📦 Asynchronous Communication

RabbitMQ is used for event-driven communication between services.

Benefits:

  • Loose Coupling
  • Better Scalability
  • Reliable Event Processing
  • Improved Performance

Example flow:

Order Created
      │
      ▼
RabbitMQ
      │
      ▼
Interested Services Consume Event

⚡ Redis

Redis is used to improve application performance through distributed caching.

Benefits:

  • Faster Read Operations
  • Reduced Database Load
  • Improved Response Time

🐳 Docker

Every microservice is containerized.

Services can be started together using Docker Compose.

Example components:

  • API Gateway
  • Eureka Server
  • User Service
  • Product Service
  • Cart Service
  • Order Service
  • PostgreSQL
  • Redis
  • RabbitMQ
  • Keycloak

🛠️ Tech Stack

Backend

  • Java 21
  • Spring Boot
  • Spring MVC

Spring Cloud

  • Spring Cloud Gateway
  • Eureka Discovery

Security

  • Spring Security
  • OAuth2 Resource Server
  • JWT
  • Keycloak

Database

  • PostgreSQL

Messaging

  • RabbitMQ

Cache

  • Redis

Fault Tolerance

  • Resilience4j

Build Tool

  • Maven

Containerization

  • Docker
  • Docker Compose

📁 Project Structure

E-Commerce-Microservice
│
├── api-gateway
├── eureka-server
├── user-service
├── product-service
├── cart-service
├── order-service
│
├── docker-compose.yml
└── README.md

🔄 Order Processing Flow

Client
   │
   ▼
API Gateway
   │
   ▼
Order Service
   │
   ├────────► User Service
   │
   ├────────► Cart Service
   │
   ├────────► Product Service
   │             │
   │             └── Reserve Stock
   │
   ▼
Save Order
   │
Publish Event
   │
RabbitMQ

🎯 Learning Objectives

This project was built to gain practical experience with:

  • Microservices Architecture
  • Distributed Systems
  • API Gateway
  • Service Discovery
  • JWT Authentication
  • OAuth2
  • Keycloak
  • Event-Driven Architecture
  • RabbitMQ
  • Redis
  • Resilience4j
  • Docker
  • Production-style Backend Design

📈 Future Improvements

  • Kubernetes Deployment
  • Distributed Tracing (Zipkin/OpenTelemetry)
  • Centralized Logging (ELK Stack)
  • API Rate Limiting
  • Payment Service Integration
  • Notification Service
  • Distributed Transactions (Saga Pattern)
  • Monitoring with Prometheus & Grafana
  • CI/CD Pipeline using GitHub Actions or Jenkins

👨‍💻 Author

Suraj Mondal

Backend Developer | Java | Spring Boot | Microservices | Distributed Systems

GitHub: https://github.com/Surajhub21


⭐ If you found this project interesting, consider giving it a star!

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages