Design food ordering system for 1000 restaurants in a city

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2021-09-20

Problem Statement

Design and implement a scalable, modular food ordering system that allows users to browse menus, place orders, and track delivery from 1000 restaurants. Focus on object-oriented design, order lifecycle, restaurant/menu management, and user experience.


Functional Requirements (FR)


User Management


•Users can register/login and maintain profiles.
•Save delivery addresses and payment methods.


Restaurant & Menu Management


•Each restaurant maintains:
•Menu items, categories, prices.
•Opening hours and availability.
•Restaurants can update menu and status (open/closed).


Order Management


•Users can browse restaurants and place orders.
•Orders contain multiple menu items, quantities, and special instructions.
•Order states: PLACED → CONFIRMED → PREPARING → OUT_FOR_DELIVERY → DELIVERED → CANCELLED.
•Track order history.


Delivery Management


•Assign delivery personnel to orders.
•Track delivery status and estimated time.
•Handle order cancellations or failed deliveries.


Payment Management


•Support online payments, wallets, and cash on delivery.
•Generate invoices for orders.


Notifications


•Notify users and restaurants on order status changes.
•Optional SMS/push notifications for delivery updates.


Non-Functional Requirements (NFR)


•Scalability → Support 1000+ restaurants and thousands of concurrent users.
•Availability → System should be available 24/7.
•Low Latency → Fast menu retrieval and order placement.
•Consistency → Orders and payments should remain consistent.
•Extensibility → Add new features like ratings, reviews, or discounts.


Core Entities & Attributes


User


•userId, name, email, phone, addressList, paymentMethods


Restaurant


•restaurantId, name, location, menu[], isOpen


MenuItem


•itemId, restaurantId, name, category, price, availability


Order


•orderId, userId, restaurantId, items[], totalAmount, status, timestamp, deliveryPersonId


DeliveryPerson


•deliveryPersonId, name, location, status (AVAILABLE/BUSY)


Payment


•paymentId, orderId, amount, method, status


Core Components


UserService


•Manages user profiles, addresses, and preferences.


RestaurantService


•Manages restaurant data, menus, and availability.


OrderService


•Handles order creation, state transitions, and tracking.


DeliveryService


•Assigns delivery personnel and tracks delivery status.


PaymentService


•Processes payments and refunds.


NotificationService


•Sends updates to users and restaurants.


APIs / Operations


User APIs


•createUser(name, email, phone)
•updateUser(userId, details)
•getUserOrders(userId)


Restaurant APIs


•getRestaurants(location)
•getMenu(restaurantId)
•updateMenu(restaurantId, menu)


Order APIs


•placeOrder(userId, restaurantId, items)
•updateOrderStatus(orderId, status)
•getOrderStatus(orderId)


Delivery APIs


•assignDelivery(orderId)
•updateDeliveryStatus(orderId, status)


Payment APIs


•processPayment(orderId, method, amount)
•refundPayment(orderId)


LLD Design Goals


•Class Diagram → User, Restaurant, MenuItem, Order, DeliveryPerson, Payment, Services.


Design Patterns:


•Observer → Notify users/restaurants on order updates.
•Factory → For creating orders, payments, and delivery assignments.
•Singleton (Optional) → For centralized services like NotificationService.
•Concurrency Handling → Thread-safe order creation and delivery assignment.
•Trade-offs →1. Real-time order tracking vs. performance overhead.

2.Denormalized vs. normalized menu/order storage for faster queries.


Solution

Comments