Bugpit

Lessons › Real apps

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 level

Part 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.

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

Check yourself

What was the real load: orders or riders?

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?

Show the answer

It only checks the map cells around the restaurant. A normal database must measure everyone. A geo index looks only nearby.

Try it yourself

More in Real apps

← Flipkart: the sale opens Instagram: 3 billion people →