Food cart system design
Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2024-09-03
Problem Statement
Designing a Food Cart System, which allows multiple food carts (mobile vendors) in a city to register, list their menus, and serve orders placed by nearby customers through an app. The system should handle real-time order management, inventory tracking, location-based cart discovery, and payment handling while supporting scale across multiple cities.
Functional Requirements (FR)
Vendor (Food Cart) Management
•Vendors can register their carts with details (name, cuisine, location).
•Ability to update availability, menu items, and prices in real-time.
•Inventory management (track items in stock).
Customer Features
•Customers can browse and discover nearby food carts (using location).
•Customers can view menu, select items, place orders.
•Support digital payments (UPI, cards, wallets, cash on delivery).
•Track order status in real-time.
Order Management
•Support placing, updating, and canceling orders.
•Real-time communication of order status between vendor and customer.
•Handle multiple carts serving multiple customers concurrently.
Delivery / Pickup
•Customers can pick up food directly from the cart OR use third-party delivery integration.
Notifications
•Notify customers of order status changes.
•Notify vendors of new incoming orders.
Reviews & Ratings
•Customers can rate food, service, and carts.
Non-Functional Requirements (NFR)
•Scalability: Handle thousands of carts and millions of customers in a city.
•Low Latency: Real-time order updates with minimal delay (< 2s).
•Availability: High uptime for order placement and tracking.
•Consistency: Strong consistency needed for order and payment state.
•Security: Secure payments, customer data privacy, vendor authentication.
•Fault Tolerance: Ensure no order is lost during failures.
Core Components
1.User Service – Handles registration, authentication (customers & vendors).
2.Cart/Vendor Service – Manages vendor profiles, menus, availability, inventory.
3.Discovery Service – Provides location-based search for nearby food carts.
4.Order Service – Manages end-to-end order lifecycle (pending, accepted, prepared, ready, completed).
5.Payment Service – Secure integration with payment gateways, refund handling.
6.Notification Service – Push notifications, SMS, or in-app alerts for order updates.
7.Review & Rating Service – Stores feedback for vendors.
8.Analytics Service – Tracks demand, peak hours, popular carts, and sales insights.
9.Database –1. Relational DB for orders, users, and payments. 2. NoSQL/Cache for fast menu retrieval and location search.
Data Flow (High-Level)
1.Customer opens app → Discovery Service fetches nearby carts.
2.Customer selects cart → fetch menu from Vendor Service.
3.Customer places order → Order Service records it → vendor notified.
4.Vendor accepts/rejects → status update sent to customer.
5.Payment processed via Payment Service.
6.Notification Service updates both parties in real-time.
7.After completion → customer rates experience.
Key Design Challenges
•Handling real-time order updates with low latency.
•Managing dynamic locations of mobile carts (GPS tracking).
•Ensuring high availability during peak hours (e.g., lunchtime rush).
•Optimizing inventory sync when multiple customers order the same item simultaneously.
•Supporting offline carts (when vendors go temporarily offline due to network issues).