KatInterview

Design a Fair, Real-Time Pricing Engine for a Ride Platform

System DesignModel answer
HardModel answerSystem Designpricingreal-time systemssurge

Last updated

Design the components, data flows, and core pricing logic for a ride platform that handles surge, carpooling, fairness constraints, and live experimentation at scale.

The Problem

You're designing the pricing engine for a large ride-hailing platform. The system must compute upfront prices in real time, support both solo and shared rides, stay fair to riders across different neighborhoods, and give the business a lever for running controlled pricing experiments.

Functional requirements

  1. Accept a ride request (origin, destination, product type, pool opt-in) and return several route options — each with a price and an itemized breakdown.
  2. Price each route using at minimum: distance, trip duration, supply/demand conditions, pickup wait time, and driver incentives.
  3. For pooled rides, calculate each rider's share based on which segments they actually share and any detour added to their trip.
  4. Enforce hard fairness rules: cap how high surge can go, prevent price discrimination by rider identity, surface transparent breakdowns, and keep pricing equitable across neighborhoods.
  5. Support A/B testing of pricing parameters with automatic rollback if safety metrics are violated.
  6. Reflect changes in driver availability and demand in near real time.

Non-functional requirements

  • ~20 million rides per day; quoting runs roughly 10× bookings, so you need to handle ~20k quote requests per second at peak with 3 route options each.
  • Driver location updates arrive at ~250k events/second.
  • Quote API p99 latency under 300 ms end-to-end; the pricing function itself should run in under 10 ms.
  • Prices are locked for 2–5 minutes after a quote is issued.
  • Every computed price must be reproducible for auditing.

What's expected

Walk through your high-level architecture (components, data flows, storage choices), then write pseudocode or working code for the core price calculation function — including how pooling and surge feed into it. Call out trade-offs, constraints you're assuming, and how you'd validate that the fairness rules are actually working.

Hints

Hint 1

Start by pinning down the numbers: 20k quotes/s means ~60k price computations/s. That rules out anything slow in the hot path — the pricing function itself needs to be stateless and read only from a pre-warmed local cache. What does that imply about how you feed it surge data?

Hint 2

Surge needs smoothing in two dimensions: time (to avoid oscillations) and space (to avoid jarring price cliffs at cell boundaries). H3 hexagons and neighbor blending are a natural fit. Think about what happens when the surge feed goes stale — what's the safe default?

Hint 3

Pool pricing has a bootstrapping problem: at quote time you don't know who your co-riders will be. Model occupancy as an expected value per segment, quote that upfront, and decide what happens when no match materializes. Also consider: is proportional cost splitting the right model, or is there a fairer one?