This project is an E-commerce System implemented as a set of microservices using Spring Boot and Kafka messaging. The system comprises three microservices, each serving a specific function: Inventory, Order, and Payment.
The project aims to demonstrate the concept of microservices communication and transactional consistency using the SAGA pattern. Microservice A acts as the orchestrator and communicates with two independent microservices, B and C, through Kafka messages. The system is also secured using Spring Security.
- Inventory Service (Service B): Manages product inventory and stock.
- Order Service (Service A): Orchestrates the order creation process.
- Payment Service (Service C): Handles payment transactions.
Access to the API is secured using Spring Security. Users need to authenticate to access the endpoints.
- POST /api/v1/auth/login - Authenticates a user. Default user credentials:
{
"username": "username",
"password": "password"
}
-
POST /api/v1/orders - Creates an order. Request body format:
{ "productCount" : 4, "customerId" : 3, "productId" : 2, "totalPrice" : 18.90 }
-
GET /api/v1/orders/{id} - Retrieves the status of an order. For instance:
{ "id": 1, "productCount": 4, "customerId": 3, "productId": 2, "totalPrice": 18.9, "orderStatus": "in process", "paymentStatus": "in process", "inventoryStatus": "in process" }
Unit and integration tests have been implemented to ensure the reliability and correctness of the services. Kafka integration tests are carried out using Testcontainers.
The services, Kafka, and the database are deployed in a local Kubernetes cluster using Minikube. This deployment demonstrates a local containerized environment.
You must have minikube, kubectl, gradle and docker installed on your computer.
- Clone project and go to root folder
- Run minikube
minikube start
- Deploy all infrastructure in kubernetes
kubectl apply -f k8s/minikube/ --recursive
- Route LoadBalancer service to be able to connect to it locally
minikube tunnel
- Check external-ip exposed to service
order
deployment and use it as host
kubectl get svc
- Spring Boot: For building microservices.
- Kafka: For asynchronous messaging.
- Spring Security: For securing the API.
- PostgreSQL: As the database.
- Data JPA: For data access.
- Testcontainers: For integration testing.
- Minikube: For local Kubernetes deployment.