Lesson 9 of 15
44. Design Ride-Hailing with Surge Pricing (Uber / Rapido)

44.8 How does surge pricing work?

3 min read+10 XP

When a concert ends, 300 people request rides in a cell with 100 drivers. Surge raises the price there to reduce demand (some people wait or walk) and attract supply (drivers head to the area):

surge per cell goes 1.5, 1.75, 2.12 and eases to 1.38; a trip moves requested, matched, arriving, in_trip, completed, or cancelled.

Figure: surge nudges supply and demand together; the trip moves through fixed states.

  • Per cell, per minute: count open requests and available drivers in each cell (from the request stream and the driver index).
  • Multiplier from the ratio: 1.0 when supply covers demand, rising with the shortage, capped (say ×2.5).
  • Smooth it: move part-way toward the target each minute, so prices don't jump around. In the chapter's code: ×1.5, then ×1.75, a spike to ×2.12 (under the ×2.5 cap), then easing to ×1.38 when demand drops.
  • Lock it into the quote: the rider pays the multiplier they saw, even if surge changes during the trip.
  • Guardrails: caps, and policies to limit surge during emergencies; show the multiplier clearly before booking.

Memory code: "Price the shortage, smooth the jumps, cap the top, lock the quote."