Design a store pickup route system

Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2025-05-14

Problem Statement

Design a Store Pickup Route System that helps delivery drivers or warehouse operators plan and optimize their pickup routes across multiple retail stores or warehouses.


The system should take into account pickup locations, item priorities, store operating hours, distance, and traffic conditions to generate an optimized pickup route that minimizes travel time and maximizes efficiency.


🎯 Objective


To build a route optimization and scheduling platform that:


•Allows users (drivers, logistics planners) to select pickup locations.
•Generates an optimal pickup order and route.
•Provides real-time updates on progress, delays, or store availability.
•Integrates with mapping and navigation APIs for live tracking and ETA adjustments.


✅ Functional Requirements


1. Pickup Request Management


•Each pickup request includes:
•Store location
•Items to pick
•Time window (when the store is open)
•Priority or urgency
•Requests can be created manually or ingested from a logistics/order management system.


2. Route Optimization


•Generate optimized routes using:
•Shortest distance
•Traffic conditions
•Store time windows
•Vehicle capacity (if multiple pickups)
•Support real-time re-optimization if delays or cancellations occur.


3. Assignment & Scheduling


•Assign pickup routes to available drivers based on:
•Proximity to stores
•Shift timing
•Vehicle capacity and type


4. Navigation & Tracking


•Provide turn-by-turn navigation via integration with Google Maps / OpenStreetMap.
•Track real-time driver location and ETA to next store.
•Update pickup statuses dynamically (“Pending”, “In Progress”, “Completed”, “Failed”).


5. Notifications & Alerts


•Notify drivers of route updates, traffic delays, or store unavailability.
•Notify stores of expected arrival time.


6. Dashboard / Reports


•Admin dashboard to:
•View routes and driver progress.
•Monitor pickup SLAs (on-time vs delayed).
•Analyze performance metrics (distance saved, route efficiency).


⚙️ Non-Functional Requirements


AttributeGoal


Scalability


Support 10K+ pickups per day


Latency


Route generation within 5 seconds



Availability


99.9% uptime


Accuracy


ETA prediction error < 10%


Reliability


Ensure route persistence even during failures


Extensibility


Add support for multi-day or multi-driver routes


Security


Protect sensitive store and location data


🧩 Core Components


ComponentDescription


Pickup Service


Manages pickup requests and store metadata


Route Optimization Engine


Computes optimal routes based on constraints


Driver Management Service


Handles driver profiles, shifts, and assignments


Tracking Service


Tracks real-time driver locations



Notification Service


Sends alerts and updates to drivers and stores


Map & Traffic Integration


Fetches live traffic and routing data


Admin Dashboard


Visualizes pickups, routes, and driver performance


Storage Layer


Stores route, pickup, and tracking data


🧱 High-Level Architecture

1 2 +-------------------------+ 3 | Admin Dashboard | 4 +-----------+-------------+ 5 | 6 +-----------v-------------+ 7 | API Gateway | 8 +-----------+-------------+ 9 | 10 +-------------------------------------------------------+ 11 | Application Layer | 12 +-------------------------------------------------------+ 13 | Pickup Svc | Route Engine | Driver Svc | Tracking Svc | 14 +-------------------------------------------------------+ 15 | 16 +----------v----------+ 17 | Map & Traffic APIs | 18 | (Google, OSM, etc.) | 19 +----------+----------+ 20 | 21 +----------v----------+ 22 | Notification Svc | 23 +----------+----------+ 24 | 25 +----------v----------+ 26 | Storage Layer | 27 | (SQL + Redis Cache) | 28 +----------+----------+ 29 | 30 +----------v----------+ 31 | Analytics Svc | 32 +---------------------+


🧠 System Flow


1. Pickup Creation


•Pickup requests are created (via API or admin portal):
1 2{ 3 "pickup_id": "P1001", 4 "store_name": "Reliance Fresh, Koramangala", 5 "coordinates": "12.934,77.615", 6 "time_window": ["09:00", "18:00"], 7 "priority": "HIGH" 8}


2. Route Optimization


•Route Engine fetches all pending pickups for a driver or batch.
•Uses heuristics (e.g., Dijkstra / A*, Traveling Salesman Problem with Time Windows).
•Considers traffic, store hours, and driver shift constraints.
•Generates an optimized sequence:
1 2Route: Store A → Store C → Store D → Store B 3Total Distance: 24.6 km | ETA: 2h 10m


3. Assignment


•Assigns route to the most suitable driver.
•Sends notification with route plan to driver’s mobile app.


4. Execution & Tracking


•Driver app updates location periodically (e.g., every 10 seconds).
•Tracking Service updates route progress and recalculates ETA.
•Notifications sent to stores for upcoming arrivals.


5. Completion


•Each pickup marked as “Completed” when driver checks in.
•Route summary generated with distance, time, and delays.


🧱 Data Model (Simplified)


Pickup

1 2 3{ 4 "pickup_id": "P1001", 5 "store_id": "S543", 6 "address": "Reliance Fresh, Koramangala", 7 "priority": "HIGH", 8 "status": "PENDING", 9 "time_window": ["09:00", "18:00"], 10 "coordinates": [12.934, 77.615] 11}


Route

1 2{ 3 "route_id": "R567", 4 "driver_id": "D102", 5 "pickup_ids": ["P1001", "P1002", "P1003"], 6 "total_distance_km": 26.4, 7 "estimated_time_min": 145, 8 "status": "IN_PROGRESS" 9}


Driver

1 2{ 3 "driver_id": "D102", 4 "name": "Ravi Kumar", 5 "current_location": [12.936, 77.620], 6 "vehicle_type": "VAN", 7 "shift": ["08:00", "16:00"] 8}


⚡ Scalability & Optimization Considerations


| Feature | Approach |

| ---------------------- | -------------------------------------------------- |

| **Routing at scale** | Use asynchronous job queues + batch processing |

| **Real-time tracking** | Use WebSockets or MQTT for updates |

| **Traffic awareness** | Integrate with live traffic APIs |

| **Performance** | Cache store geocodes and route segments in Redis |

| **Route updates** | Dynamically re-optimize on delays or cancellations |

| **Fault tolerance** | Store last known route state for recovery |


🔒 Security & Compliance


•Secure APIs with OAuth2/JWT tokens.
•Mask or encrypt sensitive location data.
•Audit logs for driver route access.
•Role-based access for admins and drivers.


🧩 Tech Stack (Example)


| Layer | Technology |

| -------------- | -------------------------------------- |

| **Frontend** | React / Angular for admin dashboard |

| **Backend** | Java / Go / Node.js microservices |

| **Database** | PostgreSQL + Redis (for caching) |

| **Queue** | Kafka / RabbitMQ |

| **Maps API** | Google Maps / Here API / OpenStreetMap |

| **Tracking** | WebSocket / MQTT |

| **Deployment** | Docker + Kubernetes |

| **Monitoring** | Prometheus + Grafana |


🚀 Key Challenges


| Challenge | Solution |

| ----------------------------------- | ---------------------------------------------------------- |

| **Dynamic routing (TSP)** | Use heuristic algorithms (Nearest Neighbor, Clarke-Wright) |

| **Real-time traffic updates** | Recalculate ETA every few minutes |

| **Multi-driver scheduling** | Partition requests geographically |

| **Offline connectivity** | Local cache + sync on reconnection |

| **Large-scale route recomputation** | Asynchronous background jobs with prioritization |


✅ Goal:

Design a smart, scalable, and traffic-aware store pickup routing system that ensures timely pickups, optimal travel distance, and real-time visibility for drivers and operations teams.

Solution

Comments