DSAOps Lab
D
DSAOps LabSwiggy Delivery Lab

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

1

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.

Restaurant
#123
Order
Partner
1 / 5

Experiments

Visualization

Interactive Simulation

City grid with restaurants, partners, and orders

P1
P3
R2
O5
R1
O1
O4
O2
O3
P2
RestaurantPartnerOrder

Partners

P1
0 orders
P2
0 orders
P3
0 orders

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

AlgorithmTime ComplexitySpace ComplexityUse Case
Greedy AssignmentO(n×m)O(n)Nearest assignment
Min-Heap BatchingO(n log n)O(n)Proximity grouping
Dijkstra RoutingO((V+E) log V)O(V)Multi-stop path
DP SelectionO(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

Q

Design real-time delivery assignment for 10k+ orders/min.

H

Geohash for proximity, priority queues, consistent hashing.

Q

How to implement multi-order batching minimizing time?

H

K-means + min-heap merging. Recompute as orders arrive.

Q

Design route optimization with traffic and time windows.

H

Time-dependent Dijkstra. Contraction hierarchies for hotspots.

Q

Scale restaurant selection across thousands per city?

H

Precompute clusters by cuisine/area. DP + Redis cache.