Swiggy: New Year's Eve
Swiggy hit 9,500 food orders a minute on New Year's Eve: 158 a second. Here that's real size, not scaled down. With 100,000 riders each sending their position every 5 seconds, that's 20,000 location updates a second going straight into one database.
Play this levelPart of Bugpit Pro. It runs in your browser: build the design, press Run, and watch what breaks.
The lesson
The orders aren't the hard part: 158 a second is small. The riders are. Every moving rider is a stream of writes, and nearly all of them are about to be out of date.
So don't store each position forever. Send it down an event stream, and let workers keep only the latest in a geo index. The stream gives each rider's update a place to wait at the peak.
To place an order you ask who's nearest. A normal database must measure everyone. A geo index only checks the map cells around the restaurant.
Then you need a route and an arrival time, and that means an outside Maps API with a quota. Keep orders in a store built for the load, and hold a live connection open so the app can show the rider moving.
What you have to achieve
23,000 requests a second at the busiest hour, 87% of them writes.
- No broken or illegal connections
- Use a Realtime Gateway
- Use an Event Stream
- Use a Geo Index with at least 2 instances
- Use a Maps API
- No component is overloaded
- Workers clear the queue within the day
- Fewer than 0.1% of requests fail
- p99 response time under 400 ms
What you learn
Open Monthly cost and find Map routes: each call is cheap, and you make a lot of them. Most of your load was never orders. It's where people are, right now. Whenever data is out of date in seconds, stop treating it like a record and start treating it like a stream.
The real numbers behind it
- 9,500 food orders a minute at its New Year's Eve peak, per Swiggy (Reported: The News Minute: Swiggy's New Year's Eve)
- 100,000 delivery partners on an earlier New Year's Eve, per Swiggy (Reported: The News Minute: 100,000 delivery partners)
- One position every 5 seconds from each rider. Swiggy doesn't publish this (Estimate)
- 3,000 req/s of browsing on top. Swiggy doesn't publish this (Estimate)
- The stream and geo index are a standard design. Swiggy's own isn't confirmed here (Estimate)
Check yourself
What was the real load: orders or riders?
- Orders, at 158 a second
- Both equally
- Rider positions, at 20,000 a second
Show the answer
Rider positions, at 20,000 a second. Every moving rider is a stream of writes that's out of date in seconds.
How does a geo index find the nearest rider fast?
- It measures every rider
- It only checks the map cells around the restaurant
- It asks the Maps API
Show the answer
It only checks the map cells around the restaurant. A normal database must measure everyone. A geo index looks only nearby.