High-Level Design question related to Swiggy

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

Problem Statement

Design a scalable, high-performance food delivery platform similar to Swiggy, allowing users to browse restaurants, place orders, track delivery in real-time, and handle payments. Focus on components, APIs, data flow, and scalability rather than detailed implementation.


Functional Requirements (FR)


User & Customer Management


•Users can register/login via email, phone, or social login.
•Maintain user profile: name, addresses, payment methods, order history.


Restaurant & Menu Management


•Restaurants can register and manage menu items.
•Menu includes items, prices, availability, categories.
•Support dynamic offers/discounts.


Order Management


•Users can browse restaurants by location and cuisine.
•Place orders with multiple items.
•Track order status: Placed → Accepted → Preparing → Out for Delivery → Delivered.
•Cancel orders before a specific stage.


Delivery Management


•Assign delivery partners (riders) based on proximity, availability, and workload.
•Real-time tracking of delivery location.
•Update estimated delivery time dynamically.


Payment Management


•Support multiple payment methods (card, wallet, UPI, cash).
•Ensure secure transactions.
•Refund/cancellation handling.


Notifications & Alerts


•Notify users and restaurants about order updates.
•Notify delivery partners of new assignments.


Non-Functional Requirements (NFR)


•Scalability – Support millions of users and thousands of concurrent orders.
•Availability – High uptime, especially during peak hours.
•Low Latency – Fast menu browsing, order placement, and tracking.
•Consistency – Ensure no double booking of delivery partners or order conflicts.
•Reliability – Ensure order, payment, and delivery status are accurate.


Core Components


Component Responsibilities

User Service Manage user profiles, addresses, payment methods, and order history.

Restaurant Service Manage restaurant registration, menu items, availability, and offers.

Order Service Create, update, and track orders; maintain order status.

Delivery Service Assign riders, track location, and update delivery status.

Payment Service Process payments, refunds, and handle secure transactions.

Notification Service Push notifications and alerts to users, restaurants, and riders.

Analytics & Recommendation Provide restaurant recommendations, trending items, and personalized offers.

Cache Layer Cache menus, offers, and frequently accessed data for low latency.

Database Layer Store user data, restaurant data, orders, delivery status, and payments.


Data Flow Overview


1.User opens app → fetch nearby restaurants from Restaurant Service (cached).
2.User places order → Order Service validates stock, calculates total, and sends to Payment Service.
3.Payment confirmed → Order Service updates status → Delivery Service assigns rider.
4.Rider picks up → status updated in Order Service, pushed via Notification Service.
5.User tracks order in real-time using Delivery Service API.


Scalability Considerations


•Microservices → Each service (Order, Delivery, Payment) can scale independently.
•Caching → Menus and restaurant data cached for faster reads.
•Load Balancing → Across APIs for high availability.
•Database Sharding → By geography or user ID to handle high write/read volume.
•Message Queue → For asynchronous tasks like notifications, payment confirmation, and rider assignment.


Design Patterns


•Observer → Push notifications to users and delivery partners.
•Strategy → Different payment methods.
•Singleton → For centralized services like configuration management.
•Circuit Breaker → Payment service to handle external API failures gracefully.


✅ This HLD problem tests:


•Ability to design end-to-end high-level architecture.
•Understanding of scalability, caching, database sharding, and service orchestration.
•Trade-offs between consistency, availability, and performance in real-world applications.


Solution

Comments