LearnSystem design

SKU-level demand forecasting for online grocery

Forecast daily demand per product per fulfilment centre for the next 14 days to drive purchasing, minimising both waste and stock-outs.

ML engineering8 parts

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.

  1. RequirementsForecast daily demand per product per fulfilment centre for the next 14 days to drive purchasing, minimising both waste and stock-outs.
  2. Estimates50k SKUs × 30 sites × 14 horizons ≈ 21M forecasts/day; nightly batch with an intraday refresh; many intermittent SKUs.
  3. API
  4. Data model
  5. 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.
  6. Deep dives
  7. Trade-offsglobal vs per-SKU models; point vs probabilistic forecasts; freshness vs compute; interpretability for planners.
  8. 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

Nightly batch timingA left-to-right flow of the nightly batch: data cut-off at 23:00, features from 23:00 to 00:30, inference from 00:30 to 01:00, reconciliation and checks from 01:00 to 01:30, and publish by 02:00. A final box shows the intraday refresh for the next 1–3 days and perishables.Data cut-off23:00Features23:00–00:30Inference00:30–01:00Reconciliation and checks01:00–01:30Publishby 02:00Intraday refreshnext 1–3 days, perishables ~30%12345Nightly batchIntraday
  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.

The nightly window runs from the 23:00 data cut-off to publish by 02:00, with a separate intraday refresh for short horizons and perishables.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
Data
Steps
StepTitleWhat happens
1Data cut-offThe nightly window opens at the 23:00 data cut-off.
2FeaturesFeature building and joins run 23:00–00:30 and are the real time sink.
3InferenceInference runs 00:30–01:00 on 21M rows.
4Reconcile and publishReconciliation and checks run 01:00–01:30, then forecasts publish by 02:00.
5Intraday refreshIntraday refresh covers only the next 1–3 days and perishables (~30% of SKUs), about 1.4M forecasts.

Source: This page's text

Boxes
BoxGroupDetail
Data cut-offNightly batch23:00
FeaturesNightly batch23:00–00:30
InferenceNightly batch00:30–01:00
Reconciliation and checksNightly batch01:00–01:30
PublishNightly batchby 02:00
Intraday refreshIntradaynext 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

Architecture for SKU-level demand forecastingSources flow through demand reconstruction and the feature pipeline into a global model, which feeds hierarchical reconciliation and then the quantile forecasts. The cold-start path for new items and sites feeds the quantile forecasts directly. Quantile forecasts drive a newsvendor-style ordering rule that produces purchase proposals for planners; planner overrides are logged and feed back into training.Sourcessales, availability, promotions,pricesDemand reconstructioncorrect for stock-outs andsubstitutionsFeature pipelinelags, seasonality, weather,embeddingsCold-start pathheuristics andsimilar-SKU transferGlobal modelGBDT or deepsequence modelHierarchical reconciliationSKU x site to category x siteQuantile forecastsq10, q50, q90, q97, meanOrdering rulenewsvendor with shelf life and leadtimePurchase proposalspurchase quantitiesPlannersoverride with reasonsPlanner overrideslogged, reason-codedTrainingoverrides feed back into training12345InputComputeOutput
  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.

Demand is reconstructed, modelled globally, reconciled and turned into quantile-based purchase proposals, with planner overrides feeding back into training.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
Data
Steps
StepTitleWhat happens
1Reconstruct demandHourly sales and availability, promotions, prices, weather and events are reconstructed into true demand, correcting for stock-outs and substitutions.
2Model and reconcileThe feature pipeline feeds the global model across SKUs and sites, whose output is reconciled hierarchically before becoming quantile forecasts.
3Cold startNew SKUs and sites use heuristics and similar-SKU transfer, feeding the quantile forecasts directly.
4OrderQuantile forecasts feed the newsvendor-style ordering rule, which sets purchase quantities as proposals for planners.
5Override and retrainPlanners override forecasts with reasons; overrides are logged and feed back into training.

Source: This page's text

Boxes
BoxGroupDetail
SourcesInputsales, availability, promotions, prices
Demand reconstructionComputecorrect for stock-outs and substitutions
Feature pipelineComputelags, seasonality, weather, embeddings
Global modelComputeGBDT or deep sequence model
Hierarchical reconciliationComputeSKU x site to category x site
Cold-start pathComputeheuristics and similar-SKU transfer
Quantile forecastsComputeq10, q50, q90, q97, mean
Ordering ruleComputenewsvendor with shelf life and lead time
TrainingComputeoverrides feed back into training
Purchase proposalsOutputpurchase quantities
PlannersOutputoverride with reasons
Planner overridesOutputlogged, 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 site

Deep dives

CalculatorFrom quantiles to orders

Target quantile = Underage cost ÷ (Underage cost + Overage cost)

Worked cases
CaseUnderage cost (£)Overage cost (£)Target quantile
Short-life salad11.540%
The newsvendor critical ratio sets the target quantile: order near the 40th percentile for the short-life salad case.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.

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

How evaluation moves from backtests to pilotA left-to-right flow: historical data feeds rolling-origin backtests, which produce WAPE, bias and pinball metrics, then a business simulation replays the ordering rule to estimate waste and availability. The result is checked online as pilot sites against matched control sites, with monitoring of bias, coverage and data freshness.Historical dataonly data available at each originRolling-origin backtestsweekly origins, 14 days aheadMetricsWAPE, bias, pinball, coverageBusiness simulationreplay ordering rulePilot vs controldifference-in-differencesMonitoringbias, coverage, freshness12345OfflineOnlineMonitoring
  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.

Evaluation moves from rolling-origin backtests and metrics into a business simulation, then a pilot against control sites and ongoing monitoring.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.
Data
Steps
StepTitleWhat happens
1BacktestRolling-origin backtests forecast 14 days ahead using only data available at each origin.
2ScoreWAPE and bias by category, site and horizon, plus pinball loss and interval coverage, split by promoted weeks, holidays, intermittent and new SKUs.
3SimulateReplay the ordering rule with historical stock levels and lead times to estimate waste % and availability %.
4PilotPilot sites are compared with matched control sites on waste % and availability %, tracking planner override rate and whether overrides help.
5MonitorDaily bias per category and site alerts beyond ±5% for a week, with coverage drift and data-freshness checks.

Source: This page's text

Boxes
BoxGroupDetail
Historical dataOfflineonly data available at each origin
Rolling-origin backtestsOfflineweekly origins, 14 days ahead
MetricsOfflineWAPE, bias, pinball, coverage
Business simulationOfflinereplay ordering rule
Pilot vs controlOnlinedifference-in-differences
MonitoringMonitoringbias, 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.

Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.