m# Order Processing System
This system implements the Create Order distributed transaction, using Spring Boot, gRPC, and a combination of MongoDB and PostgreSQL databases. The system handles order creation, Inventory availability checks, and order status updates based on the Inventory's availability. It ensures the integrity of the transaction across multiple microservices, following the Saga Pattern for managing distributed transactions.
| Layer | Technology Used |
|---|---|
| Backend Services | Spring Boot (REST APIs, gRPC) |
| Messaging | Apache Kafka |
| Databases | MongoDB (Order Service), PostgreSQL (Inventory Service) |
| Containerization | Docker & Docker Compose |
| Build Tool | Gradle |
| gRPC Communication | Protocol Buffers (protobuf) |
| Java Version | Java 17+ |
| Monitoring | Kafdrop # Order Processing System |
A microservices-based order processing system designed to handle inventory and order management using:
- Frontend (Angular): UI for creating and viewing orders.
- Backend (Spring Boot + gRPC): Order and Inventory microservices communicating via gRPC.
- Docker: Containerized services with Docker Compose.
- Git: GitHub-based collaboration using best practices.
/order-processing-system
├── backend/
│ ├── .gradle/
│ ├── .idea/
│ ├── assets/
│ │ └── architecture.png
│ ├── build/
│ ├── gradle/
│ ├── microservices/
│ │ ├── build/
│ │ ├── orderService/
│ │ ├── inventoryService/
│ │ ├── src/
│ │ └── build.gradle
│ ├── proto-api/
│ │ └── (gRPC .proto files)
│ ├── src/
│ ├── Utils/
│ │ ├── Custom exceptions/
│ │ ├── Models and DTOs/
│ │ ├── Events/
│ │ └── Global error handling/
│ ├── create-projects.bash
│ ├── build.gradle
│ ├── settings.gradle
│ ├── gradlew
│ ├── gradlew.bat
│ ├── .gitignore
│ └── docker-compose.yml
├── frontend/
│ ├── src/
│ │ ├── app/
│ │ │ ├── core/
│ │ │ ├── shared/
│ │ │ ├── features/
│ │ │ │ ├── inventory/
│ │ │ │ └── order/
│ │ │ ├── assets/
│ │ │ └── app.component.ts
│ │ ├── assets/
│ │ ├── environments/
│ │ │ ├── environment.ts
│ │ │ └── environment.prod.ts
│ │ └── main.ts
│ ├── angular.json
│ ├── package.json
│ ├── tsconfig.json
│ ├── tsconfig.app.json
│ ├── tsconfig.spec.json
│ ├── README.md
│ └── .gitignore
-
Spring Boot microservices:
- Order Service
- Inventory Service
-
Communication via gRPC (not REST)
-
UI with:
- Form: Select product & quantity
- Table: Display orders
-
Uses Angular Services to communicate with backend via HTTP
- Define a .proto file (order.proto)
syntax = "proto3";
service OrderService {
rpc CreateOrder(OrderRequest) returns (OrderResponse);
}
message OrderRequest {
string product = 1;
int32 quantity = 2;
}
message OrderResponse {
string status = 1;
}- Dockerfile for each microservice
- docker-compose.yml to orchestrate services
- Feature branches
- Pull requests before merging
- Clear commit messages
- Spring Boot App with Order entity
- gRPC Server for order creation
✔ Outcome: POST /orders and gRPC service
- Spring Boot App with Product entity
- gRPC Server for inventory check
✔ Outcome: gRPC inventory check/update method
- Implement gRPC client in Order Service
- Order Service checks stock before placing order
✔ Outcome: Order logic based on Inventory gRPC response
- Simple UI with form & list
✔ Outcome: Submit & view orders via backend
- Dockerfile + docker-compose.yml
✔ Outcome: docker-compose up starts entire system
-
Use Git with:
- Feature branches
- PRs for merge
- Clear commit messages
✔ Outcome: Clean GitHub repo and commit history
| Layer | Technology |
|---|---|
| Backend Services | Spring Boot + gRPC |
| Databases | MongoDB, PostgreSQL |
| gRPC Communication | Protobuf (.proto) |
| Frontend | Angular |
| Messaging | Apache Kafka (optional) |
| Build Tool | Gradle |
| Containerization | Docker + Compose |
| Monitoring | Kafdrop (optional) |
./gradlew test # All services
./gradlew :microservices:orderService:test- Add Notification Service
- Use Kubernetes for orchestration
- Proto files:
proto-api/ - Angular App:
frontend/ - Microservices:
backend/microservices/
| Service Name | Description | Database |
|---|---|---|
| Order Service | Manages orders, creates new orders, and updates order status based on Inventory availability. | MongoDB |
| Inventory Service | Handles Inventory details, availability checks, and updates the Inventory's stock. | PostgreSQL |
| gRPC Method | Description |
|---|---|
getInventoryById() |
Called by the Order Service to retrieve Inventory details (including price) from the Inventory Service. |
checkInventoryAvailability() |
Used by the Order Service to check Inventory availability in the Inventory Service. |
-
Order Request:
- A new order request comes to Order Service with Inventory ID and quantity.
- The Order Service calls
getInventoryById()in the Inventory Service to fetch the Inventory details.
-
Check Inventory Availability:
- Once the Order Service has the Inventory data (including price), it proceeds to check the Inventory's availability.
- The Order Service sends a
checkInventoryAvailability()event to the Inventory Service.
-
Inventory Availability:
- If the Inventory is available:
- Inventory Service updates the Inventory stock.
- Sends a Inventory event with the
AVAILABLEstate to the Order Service. - Order Service updates the order status to
PROCESSING.
- If the Inventory is out of stock:
- Inventory Service sends a Inventory event with the
OUT_OF_STOCKstate to the Order Service. - Order Service updates the order status to
FAILED.
- Inventory Service sends a Inventory event with the
- If the Inventory is available:
-
Transaction Status:
- Order Service updates the database with the final state of the order: either
PROCESSINGorFAILED.
- Order Service updates the database with the final state of the order: either
The architecture diagram illustrates:
- Order Service calling Inventory Service via gRPC
- gRPC Methods (
getInventoryById(),checkInventoryAvailability())- The flow of events (order creation, Inventory availability check, and status update)
- MongoDB for storing order data and PostgreSQL for Inventory data
- Kafka for event messaging between services
- Docker & Docker Compose
- Java 17+
- Gradle
- Clone the repository:
git clone https://github.com/bigjohncodes/order-processing-system.git- Start the services along with the infrastructure (MongoDB, PostgreSQL, Kafka, Zookeeper, and Kafdrop) using Docker Compose:
.graddlew build
docker-compose up -d- Check if services are running:
# Check Docker containers status
docker-compose ps
# Check MongoDB status
docker exec -it mongodb mongosh -u root -p password
# Check PostgreSQL status
docker exec -it postgres psql -U postgres -d InventoryOrder- Access Kafdrop for Kafka monitoring:
- Open your browser and navigate to:
http://localhost:9000
- Open your browser and navigate to:
Example of API testing with Postman

