Design a Delivery Service

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2025-03-27

Problem Statement

Design a Delivery Service System that allows users to place orders, track deliveries, and receive updates while optimizing delivery assignment and route planning. The system should handle order management, delivery partner coordination, real-time tracking, and notifications at scale.


Functional Requirements (FR)


1.User Management
•Register/login users via email, phone, or social login.
•Maintain user profiles including addresses and payment preferences.
2.Order Management
•Place, update, or cancel orders.
•Track order status: Pending → Accepted → Picked-up → In-Transit → Delivered.
•Support multiple item types and vendors (restaurants, stores).
3.Delivery Partner Management
•Register delivery partners and track their availability.
•Assign orders to delivery partners based on proximity, workload, and capacity.
4.Real-Time Tracking
•Track delivery partners’ location in real-time.
•Provide live updates to users about order progress.
5.Notifications
•Notify users on order confirmation, dispatch, and delivery.
•Notify delivery partners of new orders or updates.
6.Payment & Billing
•Accept multiple payment methods (cards, wallets, COD).
•Generate invoices and maintain transaction history.
7.Analytics & Reporting
•Monitor delivery metrics: time, distance, success rate.
•Provide insights for demand forecasting and delivery optimization.


Non-Functional Requirements (NFR)


•Scalability – Support thousands of concurrent users and delivery partners.
•Availability – Ensure real-time tracking and order updates 24/7.
•Low Latency – Fast order placement and real-time location updates.
•Reliability – Accurate order assignment and status tracking.
•Extensibility – Ability to add new features like dynamic pricing, promotions, or route optimization.


Core Components


1.Client Applications
•User App: Place orders, track delivery, and receive notifications.
•Delivery Partner App: Receive assignments, update status, and navigate routes.
2.Order Management Service
•Handles order creation, updates, cancellation, and status tracking.
3.Delivery Assignment & Route Planning Service
•Assigns delivery partners based on proximity, availability, and load.
•Calculates optimal routes using mapping services.
4.Location Tracking Service
•Updates and stores real-time location of delivery partners.
•Provides location data to users and analytics service.
5.Notification Service
•Sends push notifications, SMS, or email updates.
6.Payment Service
•Processes payments securely.
•Handles refunds or cancellations.
7.Database & Storage
•Orders DB: stores order details and status.
•Users DB: stores user profiles and addresses.
•Delivery Partner DB: stores partner availability and history.
•Analytics DB: stores historical data for insights.


Data Flow


1.User places order → Order Management Service.
2.Order Assignment Service assigns delivery partner → updates status.
3.Delivery Partner app receives assignment → picks up order.
4.Location Tracking Service updates real-time location → User App sees live progress.
5.Payment Service handles transaction → Notification Service updates user and partner.
6.Analytics Service collects metrics for reporting and optimization.


Design Considerations


1.Scalability
•Partition database by region or city.
•Use message queues for order assignment and notifications.
2.Consistency & Reliability
•Ensure order and delivery status is consistent across services.
•Handle failures in assignment or tracking gracefully.
3.Real-Time Location Handling
•Efficiently process frequent location updates from delivery partners.
•Use geo-indexing (like Redis Geo or PostGIS) for proximity calculations.
4.Trade-offs
•Real-time tracking vs network/data usage.
•Optimal route computation vs computational cost.
•Strong consistency vs high availability for delivery assignment.


✅ This HLD problem tests:


•Design of scalable, real-time delivery systems
•Service interactions and data flow management
•Geospatial computations and route optimization
•Handling concurrency, notifications, and fault tolerance


Solution

Comments