Design Food Delivery Application
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2021-08-20
Problem Statement
Design and implement the backend system for a food delivery application, supporting restaurants, menu management, order placement, delivery tracking, payments, and notifications.
Focus on object modeling, order workflow, and extensibility.
Functional Requirements (FR)
User Management
•Users can register/login.
•Manage profile (name, address, contact info, payment methods).
Restaurant & Menu Management
•Restaurants can register and manage menus.
•Menu items have attributes: name, description, price, availability.
•Support multiple categories (starter, main course, dessert).
Order Management
•Users can browse restaurants and place orders.
•Orders contain multiple items with quantity and customizations.
•Calculate total amount including taxes, discounts, delivery fee.
•Update order status: Placed → Accepted → Preparing → Out for Delivery → Delivered → Cancelled.
Delivery Management
•Assign orders to delivery partners based on location and availability.
•Track order status and delivery partner in real-time.
•Support order cancellation and refunds.
Payment Management
•Support multiple payment methods: wallet, card, UPI, cash.
•Track payment status: Pending, Success, Failed.
Notifications
•Notify users and delivery partners about order status.
•Optional: Notify restaurants about incoming orders.
Non-Functional Requirements (NFR)
•Scalability → Handle thousands of concurrent users and orders.
•Reliability → Ensure orders are not lost and payments are accurate.
•Low Latency → Real-time updates for order status and delivery tracking.
•Extensibility → Support promotions, ratings, reviews, multiple cuisines, or multi-location deliveries.
•Security → Encrypt user and payment data.
Core Entities & Attributes
User
•userId, name, email, phone, addresses[], paymentMethods[]
Restaurant
•restaurantId, name, address, menuItems[]
MenuItem
•itemId, name, description, price, category, availability
Order
•orderId, userId, restaurantId, items[], totalAmount, status, paymentStatus, deliveryPartnerId
DeliveryPartner
•partnerId, name, vehicleType, currentLocation, availabilityStatus
Payment
•paymentId, orderId, userId, amount, method, status
Core Components
OrderService
•Create, update, cancel, and track orders.
PaymentService
•Initiate, verify, and process payments.
DeliveryService
•Assign delivery partners and track delivery.
NotificationService
•Send updates via SMS, push, or email.
RestaurantService
•Manage menu and order acceptance.
APIs / Operations
User APIs
•registerUser(name, email, phone)
•updateProfile(userId, details)
•getUserOrders(userId)
Restaurant APIs
•addMenuItem(restaurantId, item)
•updateMenuItem(restaurantId, itemId, details)
•getMenu(restaurantId)
Order APIs
•placeOrder(userId, restaurantId, items)
•updateOrderStatus(orderId, status)
•cancelOrder(orderId)
•trackOrder(orderId)
Delivery APIs
•assignDeliveryPartner(orderId)
•updateLocation(partnerId, location)
Payment APIs
•initiatePayment(orderId, method)
•getPaymentStatus(paymentId)
LLD Design Goals
•Class Diagram → Entities: User, Restaurant, MenuItem, Order, DeliveryPartner, Payment, OrderService, PaymentService, DeliveryService, NotificationService.
•Design Patterns:
•Strategy → for payment methods.
•Observer → for order status notifications.
•Factory → for creating different types of orders (regular, scheduled, bulk).
•Concurrency Handling → Multiple users placing orders simultaneously; delivery partner allocation.
•Trade-offs: Pre-compute delivery ETA vs. real-time calculation, synchronous vs. asynchronous notifications.