Swiggy
Swiggy Delivery Lab
Delivery assignment, multi-order batching, route optimization, restaurant selection
Walkthrough
How Swiggy Delivery Works
Step-by-step from order placement to delivery
Order Placed
A customer places an order at a restaurant. The order includes items, quantity, and delivery address. The system records the order with a timestamp and assigns an order ID.
Experiments
Visualization
Interactive Simulation
City grid with restaurants, partners, and orders
Partners
Algorithms
Algorithm Explanation
Delivery algorithms and their real-world application
Delivery Assignment (Greedy)
For each order, Manhattan distance to all partners. Assign to nearest. O(n×m) baseline for real-time decisions.
Multi-order Batching (Heaps)
Min-heap sorts orders by proximity. Extract closest pairs into batches, reducing time 30-40%.
Route Optimization (Graphs)
City roads = weighted graph. Dijkstra for shortest paths. Multi-stop via TSP + nearest-neighbor.
Restaurant Selection (DP)
DP selects optimal restaurant combo by distance, prep time, partner availability. KnapSack-style.
Analysis
Complexity Analysis
Time and space complexity of delivery algorithms
| Algorithm | Time Complexity | Space Complexity | Use Case |
|---|---|---|---|
| Greedy Assignment | O(n×m) | O(n) | Nearest assignment |
| Min-Heap Batching | O(n log n) | O(n) | Proximity grouping |
| Dijkstra Routing | O((V+E) log V) | O(V) | Multi-stop path |
| DP Selection | O(n×k) | O(n×k) | Restaurant combo |
Architecture
System Design
How Swiggy-scale delivery systems are architected
Architecture
- Microservices: ingestion, assignment, routing, tracking
- Kafka for order events
- Redis for partner location/proximity
- PostgreSQL for history & analytics
Data Flow
- Order placed → geohash → greedy assignment
- Min-heap batching within radius
- Dijkstra on road graph + live traffic
- GPS pings → WebSocket tracking
Scalability
- Horizontal scaling by city zone (K8s)
- Graph partitioned by zone (<50ms)
- Read replicas for menus, write master for orders
- Peak-hour prewarm top restaurant routes
Algorithms
- Greedy nearest-neighbor assignment
- Min-heap multi-order batching
- Time-dependent Dijkstra routing
- KnapSack DP for restaurant selection
Practice
Interview Questions
Common system design and DSA questions from Swiggy interviews
Design real-time delivery assignment for 10k+ orders/min.
Geohash for proximity, priority queues, consistent hashing.
How to implement multi-order batching minimizing time?
K-means + min-heap merging. Recompute as orders arrive.
Design route optimization with traffic and time windows.
Time-dependent Dijkstra. Contraction hierarchies for hotspots.
Scale restaurant selection across thousands per city?
Precompute clusters by cuisine/area. DP + Redis cache.