sequenceDiagram
participant Customer
participant OrderService
participant InventoryService
participant PaymentService
participant NotificationService
Customer->>OrderService: Create Order
OrderService->>OrderService: Emit OrderCreated Event
OrderService->>Customer: Order Created
OrderService-->>InventoryService: OrderCreated Event
InventoryService->>InventoryService: Reserve Inventory
InventoryService->>InventoryService: Emit InventoryReserved Event
InventoryService-->>PaymentService: InventoryReserved Event
PaymentService->>PaymentService: Process Payment
PaymentService->>PaymentService: Emit PaymentProcessed Event
PaymentService-->>NotificationService: PaymentProcessed Event
NotificationService->>NotificationService: Send Confirmation Email
NotificationService->>Customer: Order Confirmed
Note right of OrderService: If any step fails
InventoryService-->>OrderService: InventoryReserveFailed Event
PaymentService-->>OrderService: PaymentFailed Event
OrderService->>OrderService: Emit OrderFailed Event
OrderService->>Customer: Order Failed
OrderService-->>NotificationService: OrderFailed Event
NotificationService->>NotificationService: Send Cancellation Email
NotificationService->>Customer: Order Cancelled
OrderService-->>InventoryService: OrderFailed Event
InventoryService->>InventoryService: Compensate Inventory
OrderService-->>PaymentService: OrderFailed Event
PaymentService->>PaymentService: Compensate Payment
sequenceDiagram
participant Customer
participant Orchestrator
participant OrderService
participant InventoryService
participant PaymentService
participant NotificationService
Customer->>OrderService: Create Order
OrderService->>Orchestrator: Order Created
Orchestrator->>InventoryService: Reserve Inventory
InventoryService->>Orchestrator: Inventory Reserved
Orchestrator->>PaymentService: Process Payment
PaymentService->>Orchestrator: Payment Processed
Orchestrator->>OrderService: Confirm Order
OrderService->>Customer: Order Confirmed
Orchestrator->>NotificationService: Send Confirmation Email
NotificationService->>Customer: Order Confirmation Sent
Note right of Orchestrator: If any step fails
Orchestrator->>PaymentService: Compensate Payment
PaymentService->>Orchestrator: Payment Compensated
Orchestrator->>InventoryService: Compensate Inventory
InventoryService->>Orchestrator: Inventory Compensated
Orchestrator->>OrderService: Cancel Order
OrderService->>Customer: Order Cancelled
Orchestrator->>NotificationService: Send Cancellation Email
NotificationService->>Customer: Order Cancellation Sent
- Spring Boot, web framework, makes it easy to create stand-alone, production-grade Spring based Applications
- Apache Kafka, a distributed and fault-tolerant stream processing system used for event-driven communication between microservices.
- Spring Cloud Netflix Eureka, a service discovery mechanism that allows microservices to find and communicate with each other without hard-coding the hostname and port.
- Spring Cloud Gateway, an api gateway that provide a simple, yet effective way to route to APIs and provide cross-cutting concerns to them such as: security, monitoring/metrics, and resiliency.
- Spring Data Redis, provides an implementation of Spring Framework’s Cache Abstraction.
- Spring Integration, provides inbound and outbound channel adapters to support the Message Queueing Telemetry Transport (MQTT) protocol.
- Resilience4j, a library that helps prevent cascading failures and provides mechanisms for graceful degradation and self-healing when external services experience issues.
- Zipkin, a distributed tracing system that provides end-to-end visibility into how requests flow through the system, helping troubleshoot issues in distributed architectures.
Spring Cloud Sleuth, autoconfiguration for distributed tracing- Micrometer Tracing with Brave, library for distributed tracing (update to Spring Boot 3.x)
- Docker and docker-compose, for containerization
- Spring Data JPA provides repository support for the Jakarta Persistence API
- Flywaydb for migrations
- Keycloak for providing authentication, user management, fine-grained authorization
- PostgreSQL
- Java 17
- Maven
- Docker
- GNU Make
- WSL (if using Windows)
-
Microservice repositories
- spring-boot-microservices : https://github.com/ericdaniel6166/spring-boot-microservices
- shared configuration files, components, etc. that can be reused in other microservices (order-service, inventory-service, etc)
- discovery-server : https://github.com/ericdaniel6166/discovery-server
- This microservice acts as a registry for all the other microservices, allowing them to find and communicate with each other.
- api-gateway : https://github.com/ericdaniel6166/api-gateway
- This microservice acts as an entry point for external requests, routing them to the appropriate microservice.
- user-service : https://github.com/ericdaniel6166/user-service
- This microservice handles user-related functionality, such as creating, reading, and updating user data.
- product-service : https://github.com/ericdaniel6166/product-service
- order-service : https://github.com/ericdaniel6166/order-service
- This microservice handles order-related functionality, such as creating, reading, and updating order data.
- inventory-service : https://github.com/ericdaniel6166/inventory-service
- This microservice handles inventory-related functionality, such as managing product stock levels.
- payment-service : https://github.com/ericdaniel6166/payment-service
- This microservice handles payment-related functionality, such as processing payments.
- notification-service : https://github.com/ericdaniel6166/notification-service
- This microservice handles notification-related functionality, such as sending confirmation and cancellation emails.
- spring-boot-microservices : https://github.com/ericdaniel6166/spring-boot-microservices
-
Make sure microservice repositories at directory as below, otherwise should change this for dev-environment setup
.
├── spring-boot-microservices
├── discovery-server
├── api-gateway
├── user-service
├── product-service
├── order-service
├── payment-service
├── inventory-service
└── notification-service
127.0.0.1 keycloak
- Docker environment
# Docker compose up
make up
# Docker compose down
make down
- Non Docker / standalone environment
# Docker compose up
make local-up
# Start discovery-server, api-gateway, user-service
# Start microservice
# Docker compose down
make local-down
Non Docker / standalone environment: http://localhost:8090/
Docker environment: http://keycloak:8090/
username/password
admin/admin
Non Docker / standalone environment: POST http://localhost:8090/realms/spring-boot-microservices-realm/protocol/openid-connect/token
Docker environment: POST http://keycloak:8090/realms/spring-boot-microservices-realm/protocol/openid-connect/token
#Basic Auth
Username="microservices-auth-client"
Password="123456789"
#form data
'grant_type="password"'
'scope="openid offline_access"'
'username="admin"'
'password="P@ssw0rd"'
- Account
username/password
admin/P@ssw0rd
customer/P@ssw0rd
guest/P@ssw0rd
http://localhost:8181/swagger-ui.html
http://localhost:9411/
http://localhost:8161/
username/password
admin/admin
- Using Offset Explorer - a GUI application for managing and using Apache Kafka clusters
Cluster name: spring-boot-microservices
Zookeeper Host: localhost
Zookeeper Port: 2181
Bootstrap servers: localhost:9092