For the given e-commerce user flow, the following microservices are identified based on core domain responsibilities, separation of concerns, and future scalability. Each microservice encapsulates a bounded context with its own data store and business logic.
-
Responsibilities:
- Validates user login credentials.
- Mocks token/session generation.
- Provides user identity to other services.
-
Responsibilities:
- Maintains the catalog of products.
- Allows querying products by name or category.
- Provides detailed product information.
-
Responsibilities:
- Manages user shopping cart.
- Adds/removes items and retrieves cart content.
-
Responsibilities:
- Initiates order placement.
- Validates cart contents.
- Orchestrates inventory check and mock payment.
- Manages order status transitions.
-
Responsibilities:
- Maintains inventory stock levels.
- Supports reserving and releasing stock.
-
Responsibilities:
- Sends/logs notifications based on order events.
- Supports logging for audit purposes.
-
Responsibilities:
- Acts as the single entry point for external clients.
- Routes requests to respective services.
- Handles cross-cutting concerns (rate limiting, caching, load balancing).
POST /auth/login
{
"username": "john_doe",
"password": "mock123"
}
Response:
{
"token": "mock-jwt-token"
}
GET /products?name=shoes&category=sports
Response: [ { product } ]
GET /products/{productId}
Response: { product }
- User id will be retrieved from access token provided in request header
POST /cart/add
{
"productId": "prod-001",
"quantity": 2
}
Response: { "message": "Product added to cart" }
GET /cart/
Response: { "userId": "user-123", "items": [ ... ] }
POST /orders
{
"cartId": "cart-123"
}
Response (success): { "orderId": "order-987", "status": "confirmed" }
Response (failure): { "status": "cancelled" }
POST /inventory/check
{
"productId": "prod-001", "quantity": 2
}
I am using message broker for notification
publish events
{
"userId": "user-123",
"type": "order_success",
"message": "Order confirmed."
}
- RESTful HTTP: All services communicate via RESTful HTTP APIs.
- Synchronous communication: Order Service calls Inventory and Notification services directly using http client.
-
User adds product to cart via Cart Service.
-
User places order via Order Service:
- Order Service calls Cart Service to get cart items.
- Calls Inventory Service to check items availability.
- Mocks payment logic.
- If successful: creates order and calls Notification Service.
- If failed: calls Notification Service with cancellation.
- Authentication JWT based access
- Inventory system holds product ID and stock only (no full product info).
- Notification system is a logger (no real email/SMS integration).
- No orchestration tool like Saga or choreography; Order Service drives the transaction.
- Each microservice has its own database (In-memory).
+-------------------+
| API Gateway |
+--------+----------+
|
+------------------------+------------------------+
| | |
+---------------+ +------------------+ +-------------------+
| Auth Service | | Product Service | | Cart Service |
+---------------+ +------------------+ +-------------------+
|
v
+-------------------+
| Order Service |
+-------------------+
/ \
v v
+----------------+ +--------------------+
| Inventory Svc | | Notification Svc |
+----------------+ +--------------------+
- GatewayService
- UserService
- ProductService
- CartService
- OrderService
- InventoryService
- PaymentService
- NotificationService
docker compose -f prod.docker-compose.yml updocker compose -f prod.docker-compose.yml down- Need to clear cart after order created
- Need to update inventory after payment successful
- Need to update order status after payment [success / failure]