Senior
The product came with a request to develop a Loyalty service, which based on the number of delivered orders (master system for orders OMS) will give the order processing service (cashier) a discount amount. The Loyalty service will not have a front-end part for now, only in the database, a mapping of how much discount corresponds to the number of delivered and not canceled orders should be stored. Something like Orders Discount [phone]% [phone]% [phone]% [phone]% It is necessary to design the service, propose integration mechanisms with the Order Processing Service and the Order Management Service. Design the architecture of the service that can be handed over to the development and deployment team.
sobes.tech AI
Answer from AI
The following architecture and integration are proposed for the Loyalty service:
Architecture of the Loyalty Service
-
Data Storage: a table in the database with a mapping of the number of delivered and non-canceled orders to the discount size.
CREATE TABLE loyalty_discounts ( min_orders INT PRIMARY KEY, discount_percent DECIMAL(5,2) ); -
Service API: REST or gRPC interface providing a method to get the discount based on the number of orders.
// Example method in Java public BigDecimal getDiscount(int deliveredOrders) { // Logic to select the maximum discount where min_orders <= deliveredOrders }
Integration with other services
-
Order Management Service (OMS):
- Responsible for tracking and updating order statuses.
- Sends an event (e.g., via Kafka or RabbitMQ) to the Loyalty service when the order status changes (delivered, canceled).
-
Loyalty Service:
- Subscribes to OMS events.
- Updates internal data on the number of delivered orders for each user.
-
Order Placement Service (cashier):
- When placing an order, requests the discount size from the Loyalty service using the user ID.
- Applies the discount to the order.
Additional
- Use caching in the Loyalty service to speed up responses.
- Ensure idempotency in event processing from OMS.
- Implement logging and monitoring to track correct operation.
This approach will separate the discount business logic from the main services, ensuring scalability and ease of maintenance.