Food Ordering System

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-04-04

Problem Statement

Design a Food Ordering System that allows customers to browse restaurants, view menus, place orders, make payments, and track delivery status.


The focus should be on object-oriented design, class structure, and interactions between components — not on UI or real-time services.


🔹 Problem Context


You are asked to design the core backend model for a food ordering platform similar to Swiggy, Zomato, or Uber Eats — focusing on how different entities (users, restaurants, food items, orders, and payments) interact.


The system should support:


•Multiple users (customers, delivery agents, and restaurants)
•Order placement and tracking
•Restaurant menu management
•Payment processing


✅ Functional Requirements


🧑‍💻 User Management


•Users can register as:
•Customers (place orders)
•Restaurants (manage menu and orders)
•Delivery Partners (deliver orders)
•A user can log in, view their profile, and access role-specific features.


🍱 Restaurant & Menu


•Each restaurant has:
•A name, location, rating, and menu.
•Each menu contains food items, each with:
•Name, description, price, category (veg/non-veg), and availability.


🛒 Ordering


•A customer can:
•Browse restaurants and their menus.
•Add items to a cart.
•Place an order for selected items.
•Once an order is placed:
•It gets assigned a status (PLACED → CONFIRMED → PREPARED → OUT_FOR_DELIVERY → DELIVERED).
•A delivery partner is assigned.


💳 Payment


•The system supports multiple payment methods (UPI, Card, Wallet, COD).
•Payment can succeed or fail; order confirmation depends on payment success.


🚚 Delivery Tracking


•Delivery partner can update status:
•Order picked up
•Order en route
•Order delivered


🧾 Order History


•Customers can view previous orders, reorder items, or rate the food and delivery.


⚙️ Non-Functional Requirements


Aspect with Description


Scalability

Should easily handle multiple restaurants and customers.


Extensibility

Support adding coupons, reviews, or loyalty programs later.


Reliability

Payment and order tracking should be consistent.


Maintainability

Clean separation between order, payment, and delivery logic.


Performance

Efficient search and filtering of restaurants/menus.


🧩 Core Classes and Responsibilities


Class with Description


User

Base class with common attributes like userId, name, email, phone.


Customer

Inherits from User; can browse, order, and pay for food.


Restaurant

Inherits from User; manages menu and accepts/rejects orders.


DeliveryPartner

Inherits from User; delivers food and updates status.


Menu

Holds a collection of MenuItem objects for a restaurant.


MenuItem

Represents a food item (name, price, category, availability).


Order

Contains details of items ordered, restaurant, customer, total amount, and status.


Cart

Temporarily stores selected items before order confirmation.


Payment

Handles payment logic, including type (UPI, card, etc.) and status (SUCCESS, FAILED).


OrderStatus (enum)

Defines order stages: PLACED, CONFIRMED, PREPARED, OUT_FOR_DELIVERY, DELIVERED.


PaymentType (enum)

Defines payment modes: CARD, UPI, WALLET, COD.


DeliveryService

Manages delivery assignment and updates.


OrderService

Handles order creation, update, and retrieval logic.


🧠 Key Design Considerations


•Use Composition for relationships (e.g., Restaurant → Menu → MenuItem).
•Apply Strategy Pattern for payment processing (different payment methods).
•Use Observer Pattern for notifying customers about order status changes.
•Consider Enum-based state machine for managing order statuses.
•Use Factory Pattern for creating different user types (Customer, Restaurant, etc.).


💻 Example Scenario


1.A customer browses restaurants nearby.
2.The customer selects a restaurant, views the menu, and adds items to the cart.
3.The customer places the order and makes a payment using UPI.
4.The restaurant receives the order and updates it to PREPARED once ready.
5.A delivery partner is assigned to pick up and deliver the order.
6.The customer tracks the order in real time and receives it as DELIVERED.
7.The customer can rate the restaurant and delivery.


🔮 Extensions


•Add coupons, offers, or referral codes.
•Integrate reviews and ratings for restaurants and delivery partners.
•Introduce real-time notifications for order updates.
•Add restaurant search filters (cuisine, rating, distance, price range).
•Support scheduled deliveries.


💬 Interview Prompt Summary

Design a Food Ordering System that enables users to browse restaurants, add items to a cart, place orders, and make payments.
Focus on class relationships and responsibilities for User, Restaurant, Menu, Order, Payment, and Delivery.
Ensure the system is extensible and maintainable.


Solution

Comments