Skip to content

Rafael-Bessa/ecommerce-microservices-spring

Repository files navigation

🛒 ecommerce-microservices-spring

Java Spring Boot Spring Cloud MySQL SQL Server Resilience4j Flyway

E-commerce backend built with Java, Spring Boot and Microservices architecture.


📐 Architecture

Client
  │
  ▼
┌─────────────────────┐
│    API Gateway       │  ← Spring Cloud Gateway (port 8080)
└─────────┬───────────┘
          │
    ┌─────┴──────┐
    ▼            ▼
┌────────┐  ┌────────┐
│Product │  │ Order  │
│Service │  │Service │
│ :8081  │  │ :8082  │
└────────┘  └────────┘
    │            │
  MySQL      SQL Server

          ◎ Eureka Server (port 8761)
          All services registered

🧩 Services

Service Port Database Description
eureka-server 8761 Service Discovery
api-gateway 8080 API Gateway & routing
product-service 8081 MySQL Product catalog management
order-service 8082 SQL Server Order processing

🛠️ Tech Stack

  • Java 17 + Spring Boot 4 + Spring Framework 7
  • Spring Cloud Gateway — API Gateway with load balancing
  • Netflix Eureka — Service Discovery
  • OpenFeign — Declarative HTTP client for inter-service communication
  • Resilience4j — Circuit Breaker pattern
  • Flyway — Database migrations
  • MySQL — Product Service database
  • SQL Server — Order Service database

🚀 Getting Started

Prerequisites

  • Java 17+
  • Maven
  • MySQL running on port 3306
  • SQL Server running on port 1433

Running the services

Start in this exact order:

# 1. Eureka Server
cd eureka-server && mvn spring-boot:run

# 2. Product Service
cd product-service && mvn spring-boot:run

# 3. Order Service
cd order-service && mvn spring-boot:run

# 4. API Gateway
cd api-gateway && mvn spring-boot:run

Eureka Dashboard

http://localhost:8761

📡 API Endpoints

All requests go through the API Gateway at http://localhost:8080

Products

Method Endpoint Description
GET /products List all products
GET /products/{id} Get product by ID
POST /products Create product
PUT /products/{id} Update product
DELETE /products/{id} Delete product

Orders

Method Endpoint Description
GET /orders List all orders
GET /orders/{id} Get order by ID
POST /orders Create order

🔁 Inter-service Communication

The Order Service communicates with the Product Service via Feign Client. Errors are translated into domain exceptions by a custom ErrorDecoder:

  • 404ProductNotFoundException → returns 404 to the client
  • 503ProductServiceUnavailableException → returns 503 to the client

⚡ Resilience

  • Circuit Breaker via Resilience4j protects inter-service calls
  • Custom GlobalExceptionHandler ensures consistent error responses across all services

🗂️ Error Response Format

{
  "error": "Produto não encontrado com o id informado",
  "status": 404,
  "timestamp": "2026-03-10T09:54:00.000"
}

🗺️ Roadmap

  • Service Discovery with Eureka
  • API Gateway with Spring Cloud Gateway
  • Inter-service communication with Feign Client
  • Circuit Breaker with Resilience4j
  • Database migrations with Flyway
  • Redis caching
  • Async messaging with RabbitMQ
  • Docker Compose setup
  • Distributed tracing with Zipkin

Made with ❤️ by Rafael Bessa

About

E-commerce backend with Java, Spring Boot, Microservices, API Gateway, Eureka, Feign Client and Resilience4j.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors