Quick Commerce System Design

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-04-02

Problem Statement

Design the Low-Level Design (LLD) of a Quick Commerce System that allows users to order groceries, essentials, and daily-use items and get them delivered within minutes from nearby dark stores or micro-fulfillment centers.


The focus should be on object-oriented design, class responsibilities, and interaction flow, not large-scale distributed architecture or database sharding (which would be part of an HLD).


🎯 Goal


Design a system that can:


β€’Allow customers to browse, search, and order products.
β€’Show real-time inventory from nearby stores.
β€’Assign delivery partners for fast dispatch.
β€’Handle order updates, payment status, and delivery tracking.
β€’Maintain inventory and stock levels across multiple stores.


βœ… Functional Requirements


1. User & Authentication


A user can:

β€’Register, login, and manage their profile.
β€’Save multiple delivery addresses.
β€’View order history and past transactions.


2. Catalog & Search


β€’System should maintain a catalog of products.
β€’Each product has:
β€’Name, description, price, quantity, image.
β€’Category (e.g., Fruits, Snacks, Beverages).
β€’Users can:
β€’Search for products by keyword or category.
β€’See nearby store availability.


3. Cart & Order Management


User can:

β€’Add/remove items from a cart.
β€’View total cost before checkout.
β€’Place an order.
β€’Order goes through these states:
β€’CREATED β†’ CONFIRMED β†’ PACKED β†’ OUT_FOR_DELIVERY β†’ DELIVERED β†’ CANCELLED


4. Inventory Management


β€’Each store maintains its own inventory.

When a user places an order:

β€’The system locks stock from the nearest store.
β€’Stock is reduced upon order confirmation.
β€’If stock is insufficient, system should suggest alternate stores.


5. Delivery Partner Assignment


Once order is ready:

β€’A delivery partner is assigned based on proximity and availability.
β€’Delivery tracking is enabled.
β€’Partners can accept/reject assignments.


6. Payment


Users can pay via:

β€’Wallet, Card, UPI, or Cash on Delivery.
β€’Payment system should handle:
β€’Payment status (PENDING / SUCCESS / FAILED).
β€’Refunds in case of cancellation.


7. Notifications


Users get real-time notifications for:

β€’Order confirmation
β€’Out for delivery
β€’Delivered / cancelled updates


βš™οΈ Non-Functional Requirements


β€’Low latency reads for product availability.
β€’Thread-safe inventory updates.
β€’Extensible to support coupons, loyalty points, and multiple cities.
β€’Reliability β€” order should never lose state due to system failure.


🧱 Key Classes to Design


ClassResponsibility


User


Represents a customer with profile, addresses, and order history.


Address


Represents user’s saved delivery locations.


Product


Represents an item in the catalog (price, stock, category).


Store


Represents a dark store or fulfillment center managing inventory.


InventoryItem


Represents product stock at a specific store.


Cart


Holds current user selections before placing an order.


Order


Represents a confirmed order and its current state.


OrderItem


Represents a product and quantity in an order.


Payment


Represents payment info, method, and status.


DeliveryPartner


Represents a delivery agent and current availability.


DeliveryAssignment


Links a delivery partner to an order.


NotificationService


Sends notifications for order state updates.


StoreSelectorService


Finds the nearest store with available stock.


🧩 Example Class Relationships

1 2User 3 β”œβ”€β”€ id 4 β”œβ”€β”€ name 5 β”œβ”€β”€ List<Address> 6 β”œβ”€β”€ Cart 7 β”œβ”€β”€ List<Order> 8 9Product 10 β”œβ”€β”€ id 11 β”œβ”€β”€ name 12 β”œβ”€β”€ description 13 β”œβ”€β”€ price 14 β”œβ”€β”€ category 15 16Store 17 β”œβ”€β”€ id 18 β”œβ”€β”€ name 19 β”œβ”€β”€ location 20 β”œβ”€β”€ List<InventoryItem> 21 22InventoryItem 23 β”œβ”€β”€ product 24 β”œβ”€β”€ quantity 25 26Order 27 β”œβ”€β”€ id 28 β”œβ”€β”€ user 29 β”œβ”€β”€ List<OrderItem> 30 β”œβ”€β”€ store 31 β”œβ”€β”€ status 32 β”œβ”€β”€ payment 33 β”œβ”€β”€ deliveryPartner 34 35DeliveryPartner 36 β”œβ”€β”€ id 37 β”œβ”€β”€ name 38 β”œβ”€β”€ currentLocation 39 β”œβ”€β”€ availabilityStatus


πŸ”„ Typical Flow


πŸ›οΈ Order Placement


1.User browses items and adds to cart.
2.System checks nearest store with available inventory.
3.User confirms order β†’ creates an Order object.


System:


β€’Locks inventory.
β€’Processes payment.
β€’Assigns a delivery partner.
β€’Sends notifications.


🚚 Delivery Flow


1.Partner accepts order β†’ status changes to OUT_FOR_DELIVERY.
2.User receives live updates.
3.Once delivered β†’ status = DELIVERED.
4.Payment finalization or refund as needed.


πŸ” Concurrency & Safety


β€’Use locks or atomic operations for inventory update.
β€’Payment and order state transitions must be idempotent.
β€’Consistent updates even under multiple order requests.


🧠 Possible Extensions


β€’Add dynamic pricing or surge handling.
β€’Add store-level load balancing.
β€’Add route optimization for delivery partners.
β€’Add order cancellation rules based on time or delivery stage.


βœ… Final Summary:


Design a Quick Commerce System that allows users to:


β€’Search and order nearby items,
β€’Manages store inventory and delivery partner assignments,
β€’Handles order state transitions, payments, and notifications.


Focus on object modeling, state management, and inventory logic, not on scaling or microservice design.

Solution

Comments