Design a Delivery Partner Assignment System

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

Problem Statement

Design the Low-Level Design (LLD) for a Delivery Partner Assignment System, similar to what platforms like Swiggy, Zomato, Uber Eats, or Dunzo use.


The system’s goal is to efficiently assign the best available delivery partner to a new delivery request based on multiple factors such as location, availability, proximity, and delivery load.


Focus is on object-oriented class design, data models, and interactions, not on scalability or distributed coordination (that would be HLD).


🎯 Functional Requirements

Delivery Partner Management

•Register new delivery partners.
•Maintain partner attributes like:
•ID, Name, Vehicle Type
•Current Location (latitude, longitude)
•Availability Status (AVAILABLE / BUSY / OFFLINE)
•Current active orders count or capacity.

Order / Delivery Request

•A new delivery request is created by the system (e.g., restaurant order, grocery order).
•Each request includes pickup and drop locations, expected pickup time, and delivery priority.

Assignment Logic


•When a new delivery request arrives:
•Find available partners near the pickup location.
•Rank eligible partners based on:
•Distance to pickup location.
•Current workload.
•Partner rating / performance (optional).
•Assign the most optimal partner.


Status Updates


•Partner accepts / rejects assignment.
•System reassigns order if rejected or timed out.
•Track live partner location during delivery.


Partner Tracking


•Continuously update partner’s location and order status.
•Update availability once delivery completes.


Notifications


•Notify partner about new assignment.
•Notify system and customer about assignment updates.


🚫 Non-Functional Requirements


•Fast Matching — Assign within a few hundred milliseconds.
•Accurate Proximity Calculation — Use geospatial distance calculation (e.g., Haversine formula).
•Extensible — Should easily integrate new ranking or matching strategies.
•Fault Tolerant — Handle partner rejection or disconnection gracefully.


🧱 Suggested Classes


ClassResponsibility


DeliveryPartner


Represents a delivery agent with attributes like id, name, location, status, and active order count.


Location


Represents a geographic coordinate (latitude, longitude).


OrderRequest


Represents a new delivery request with pickup, drop, and priority.


AssignmentService


Main service responsible for finding and assigning the best partner.


PartnerRepository


Stores and retrieves partner data; supports searching nearby partners.


DistanceCalculator


Utility to calculate distance between two Locations.


AssignmentStrategy (Interface)


Defines the algorithm for selecting the best delivery partner.


NearestPartnerStrategy, LoadBalancedStrategy


Concrete implementations of partner-selection strategies.


NotificationService


Sends assignment notifications to delivery partners.


AssignmentResult


Represents the outcome of an assignment attempt (success/failure, assignedPartnerId, etc.).


🔄 Example Flow


1.New Order Created
1 2OrderRequest(id=101, pickup=Koramangala, drop=BTM)
1.AssignmentService Triggered
1 2→ PartnerRepository.getAvailablePartnersWithinRadius(pickupLocation, 3 km) 3→ DistanceCalculator.calculateDistance() 4→ AssignmentStrategy.selectBestPartner()
1.Partner Selected
1 2Partner: Rajesh (1.2 km away) 3→ Notify partner via NotificationService
1.Partner Accepts
1 2Partner status = BUSY 3Order assigned successfully
1.Delivery Completed
1 2Partner status = AVAILABLE again 3Location updated


⚙️ Example Entities (Simplified)

1 2DeliveryPartner 3 ├── id 4 ├── name 5 ├── currentLocation: Location 6 ├── status: PartnerStatus 7 ├── activeOrdersCount 8 9OrderRequest 10 ├── id 11 ├── pickupLocation: Location 12 ├── dropLocation: Location 13 ├── priority 14 15AssignmentService 16 ├── partnerRepository 17 ├── strategy: AssignmentStrategy 18 ├── assignOrder(orderRequest)


🧪 Example Input / Output


Input:

1 2OrderRequest: pickup=(12.91, 77.63), drop=(12.93, 77.60) 3Available Partners: 4 P1: (12.90, 77.62), AVAILABLE 5 P2: (12.92, 77.64), BUSY 6 P3: (12.91, 77.65), AVAILABLE


Output:

1 2Assigned Partner: P1 (nearest available partner)


📏 Constraints


•Max partners: 10^5
•Max concurrent assignments: 10^4
•Location update frequency: every 5–10 seconds
•Radius search range: configurable (1–5 km)


🧠 Extension Ideas


•Partner rating & reliability in scoring.
•Dynamic ETA calculation using traffic API.
•Surge pricing or priority delivery support.
•Multi-order batching for same route.


✅ In short:


Design a Delivery Partner Assignment System that manages delivery partners, handles live locations, and efficiently assigns the nearest and most suitable partner to each delivery request, using clean OOP and strategy-based design.

Solution

Comments