Contents
Constraints
- 50k SKUs × 30 sites × 14 horizons ≈ 21M forecasts/day
- nightly batch with an intraday refresh
- many intermittent SKUs
What to cover
Sketch your own design first. A complete answer has these parts; the notes say what each should settle.
- RequirementsForecast daily demand per product per fulfilment centre for the next 14 days to drive purchasing, minimising both waste and stock-outs.
- Estimates50k SKUs × 30 sites × 14 horizons ≈ 21M forecasts/day; nightly batch with an intraday refresh; many intermittent SKUs.
- API
- Data model
- ArchitectureDemand signal reconstruction (correct for stock-outs and substitutions).; Features: price and promotions, seasonality, holidays, weather, events.; Global model across SKUs (GBDT or deep sequence model), hierarchical reconciliation.; Quantile forecasts feeding a newsvendor-style ordering rule.; Cold start via heuristics or transfer learning from similar SKUs and sites.; Planner overrides feed back into training.
- Deep dives
- Trade-offsglobal vs per-SKU models; point vs probabilistic forecasts; freshness vs compute; interpretability for planners.
- EvaluationOffline: rolling-origin backtests with WAPE and pinball loss by category, bias, and waste or availability simulation.; Online: pilot sites vs control sites on waste % and availability %.
Reference design
One way to answer it, part by part. Open a part once you have your own version of it.
Requirements
Functional: every night, forecast daily demand for each SKU at each fulfilment centre for the next 14 days, as quantiles, in time for purchase orders; refresh intraday for the next 1–3 days (fresh produce, weather, promotions going live); let planners override with reasons; feed forecasts to an ordering rule that sets purchase quantities.
What matters to the business: waste (perishables written off) and availability (customers finding what they ordered, plus substitutions). Forecast accuracy is a means; the ordering outcome is the end.
Constraints and assumptions to confirm
- 50k SKUs × 30 sites; many intermittent, slow-moving SKUs; strong weekly seasonality; promotions and price changes; holidays and events; weather sensitivity (barbecue, ice cream).
- Supplier lead times of 1–3 days; shelf life from 2 days (salad) to years (tins); orders placed early morning, so forecasts must land by ~02:00.
- Data: hourly sales and availability per site, promotions calendar, prices, product hierarchy, weather forecasts.
- Planners must understand and trust forecasts; overrides are common at launch.
- New SKUs and new sites (cold start) arrive weekly.
Estimates
Flow · 5 stepsNightly batch timing
- Data cut-off The nightly window opens at the 23:00 data cut-off.
- Features Feature building and joins run 23:00–00:30 and are the real time sink.
- Inference Inference runs 00:30–01:00 on 21M rows.
- Reconcile and publish Reconciliation and checks run 01:00–01:30, then forecasts publish by 02:00.
- Intraday refresh Intraday refresh covers only the next 1–3 days and perishables (~30% of SKUs), about 1.4M forecasts.
Data
| Step | Title | What happens |
|---|---|---|
| 1 | Data cut-off | The nightly window opens at the 23:00 data cut-off. |
| 2 | Features | Feature building and joins run 23:00–00:30 and are the real time sink. |
| 3 | Inference | Inference runs 00:30–01:00 on 21M rows. |
| 4 | Reconcile and publish | Reconciliation and checks run 01:00–01:30, then forecasts publish by 02:00. |
| 5 | Intraday refresh | Intraday refresh covers only the next 1–3 days and perishables (~30% of SKUs), about 1.4M forecasts. |
Source: This page's text
| Box | Group | Detail |
|---|---|---|
| Data cut-off | Nightly batch | 23:00 |
| Features | Nightly batch | 23:00–00:30 |
| Inference | Nightly batch | 00:30–01:00 |
| Reconciliation and checks | Nightly batch | 01:00–01:30 |
| Publish | Nightly batch | by 02:00 |
| Intraday refresh | Intraday | next 1–3 days, perishables ~30% |
Source: This page's text
- Forecast volume: 50k SKUs × 30 sites = 1.5M series × 14 horizons = 21M forecasts/day; with four quantiles plus the mean (5 values) ≈ 105M numbers.
- Training data: 1.5M series × ~3 years × 365 days ≈ 1.6B daily rows with ~200 features. A global GBDT trains on this (or a sample of it) in a few hours on a distributed cluster; a deep sequence model needs GPUs.
- Inference: 21M rows × 200 features in batch takes minutes on a modest cluster; the real time sink is feature building and joins, so budget the nightly window as: data cut-off 23:00, features 23:00–00:30, inference 00:30–01:00, reconciliation and checks 01:00–01:30, publish by 02:00.
- Intraday refresh: only next 1–3 days and perishables (~30% of SKUs) → ~1.5M × 0.3 × 3 ≈ 1.4M forecasts, minutes of compute.
- Intermittency: if ~40% of series sell less than one unit per day per site, a point forecast of 0.4 is useless for ordering — quantiles carry the information.
- Value at stake: assume £3B annual sales and 2% waste on perishables worth £1B → £20M/year; one point less waste ≈ £10M, so a small accuracy gain is worth a lot.
API
Batch outputs (warehouse table, partitioned by run):
forecast(run_id, sku, site, target_date, horizon, q10, q50, q90, q97, mean,
model_version, features_version, created_at)
GET /v1/forecasts?sku=…&site=…&from=…&to=… → quantiles per day, drivers (promo, price, weather)
POST /v1/overrides {sku | category, site | all, dates, value | multiplier, reason_code,
planner, expires_at} → override_id
GET /v1/orders/proposal?site=…&date=… → {sku, order_qty, target_quantile, stock_on_hand,
on_order, shelf_life_days}
Inputs consumed: promotions calendar, price changes, new SKU listings, site openings
Overrides are stored separately from model output so we can measure whether they helped.
Data model
- SalesHourly: sku, site, hour, units, availability flag (in stock / out of stock), substitutions given and received.
- DemandSignal: reconstructed daily demand = observed sales corrected for stock-out hours and substitution, plus online signals (add-to-basket attempts on unavailable items).
- Calendar: promotions (mechanic, depth, start/end), price history, holidays, local events.
- Weather: forecasts and actuals per site region.
- ProductHierarchy: sku → subcategory → category; attributes (shelf life, supplier, pack size); embeddings for similarity (used in cold start).
- Site: region, capacity, opening date, customer base.
- Forecast: versioned per run (above).
- Override: scope, value, reason code, planner, outcome measured after the fact.
- OrderingOutcome: ordered, received, sold, wasted, unavailable hours — closes the loop to business metrics.
Architecture
Flow · 5 stepsArchitecture for SKU-level demand forecasting
- Reconstruct demand Hourly sales and availability, promotions, prices, weather and events are reconstructed into true demand, correcting for stock-outs and substitutions.
- Model and reconcile The feature pipeline feeds the global model across SKUs and sites, whose output is reconciled hierarchically before becoming quantile forecasts.
- Cold start New SKUs and sites use heuristics and similar-SKU transfer, feeding the quantile forecasts directly.
- Order Quantile forecasts feed the newsvendor-style ordering rule, which sets purchase quantities as proposals for planners.
- Override and retrain Planners override forecasts with reasons; overrides are logged and feed back into training.
Data
| Step | Title | What happens |
|---|---|---|
| 1 | Reconstruct demand | Hourly sales and availability, promotions, prices, weather and events are reconstructed into true demand, correcting for stock-outs and substitutions. |
| 2 | Model and reconcile | The feature pipeline feeds the global model across SKUs and sites, whose output is reconciled hierarchically before becoming quantile forecasts. |
| 3 | Cold start | New SKUs and sites use heuristics and similar-SKU transfer, feeding the quantile forecasts directly. |
| 4 | Order | Quantile forecasts feed the newsvendor-style ordering rule, which sets purchase quantities as proposals for planners. |
| 5 | Override and retrain | Planners override forecasts with reasons; overrides are logged and feed back into training. |
Source: This page's text
| Box | Group | Detail |
|---|---|---|
| Sources | Input | sales, availability, promotions, prices |
| Demand reconstruction | Compute | correct for stock-outs and substitutions |
| Feature pipeline | Compute | lags, seasonality, weather, embeddings |
| Global model | Compute | GBDT or deep sequence model |
| Hierarchical reconciliation | Compute | SKU x site to category x site |
| Cold-start path | Compute | heuristics and similar-SKU transfer |
| Quantile forecasts | Compute | q10, q50, q90, q97, mean |
| Ordering rule | Compute | newsvendor with shelf life and lead time |
| Training | Compute | overrides feed back into training |
| Purchase proposals | Output | purchase quantities |
| Planners | Output | override with reasons |
| Planner overrides | Output | logged, reason-coded |
Source: This page's text
Sources: sales + availability (hourly), promotions, prices, weather, events
─► Demand reconstruction: correct sales for stock-outs and substitutions
─► Feature pipeline: lags and rolling stats, price and promo features,
seasonality and holidays, weather, hierarchy and site embeddings
─► Global model across SKUs and sites (GBDT with quantile or Tweedie
objectives; deep sequence model as challenger), one model per horizon
band or horizon as a feature
─► Hierarchical reconciliation (SKU × site ↔ category × site ↔ SKU national)
─► Cold-start path: heuristics and similar-SKU transfer for new items/sites
─► Quantile forecasts ─► Ordering rule (newsvendor with shelf life, stock
on hand and lead time) ─► purchase proposals ─► planners
─► Planner overrides (logged, reason-coded) ─► feed back into training
Monitoring: accuracy, bias, waste and availability per category and siteDeep dives
CalculatorFrom quantiles to orders
- Target quantile
- 40%
Target quantile = Underage cost ÷ (Underage cost + Overage cost) = 40%
| Case | Underage cost (£) | Overage cost (£) | Target quantile |
|---|---|---|---|
| Short-life salad | 1 | 1.5 | 40% |
Demand vs sales. When strawberries sell out at 15:00, sales understate demand. Training on raw sales teaches the model to under-forecast exactly the items that sell out, which causes more stock-outs — a vicious circle. Reconstruct demand from in-stock hours (sales while available ÷ the share of a typical day’s demand that falls in those hours, from the intraday sales profile), from substitutions given, and from online add-to-basket attempts.
From quantiles to orders. The newsvendor critical ratio sets the target quantile: q* = F⁻¹(cᵤ / (cᵤ + cₒ)), where cᵤ is the underage cost (lost margin, substitution, customer dissatisfaction) and cₒ the overage cost (waste for perishables, holding cost otherwise). With cᵤ = £1 and cₒ = £1.50 for a short-life salad, the ratio is 0.4, so order near the 40th percentile; for tinned goods cₒ is tiny and the target is ~95–97%. Subtract stock on hand and on order, and account for shelf life spanning several days of demand.
Cold start. New SKUs borrow from similar items (attribute and embedding neighbours) with a launch curve; new sites borrow from similar sites scaled by early orders; both switch to their own history as data accumulates.
Trade-offs
- Global vs per-SKU models: one global model learns shared patterns (promotions, weekdays) and handles sparse series far better; per-SKU statistical models are interpretable and cheap but fail on intermittent and new items. Use global, with per-category diagnostics.
- Point vs probabilistic forecasts: ordering needs the distribution, especially for intermittent and perishable items; points are easier to explain but lead to systematic waste or stock-outs.
- Freshness vs compute: an intraday refresh catches weather and promotion surprises for the next days; refreshing all 21M forecasts hourly would cost a lot and churn orders, so refresh only short horizons and perishables.
- Interpretability for planners: planners override what they do not understand. Show drivers (promotion uplift, weather, trend) per forecast and track override accuracy; a model planners trust beats a slightly better black box they override.
Evaluation
Flow · 5 stepsHow evaluation moves from backtests to pilot
- Backtest Rolling-origin backtests forecast 14 days ahead using only data available at each origin.
- Score WAPE and bias by category, site and horizon, plus pinball loss and interval coverage, split by promoted weeks, holidays, intermittent and new SKUs.
- Simulate Replay the ordering rule with historical stock levels and lead times to estimate waste % and availability %.
- Pilot Pilot sites are compared with matched control sites on waste % and availability %, tracking planner override rate and whether overrides help.
- Monitor Daily bias per category and site alerts beyond ±5% for a week, with coverage drift and data-freshness checks.
Data
| Step | Title | What happens |
|---|---|---|
| 1 | Backtest | Rolling-origin backtests forecast 14 days ahead using only data available at each origin. |
| 2 | Score | WAPE and bias by category, site and horizon, plus pinball loss and interval coverage, split by promoted weeks, holidays, intermittent and new SKUs. |
| 3 | Simulate | Replay the ordering rule with historical stock levels and lead times to estimate waste % and availability %. |
| 4 | Pilot | Pilot sites are compared with matched control sites on waste % and availability %, tracking planner override rate and whether overrides help. |
| 5 | Monitor | Daily bias per category and site alerts beyond ±5% for a week, with coverage drift and data-freshness checks. |
Source: This page's text
| Box | Group | Detail |
|---|---|---|
| Historical data | Offline | only data available at each origin |
| Rolling-origin backtests | Offline | weekly origins, 14 days ahead |
| Metrics | Offline | WAPE, bias, pinball, coverage |
| Business simulation | Offline | replay ordering rule |
| Pilot vs control | Online | difference-in-differences |
| Monitoring | Monitoring | bias, coverage, freshness |
Source: This page's text
- Offline: rolling-origin backtests (e.g. weekly origins over a year, each forecasting 14 days ahead with only data available then); WAPE = Σ|y − ŷ| / Σy and bias = Σ(ŷ − y) / Σy by category, site and horizon; pinball loss and interval coverage for quantiles; separate results for promoted weeks, holidays, intermittent and new SKUs.
- Business simulation: replay the ordering rule with historical stock levels and lead times to estimate waste % and availability % — the metrics that decide go/no-go.
- Online: pilot sites vs matched control sites (difference-in-differences over several weeks) on waste % and availability %; track planner override rate and whether overrides improve or worsen accuracy.
- Monitoring: daily bias per category and site (alert when beyond ±5% for a week), coverage drift, data-freshness checks on sales and availability feeds, late promotions not loaded.
What a strong design shows
- Reconstructs true demand from censored sales (stock-outs, substitutions) before modelling.
- Produces quantile forecasts and turns them into orders with a newsvendor rule tied to waste and availability costs.
- Chooses a global model with hierarchical reconciliation and a concrete cold-start path.
- Evaluates with rolling-origin backtests, bias and pinball loss, then simulates waste and availability before piloting against control sites.
- Treats planner trust and overrides as part of the system and measures them.