This project demonstrates a real-time order processing system using gRPC with Node.js. It consists of four microservices: Inventory, Notification, Order, and Payment. Each service exposes a gRPC API for interaction.
- Inventory Service: Manages product availability and quantity.
- Order Service: Handles order creation and status retrieval.
- Notification Service: Sends notifications related to orders.
- Payment Service: Processes payments for orders.
Each microservice is independent and communicates using gRPC. The services are designed to be modular and scalable.
Before running the services, install the required dependencies:
npm install @grpc/grpc-js @grpc/proto-loader grpc-node-server-reflection
Proto Definition: order.proto
Endpoints:
CreateOrder
GetOrderStatus
Commands:
# List services
./grpcurl -plaintext 127.0.0.1:50051 list
# Describe the OrderService
./grpcurl -plaintext 127.0.0.1:50051 describe order.OrderService
# Describe CreateOrderRequest
./grpcurl -plaintext 127.0.0.1:50051 describe order.CreateOrderRequest
# Create an order
./grpcurl -plaintext -d '{"customer_id": "12345", "items": ["item1", "item2"]}' 127.0.0.1:50051 order.OrderService/CreateOrder
# Get order status
./grpcurl -plaintext -d '{"order_id": "order-1734601337651"}' 127.0.0.1:50051 order.OrderService/GetOrderStatus
# Test invalid order ID
./grpcurl -plaintext -d '{"order_id": "invalid-id"}' 127.0.0.1:50051 order.OrderService/GetOrderStatus
Proto Definition: inventory.proto
Endpoints:
CheckAvailability
Commands:
# List services
./grpcurl -plaintext 127.0.0.1:50052 list
# Describe the InventoryService
./grpcurl -plaintext 127.0.0.1:50052 describe inventory.InventoryService
# Describe CheckAvailabilityRequest
./grpcurl -plaintext 127.0.0.1:50052 describe inventory.CheckAvailabilityRequest
# Describe CheckAvailabilityResponse
./grpcurl -plaintext 127.0.0.1:50052 describe inventory.CheckAvailabilityResponse
# Check item availability
./grpcurl -plaintext -d '{"item":"item1"}' 127.0.0.1:50052 inventory.InventoryService/CheckAvailability
Proto Definition: notification.proto
Endpoints:
SendNotification
Commands:
# List services
./grpcurl -plaintext 127.0.0.1:50053 list
# Describe SendNotificationRequest
./grpcurl -plaintext 127.0.0.1:50053 describe notification.SendNotificationRequest
# Describe SendNotificationResponse
./grpcurl -plaintext 127.0.0.1:50053 describe notification.SendNotificationResponse
# Send a notification
./grpcurl -plaintext -d '{"order_id": "order-123", "message": "Your order has been shipped!"}' 127.0.0.1:50053 notification.NotificationService/SendNotification
Proto Definition: payment.proto
Endpoints:
ProcessPayment
Commands:
# List services
./grpcurl -plaintext 127.0.0.1:50054 list
# Describe ProcessPaymentRequest
./grpcurl -plaintext 127.0.0.1:50054 describe payment.ProcessPaymentRequest
# Describe ProcessPaymentResponse
./grpcurl -plaintext 127.0.0.1:50054 describe payment.ProcessPaymentResponse
# Process a payment
./grpcurl -plaintext -d '{"order_id": "order-123", "amount": 15}' 127.0.0.1:50054 payment.PaymentService/ProcessPayment
-
Clone the repository:
git clone https://github.com/JawherKl/api-design.git cd grpc/nodejs/order-process-system
-
Install dependencies for each service:
cd <service-folder> npm install
-
Start the services:
node server.js
-
Test the gRPC APIs using the commands provided above.
Contributions are welcome! Please follow the contribution guidelines in the repository.
This project is licensed under the MIT License. See the LICENSE file for details.