Design a system for online grocery delivery

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-05-26

Problem Statement

Design and implement a system for online grocery ordering and delivery. The system should handle user accounts, product catalog, cart management, order placement, payment processing, and delivery tracking, while ensuring consistency, reliability, and scalability.


🔶 Functional Requirements


1.User Management
•Users can register, login, and maintain profiles.
•Manage multiple delivery addresses.
•Maintain order history and track active orders.
2.Product & Inventory Management
•Add, update, and delete grocery items (name, category, price, stock, offers).
•Track inventory in real-time across multiple stores or warehouses.
•Notify users of out-of-stock items or low-stock alerts.
3.Search & Catalog
•Search products by name, category, brand, or price.
•Filter products by availability, discounts, and ratings.
4.Cart & Order Management
•Add/remove/update items in cart.
•Place orders with selected products and delivery details.
•Support scheduled delivery or immediate delivery.
5.Payment Processing
•Support multiple payment methods: Cards, UPI, Wallets, Cash on Delivery.
•Handle payment success/failure gracefully.
6.Delivery & Tracking
•Assign delivery personnel or partner logistics.
•Update order status: Placed → Packed → Out for Delivery → Delivered.
•Provide live tracking for users.
7.Optional Extensions
•Recommendations based on purchase history.
•Promotional offers, coupons, and loyalty points.
•Handling perishable items with priority delivery.


🔶 Non-Functional Requirements


•Concurrency: Multiple users can browse, order, and pay simultaneously.
•Scalability: Handle thousands of users and orders concurrently.
•Consistency: Ensure accurate inventory updates during high-demand periods.
•Fault Tolerance: Orders and payments must be reliable; retry mechanisms for failures.
•Extensibility: Easy to add new stores, product categories, or delivery partners.


🔶 Constraints


•Each product has limited stock, which should not be oversold.
•Users can have only one active order for the same time slot.
•Payment transactions must be atomic and consistent.
•Delivery assignment must optimize for proximity and availability of delivery personnel.


🔶 Example Use Cases


1.User searches for “Organic Apples” → adds 2 kg to cart → places an order for same-day delivery.
2.System checks inventory → confirms availability → processes payment → assigns delivery person.
3.User tracks the order in real-time and receives a notification upon delivery.
4.User cancels order before dispatch → system updates inventory and refunds payment.


👉 In short:

Design a system for online grocery delivery that manages products, inventory, user orders, payments, and delivery tracking, ensuring concurrency, consistency, scalability, and a smooth user experience.

Solution

Comments