
π Retail & E-commerce Β· State Machine
Every status an online order moves through, from placed to delivered, including cancellations, returns and refunds.
Drawing diagramβ¦
State machine for an e-commerce order: Placed, Paid, Packed, Shipped, Out for delivery, Delivered. It can be Cancelled before it ships. A failed delivery retries up to 3 times, then goes back to the warehouse (RTO). A delivered order can be returned within 7 days, which leads to Refunded.
stateDiagram-v2 [*] --> Placed Placed --> Paid: Payment received Placed --> Cancelled: Payment failed Paid --> Packed Paid --> Cancelled: Customer cancels Packed --> Shipped Packed --> Cancelled: Customer cancels Shipped --> OutForDelivery OutForDelivery --> Delivered OutForDelivery --> DeliveryFailed DeliveryFailed --> OutForDelivery: Retry (max 3) DeliveryFailed --> ReturnedToWarehouse Delivered --> ReturnRequested: Within 7 days ReturnRequested --> Refunded: Item received back Cancelled --> Refunded: If paid Delivered --> [*] Refunded --> [*] ReturnedToWarehouse --> [*]
An online store split into microservices: catalog, cart, orders, payments and search, with Kafka events connecting them to shipping and notifications.
What happens when a shopper clicks Pay: stock is reserved, the payment is authorised, the order is created and stock is released again if payment fails.
A flexible product catalog: categories, products with variants (size, colour), prices, stock per warehouse and images.
How stock stays in sync across stores, warehouses and marketplaces so the same item isn't sold twice.
How an online store handles a return: eligibility, pickup, quality check at the warehouse and the refund or replacement.
How an online store builds 'recommended for you' and 'frequently bought together': click and order data, model training and a fast serving layer.