Quantity Service: Responsible only to add or return quantity of a product.
Cart Service:
- adds list of products to a cart for a customer (has to be persisted into DB)
- triggers payment request on checkout, updates the available and reserved products count.
- listens to product status events, notify user with the status of checkout request
checkout/order-assignment service:
- listens to payment events
- monitors the orders and payments, assigns the order to user if payment is successful
- publish a kafka event for product status
Workflow:
-
user adds the products to cart.
-
user sends checkout request, the request comes to cart service.
-
cart service checks in redis (the available count) if the product is available or not.
-
if product is neither available nor reserved, it returns the appropriate error message
-
if the product is not available but reserved, it waits for 10 seconds to check if product becomes available due to cancellation, payment failures.
-
if product is available, an order is created in redis with progressing state.
-
the checkout service keeps checking all the orders status, status might get changed to success/failure due to payment events.
-
order cancellation can be handelled in checkout service.
-
if the order is successful or failed, it's removed from redis and can be persisted in sql db. a kafka event is published for the product status.
-
it also checks for time of creation, if time is more than 2 minutes, it cancels the order and any successful payment prior to that gets refunded.