---
title: SKU-level demand forecasting for online grocery
url: https://gurkanozkan.ai/learn/design/mle-sku-level-demand-forecasting-for-online-grocery-08/
markdown: https://gurkanozkan.ai/learn/design/mle-sku-level-demand-forecasting-for-online-grocery-08.md
kind: design
role: ML engineering
json: https://gurkanozkan.ai/api/learn/design/mle-sku-level-demand-forecasting-for-online-grocery-08.json
---

# 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.

## Constraints

- 50k SKUs × 30 sites × 14 horizons ≈ 21M forecasts/day
- nightly batch with an intraday refresh
- many intermittent SKUs

## What to cover

- **Requirements**: Forecast daily demand per product per fulfilment centre for the next 14 days to drive purchasing, minimising both waste and stock-outs.
- **Estimates**: 50k SKUs × 30 sites × 14 horizons ≈ 21M forecasts/day; nightly batch with an intraday refresh; many intermittent SKUs.
- **API**
- **Data model**
- **Architecture**: Demand 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-offs**: global vs per-SKU models; point vs probabilistic forecasts; freshness vs compute; interpretability for planners.
- **Evaluation**: Offline: 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

### 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

- **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

```
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

**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

- **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.*
