Design a food delivery app (like Swiggy/Zomato)

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

Problem Statement

Design a low-level architecture for a food delivery system that allows users to browse restaurants, place orders, track delivery in real-time, and handle payments. The system should manage multiple restaurants, delivery partners, and concurrent orders efficiently.


Functional Requirements (FR)


User Management


•Users can register/login using email, phone, or social accounts.
•Maintain user profile with address and payment details.


Restaurant Management


•Restaurants can manage their menu, availability, and prices.
•Menu items have attributes like name, price, category, and preparation time.


Order Management


•Users can add items to cart and place orders.
•Orders go through states: Pending, Confirmed, Preparing, Out for Delivery, Delivered, Cancelled.


Delivery Management


•Assign delivery partner based on location, availability, and load.
•Track delivery partner location and ETA.


Payment Management


•Support multiple payment methods: cards, wallets, UPI, COD.
•Handle payment verification and order confirmation.


Notifications


•Notify users about order confirmation, preparation, dispatch, and delivery.


Reviews & Ratings


•Users can rate restaurants and delivery partners.


Search & Filters


•Search restaurants by name, cuisine, or ratings.
•Apply filters like cost, delivery time, and offers.


Non-Functional Requirements (NFR)


•Scalability → Handle millions of users, restaurants, and orders.
•Low Latency → Quick response for menu, search, and order tracking.
•High Availability → 24/7 uptime with redundancy.
•Consistency → Accurate inventory and order status.
•Security → Secure authentication, authorization, and payment processing.


Core Classes & Entities


User


•userId, name, email, phone, addresses, paymentMethods


Restaurant


•restaurantId, name, location, menuItems, ratings


MenuItem


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


Order


•orderId, userId, restaurantId, items, totalAmount, status, paymentId


DeliveryPartner


•partnerId, name, currentLocation, availabilityStatus


Payment


•paymentId, orderId, amount, status, method


Notification


•notificationId, userId, message, timestamp


Key Methods / Operations


User Service


•registerUser(), loginUser(), getUserProfile()


Restaurant Service


•addMenuItem(), updateMenuItem(), getMenu(restaurantId)


Order Service


•placeOrder(userId, restaurantId, itemList)
•updateOrderStatus(orderId, status)
•trackOrder(orderId)


Delivery Service


•assignDeliveryPartner(orderId)
•updateDeliveryLocation(orderId, partnerLocation)


Payment Service


•processPayment(orderId, amount, method)
•verifyPayment(paymentId)


Notification Service


•sendNotification(userId, message)


Design Considerations


Concurrency & Inventory Management


•Handle multiple users ordering the same items simultaneously.
•Real-time inventory updates at restaurant level.


Delivery Assignment Algorithm


•Assign nearest available delivery partner with load balancing.


Scalability & Caching


•Cache restaurant menus, popular items, and search results.


Fault Tolerance & Retry Mechanisms


•Handle failed payments, delivery partner failures, and network issues.


Extensibility


•Support promotions, loyalty points, subscription models, and multi-city expansion.


Example Flow


1.User opens app → Searches for restaurants → Restaurant Service returns menu.
2.User adds items to cart → Order Service calculates total → Payment Service processes payment.
3.Payment success → Order status updated → Delivery Service assigns partner.
4.Partner picks up order → Updates location → User tracks order in real-time.
5.Order delivered → Status updated → Notification sent → User can rate order/restaurant.


Solution

Comments