How subramanyabengaluru/e-commerce-microservices works
Purpose and topology
A Maven multi-module Java 21/Spring Boot 3.5 e-commerce backend. The active architecture is independently deployable Spring Cloud services; monolith/ is a retained reference implementation. Primary client entry point is the gateway (:8080); service bootstrap entry points are each *Application.java, e.g. api-gateway/src/main/java/com/ecommerce/gateway/ApiGatewayApplication.java and order-service/src/main/java/com/ecommerce/orderservice/OrderServiceApplication.java.
Edge security and routing
The reactive API gateway validates bearer JWTs, applies security policy, injects trusted user identity headers, and routes to discovered services. Downstream services therefore rely on propagated identity rather than independently authenticating requests.
• api-gateway/src/main/java/com/ecommerce/gateway/config/RouteConfig.java
• api-gateway/src/main/java/com/ecommerce/gateway/security/GatewaySecurityConfig.java
• api-gateway/src/main/java/com/ecommerce/gateway/security/JwtAuthenticationFilter.java
Platform control plane and shared contracts
Config Server serves common and per-service external configuration from the repository-local config set; Eureka supplies registration and discovery. platform-common defines cross-service event, exception, paging, roles, and gateway-header contracts, preventing direct sharing of domain models.
• config-server/src/main/java/com/ecommerce/configserver/ConfigServerApplication.java
• discovery-server/src/main/java/com/ecommerce/discovery/DiscoveryServerApplication.java
• config-repo/application.yml
• platform-common/src/main/java/com/ecommerce/common/event/OrderEvent.java
• platform-common/src/main/java/com/ecommerce/common/web/GatewayHeaders.java
Identity, catalog, and stock ownership
User Service owns registration/login and JWT issuance. Product Service owns catalog writes and cached catalog reads, enriching product information through Inventory Service. Inventory Service exclusively owns stock mutation and exposes internal-facing operations for initialization and checkout adjustments. Service-to-service calls use OpenFeign/load balancing with Resilience4j boundaries; product reads may degrade when inventory is unavailable.
• user-service/src/main/java/com/ecommerce/userservice/user/AuthService.java
• product-service/src/main/java/com/ecommerce/productservice/product/ProductService.java
• product-service/src/main/java/com/ecommerce/productservice/product/ProductCacheService.java
• inventory-service/src/main/java/com/ecommerce/inventoryservice/inventory/InventoryService.java
Cart and transactional order workflow
Cart Service owns per-user carts and validates product references through Product Service. Order Service orchestrates checkout: retrieve cart lines, obtain product data, decrement inventory, persist order/item snapshots, clear the cart, and publish an order event. Cancellation reverses stock. These synchronous dependencies are correctness-critical and should fail rather than silently degrade.
• cart-service/src/main/java/com/ecommerce/cartservice/cart/CartService.java
• order-service/src/main/java/com/ecommerce/orderservice/order/OrderService.java
• order-service/src/main/java/com/ecommerce/orderservice/client/CartClient.java
• order-service/src/main/java/com/ecommerce/orderservice/client/InventoryClient.java
Event projections and side effects
Product Service publishes catalog-change events; Search Service consumes them to maintain an Elasticsearch ProductDocument read model, with a catalog backfill path for reconstruction. Order Service publishes order events consumed by Notification Service. Kafka is the asynchronous boundary: search and notifications are eventually consistent and decoupled from write requests.
• product-service/src/main/java/com/ecommerce/productservice/event/ProductEventPublisher.java
• search-service/src/main/java/com/ecommerce/searchservice/event/ProductEventListener.java
• search-service/src/main/java/com/ecommerce/searchservice/search/ProductDocument.java
• order-service/src/main/java/com/ecommerce/orderservice/event/OrderEventPublisher.java
• notification-service/src/main/java/com/ecommerce/notificationservice/event/OrderEventListener.java
Runtime infrastructure and observability
Business services persist independently in PostgreSQL; Redis supports catalog/cart caching, Kafka carries domain events, and Elasticsearch serves search. Docker Compose provisions those dependencies plus Prometheus, Grafana, and Zipkin. Services export metrics and traces, including Feign/gateway request chains and resilience signals.
• docker-compose.infra.yml
• docker/postgres/init-databases.sql
• docker/prometheus/prometheus.yml
• docker/grafana/provisioning/dashboards/ecommerce-overview.json
Main entry points: ProductService.java Product Service · OrderService.java Order Service · RouteConfig.java API Gateway · ConfigServerApplication.java Config Server
Components 18
Platform control plane
- Config Server · Serves shared and per-service external configuration.
config-server/src/main/java/com/ecommerce/configserver/ConfigServerApplication.java - Config set
config-repo/application.yml - Eureka
discovery-server/src/main/java/com/ecommerce/discovery/DiscoveryServerApplication.java - Platform contracts · Events, errors, paging, roles, and trusted gateway headers.
platform-common/src/main/java/com/ecommerce/common/web/GatewayHeaders.java
Edge and business services
- API Gateway · Validates JWTs, injects identity headers, and routes requests.
api-gateway/src/main/java/com/ecommerce/gateway/config/RouteConfig.java - User Service · Owns registration, login, and JWT issuance.
user-service/src/main/java/com/ecommerce/userservice/user/AuthService.java - Product Service · Owns catalog writes and enriches product reads with stock data.
product-service/src/main/java/com/ecommerce/productservice/product/ProductService.java - Catalog cache · Cached catalog reads may degrade if inventory is unavailable.
product-service/src/main/java/com/ecommerce/productservice/product/ProductCacheService.java - Inventory Service · Exclusively owns stock mutations and checkout adjustments.
inventory-service/src/main/java/com/ecommerce/inventoryservice/inventory/InventoryService.java - Cart Service · Owns per-user carts and validates product references.
cart-service/src/main/java/com/ecommerce/cartservice/cart/CartService.java - Order Service · Persists order snapshots and coordinates correctness-critical checkout calls.
order-service/src/main/java/com/ecommerce/orderservice/order/OrderService.java
Event projections
- Search Service · Maintains the Elasticsearch product read model and supports backfill.
search-service/src/main/java/com/ecommerce/searchservice/event/ProductEventListener.java - Notification Service · Handles order-event side effects.
notification-service/src/main/java/com/ecommerce/notificationservice/event/OrderEventListener.java
Runtime infrastructure
- PostgreSQL · Each business service persists independently.
docker/postgres/init-databases.sql - Redis · Supports catalog and cart caching.
docker-compose.infra.yml - Kafka · Asynchronous boundary for catalog and order events.
docker-compose.infra.yml - Elasticsearch
docker-compose.infra.yml - Prometheus, Grafana & Zipkin · Collects metrics, traces, and resilience signals.
docker/prometheus/prometheus.yml
Connections 32
- Config set → Config Server: served as external config
- Config Server → API Gateway: configuration
- Config Server → User Service: configuration
- Config Server → Product Service: configuration
- Eureka → API Gateway: route discovery
- Eureka → User Service: registration
- Eureka → Product Service: registration
- Platform contracts → API Gateway: trusted identity headers
- Platform contracts → Order Service: order event contract
- API Gateway → User Service: authenticated requests
- API Gateway → Product Service: authenticated requests
- API Gateway → Cart Service: authenticated requests
- API Gateway → Order Service: authenticated requests
- Product Service → Catalog cache: cached reads
- Product Service → Inventory Service: stock enrichment
- Cart Service → Product Service: validate product references
- Order Service → Cart Service: retrieve and clear cart
- Order Service → Product Service: obtain product data
- Order Service → Inventory Service: decrement or restore stock
- Product Service → Kafka: catalog-change events
- Kafka → Search Service: catalog events
- Order Service → Kafka: order events
- Kafka → Notification Service: order events
- Search Service → Elasticsearch: product documents
- User Service → PostgreSQL: identity data
- Product Service → PostgreSQL: catalog data
- Inventory Service → PostgreSQL: stock data
- Cart Service → Redis: cart cache
- Catalog cache → Redis: catalog cache
- Order Service → PostgreSQL: orders and item snapshots
- API Gateway → Prometheus, Grafana & Zipkin: metrics and traces
- Order Service → Prometheus, Grafana & Zipkin: metrics and traces