Design a Dynamic Pricing Engine
Dynamic pricing changes a product's price as demand, stock and time change. Prices move inside fixed limits, so the system can answer a busy day without wild swings.
The ask
A fixed price leaves money on the table on busy days. It also leaves stock unsold on quiet days.
Dynamic pricing adjusts each price toward what buyers will accept right now.
Prices must never pass fixed floors or ceilings, even when demand surges.
Every price change needs a reason the shop can explain later.
Some products are barred from moving prices by law or by shop policy.
Estimate the scale
The shop holds 1,000,000 products.
Prices are recomputed every hour.
1,000,000 × 24 = 24,000,000 price decisions a day.
24,000,000 ÷ 86,400 = 278 decisions per second, rounded to the nearest whole number.
Price elasticity measures how much demand moves when price moves. The design learns it from past sales, product by product.
A 1% price rise cuts demand by about 2% as a shop-wide average. Single products can move more or less.
Data and features
A demand forecast is a prediction of how many units buyers will buy at a given price. Forecasts are made per product and per hour.
Past sales are the core training data, with the price shown at the time of each sale.
A feature is one measured fact fed to the model. Features include stock left, time of day, day of week and season.
Events outside the shop matter too, such as weather, holidays and pay days.
Stock data must be fresh, because a price cut on a sold-out item wastes the cut.
Training rows must use the price and stock as they stood at the sale moment. That rule is point-in-time correctness.
High-level design
A pricing service recomputes all prices once an hour.
It reads stored features, such as stock and recent sales, from the feature store.
A rules layer checks each new price against floors, ceilings and the largest allowed step.
Approved prices go to the shop front, each with a short note of its main reasons.
The old price stays in place whenever any check fails.
Every decision is logged, so a price can be replayed and explained later.
Training the model
Two models work together, one forecasting demand and one estimating price elasticity per product.
Take a product selling 10,000 units a day at a price of 100.
A 1% rise makes the price 101. Demand falls by about 2%, to 9,800 units a day.
Before the rise, revenue is 100 × 10,000 = 1,000,000 a day.
After the rise, revenue is 101 × 9,800 = 989,800 a day. The higher price earns less here, because demand falls faster than price rises.
Training learns each product's own elasticity from its price history. Products with little history borrow the average of their group.
Serving predictions
Serving is the hourly run itself, since no buyer waits on a price calculation.
Between runs, the shop front serves the stored price from a cache.
A sudden stock change can trigger an early recompute for that one product.
If the pricing service fails, stored prices simply stay in place for another hour.
One product's price can move at most 20% in a day under the design's cap.
Shoppers see one stable price during a single visit, even if a run lands mid-visit.
Deep dive: new and rare products
A new product has no sales history, so it has no measured elasticity. That gap is the cold start problem.
The design starts new products at the group average elasticity for similar products.
Early prices move in small steps, so the system learns without wild swings.
Rare products sell a few units a week, and their demand signal stays noisy.
For rare products, forecasts pool sales across weeks and across similar items.
A person reviews price moves for high-value items until enough history builds.
Evaluation and trade-offs
Offline tests replay past weeks and compare predicted demand with real sales.
Online experiments give the new pricing to a small share of products first.
Revenue alone is a trap, because a price rise can earn more today and lose buyers for good.
Scores therefore track revenue, units sold and repeat buyers together.
Fairness matters too, since two buyers in the same shop should see the same price at the same time.
The design trades some possible revenue for stable, explainable prices.
Price moves and demand
| Price change | Demand change | Units a day from 10,000 |
|---|---|---|
| +1% | about -2% | 9,800 |
| +5% | about -10% | 9,000 |
| -5% | about +10% | 11,000 |
Exercise
Under the design's elasticity rule, what happens to demand when a price rises by 1%?