Bugpit

Lessons › Big architectures

Ride hailing: a driver in two seconds

60,000 drivers are on the road, each sending their position every 4 seconds: 15,000 updates a second. Riders open the app, ask for the nearest car and want a price. Every position goes straight into one database, and if the pricing service dies, nobody can book.

Play this level

Part of Bugpit Pro. It runs in your browser: build the design, press Run, and watch what breaks.

The lesson

A ride app is mostly drivers, not riders. Each moving car is a stream of writes, and every one is out of date a few seconds later. So positions go down an event stream, and workers keep only the latest one in a Geo Index.

"Who's nearest?" is a map question. A Geo Index checks only the cells around the rider, so it takes milliseconds however many drivers there are. Then a Maps API gives the route and the arrival time. It has a quota, so you pay for each step of it.

Riders and drivers both watch the car move, so the app holds a live connection through a Realtime Gateway.

Pricing is useful but not essential. If it dies, charge the normal price and keep booking rides. That's a circuit breaker on the pricing service.

What you have to achieve

16,000 requests a second at the busiest hour, 94% of them writes.

What you learn

Crash the pricing service: rides still get booked. Now count the writes: almost all your load is cars moving, and none of it touches the database. When data is out of date in seconds, keep only the latest copy and let the rest flow past.

Check yourself

Why do driver positions go through a stream instead of into a database?

Show the answer

Each position is out of date in seconds, so only the latest one is worth keeping. Workers read the stream and keep just each driver's newest position in the Geo Index. The old ones flow past.

The pricing service dies. What should happen?

Show the answer

Rides are booked at the normal price. A circuit breaker stops calling it and falls back. A ride at a normal price beats no ride.

Why did the pricing service need 10 machines, even with a breaker?

Show the answer

A breaker that trips on a normal day means users always get the fallback. The breaker is for real failures. If the service is simply too small, it trips all the time and protects nothing.

Try it yourself

More in Big architectures

← Ticket sale: one show, everyone at once Live match: a goal in the final →