Design Dynamic Pricing for Ride-Sharing
Understanding the Problem
💸 What is dynamic pricing for ride-sharing? Dynamic pricing (surge pricing at Uber, Prime Time at Lyft) raises the fare in an area when riders want more rides than there are drivers nearby. The higher price does two jobs at once: it rations the drivers who are available toward riders who need a ride most, and it pulls more drivers toward the area and onto the road. Done well, a rider can almost always get a car within a few minutes; done badly, prices flicker, drivers chase ghosts and riders feel gouged.
The pipeline that counts requests and drivers per cell and writes a multiplier to a cache is covered in Design Uber. That version maps a demand-to-supply ratio straight to a multiplier. Here we go into the ML: forecasting demand and supply before the shortage happens, learning how riders and drivers respond to price (which is much harder than it sounds), and choosing the price with an optimizer or a reinforcement learning policy.
Functional Requirements
Core Requirements
- The system should set a price multiplier per area and product (for example per H3 cell, for the standard and premium tiers), updated every minute or two.
- The system should forecast demand and supply for each area over the next 5 to 60 minutes, so prices and driver nudges can move before a shortage, not after.
- Riders should get an upfront quote that's honored for a few minutes, and the price should stay stable within that window.
- Drivers should see where prices are elevated (a heatmap) so they can reposition.
Below the line (out of scope)
- The base rate card (per-minute and per-kilometre rates), which is a business configuration.
- Driver incentive programs like bonuses for a number of trips.
- Dispatch itself: matching riders to drivers.
- Payments and fare splitting.
Non-Functional Requirements
Core Requirements
- Scale: around 600 cities, each split into cells of roughly a square kilometre (H3 resolution 8), so a few hundred thousand cells, of which on the order of 100,000 see activity at any moment.
- Freshness: multipliers recomputed every 60 seconds from data no more than a minute old; forecasts refreshed every 5 minutes.
- Quote latency: reading the multiplier for a quote adds only a few milliseconds; the whole fare quote stays under 100 ms at p99 (the ETA and routing calls dominate).
- Stability: prices shouldn't oscillate minute to minute or jump between adjacent blocks.
- Safety and fairness: hard caps per market, emergency caps during disasters, no use of personal attributes that would make two riders on the same trip see different prices for reasons unrelated to the trip.
Below the line (out of scope)
- Cross-region consistency; each region prices its own cities.
The arithmetic here is reassuring and points somewhere interesting. 100,000 active cells, each recomputed once a minute, is under 2,000 cell updates per second. Even with a forecast at 12 horizons per cell every 5 minutes, that's about 4,000 predictions per second. Fare quotes are a few hundred million a day, around 10,000 per second at peak, and each one is a single cache lookup for the multiplier. None of that is a scaling problem.
The input streams are bigger. A million online drivers sending a location every 4 seconds is 250,000 updates per second, plus app opens and requests. We need a streaming job that turns them into per-cell counts, but that's well-trodden ground.
The hard part of this problem isn't throughput. It's that the system changes the data it learns from: we set prices high exactly when demand is high, so naive models conclude that riders love high prices. If you spend your interview time on QPS, you've missed the question.