The docker-compose.yml file sets up the following services:
| Service Name | Description | Ports |
|---|---|---|
| Zookeeper | Coordination service for Kafka | 2181 |
| Kafka | Message broker for event-driven communication | 9092 |
| MongoDB | NoSQL database for Order Service | 27017 |
| PostgreSQL | Relational database for Inventory Service | 5432 |
| Kafdrop | UI for monitoring Kafka topics and messages | 9000 |
- Network:
order-processing-network(bridge network for service communication) - Volumes:
mongodb_data: Persistent storage for MongoDBpostgres_data: Persistent storage for PostgreSQL
- Service logs are available in the console output of each service
- Infrastructure container logs can be viewed with
docker-compose logs [service-name] - Kafka topics and messages can be monitored via Kafdrop UI at
http://localhost:9000
The proto-api directory contains Protocol Buffer definitions for gRPC communication between services.
The Utils directory contains:
- Custom exception classes
- Data Transfer Objects (DTOs) and Models
- Event classes for Kafka messaging
- Global error handling components
Run tests with Gradle:
# Test all services
./gradlew test
# Test specific service
./gradlew :microservices:orderService:test
./gradlew :microservices:InventoryService:testThis project is a solution built in response to a task given and it is actively evolving. In the pipeline is the development of additional microservices including a dedicated Notification Service for order updates and an Infrastructure layer incorporating API Gateway, Circuit Breaker patterns. Kubernetes deployment configurations are also under development to enable container orchestration, autoscaling, and improved resilience for Inventoryion environments.
