Design: Dynamic Pricing
Setting prices that change in real time based on demand, supply, competition, and customer willingness to pay.
The Problem
Design a system that adjusts prices for products or services in real time to maximize revenue while maintaining customer satisfaction. Examples: ride-sharing pricing that surges during peak demand, airline seats that get more expensive as the departure date approaches, or e-commerce products that adjust prices based on competitor activity.
Core Pricing Inputs
┌──────────────────────────┬──────────────────────────┬──────────────────────────┐
│ DEMAND SIGNALS │ SUPPLY SIGNALS │ EXTERNAL SIGNALS │
├──────────────────────────┼──────────────────────────┼──────────────────────────┤
│ Current request volume │ Available inventory or │ Competitor pricing │
│ Historical demand at │ driver supply. │ Weather conditions │
│ this time/day/season. │ Time until expiration │ Events (concerts, sports)│
│ User segment and history.│ (flight departure, hotel │ Economic indicators │
│ │ check-in date). │ │
└──────────────────────────┴──────────────────────────┴──────────────────────────┘
Architecture
Pricing Request (User views product)
│
▼
┌───────────────────────────────┐
│ STEP 1: FEATURE ASSEMBLY │ (~5ms)
│ Demand, supply, competitor, │
│ user segment, time features │
└───────────────────────────────┘
│
▼
┌───────────────────────────────┐
│ STEP 2: PRICE OPTIMIZATION │ (~10ms)
│ ML model predicts demand at │
│ candidate price points │
│ Optimizer selects revenue- │
│ maximizing price │
└───────────────────────────────┘
│
▼
┌───────────────────────────────┐
│ STEP 3: GUARDRAILS │ (~1ms)
│ Min/max price bounds │
│ Change rate limits │
│ Fairness constraints │
│ Output: Final price │
└───────────────────────────────┘
Step 2: Price Optimization
Two common approaches:
Approach A: Demand Prediction + Optimization
- Train a model that predicts demand (number of purchases or rides) at different price points given current conditions.
- For each pricing request, evaluate the demand model at several candidate prices.
- Select the price that maximizes expected revenue: $\text{Revenue} = \text{Price} \times \text{Predicted Demand}(\text{Price})$.
Approach B: Contextual Bandits
- Treat each price point as an "arm" in a multi-armed bandit.
- The reward is revenue generated at that price.
- Use Thompson Sampling or UCB to explore different price points while exploiting known good prices.
- Over time, the bandit learns the demand curve without needing a pre-trained demand model.
Step 3: Guardrails
Unconstrained pricing optimization can create problems:
- Price Floors and Ceilings: Never go below cost or above a maximum price that triggers regulatory or reputational issues.
- Rate Limits: Do not change the price more than 20% within a 1-hour window to avoid customer confusion.
- Fairness Constraints: Do not charge systematically different prices based on protected characteristics (race, gender, age). Regulators and customers will notice.
- Transparency: In ride-sharing, show the surge multiplier so users understand why the price is higher.
Key Design Challenges
- Demand Elasticity Estimation: You need to know how demand changes with price, but you can only observe demand at the prices you actually charged. This is a causal inference problem. Use randomized price experiments to build unbiased demand curves.
- Competitive Response: If you lower prices and a competitor matches, you lose margin without gaining volume. Model competitor behavior as a feature.
- Customer Perception: Frequent visible price changes erode trust. Some products work well with dynamic pricing (ride-sharing, airlines) while others do not (grocery staples).
- Inventory Perishability: Products with expiration (hotel rooms, airline seats, concert tickets) need more aggressive pricing as the deadline approaches because unsold inventory has zero value.
Say this out loud
Dynamic pricing adjusts prices in real time based on demand, supply, competitor activity, and time sensitivity. The system either predicts demand at candidate price points and selects the revenue-maximizing option, or uses contextual bandits to explore pricing experimentally. Guardrails enforce price bounds, change rate limits, and fairness constraints.
Followups to expect
- How do you handle price discrimination concerns? Ensure pricing algorithms do not use protected attributes. Audit for disparate impact by checking if price distributions differ significantly across demographic groups.
- How do you run pricing experiments safely? Use small holdout groups, ramp slowly, and set automatic kill switches that revert to baseline pricing if revenue or conversion drops below a threshold.
Check yourself
What fundamental economic principle drives dynamic pricing?