Skip to main content
← PROBLEMS / SYSTEM-DESIGN
An end-to-end domain learning journey

Design a Supply Chain Inventory
& Demand Forecasting System.

Design an end-to-end Supply Chain Inventory & Demand Forecasting platform generating daily P10/P50/P90 forecasts for 50M SKU-Store combinations, reconciling hierarchies via MinT, and emitting MILP-optimized Purchase Orders.
Start the journey7 stages· Last modified Nov 24, 2026
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

When durability and read throughput pull in opposite directions, unify POS sales, ERP stock, supplier lead times, and weather/promo signals in an Iceberg Feature Lakehouse feeding distributed Spark/Ray TFT training and a global MILP optimizer.

TL;DR30-second simplified summary
▾

To finish 50M series inside a 4-hour nightly SLA, stream Arrow batches to Ray GPU TFT workers, reconcile with diagonal WLS MinT per category, and solve MILP per DC-vendor.

Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
Hierarchical Demand Forecasting (MinT) & Multi-Echelon MRP
Hierarchical Demand Forecasting & Multi-Echelon MRP reconciles SKU-store predictions with regional and national totals via MinT (Minimum Trace) and converts P50/P90 uncertainty into automated safety-stock replenishment.
Full walkthrough · 7 stages
01
foundation

50M Series Scale & Daily Batch Window.

Why this matters: Size compute, storage, and SLA windows for 50M SKU-Store time series.

Think of 50M Series Scale & Daily Batch Window as the intuition layer for Design a Supply Chain Inventory & Demand Forecasting System: Size compute, storage, and SLA windows for 50M SKU-Store time series.

50M SKU-Store combinations x 730 days of history = 36.5B daily feature rows (~4 TB Zstd Parquet in Iceberg). The nightly forecast + MILP optimization must complete within a 4-hour batch window (00:00–04:00 UTC) so ERP Purchase Orders are ready before 05:00 warehouse shifts.

Batch Scale

50M Series & 4-Hour Nightly Replenishment Window

50M SKU-StoreSeriesData scale4-Hour NightlyWindowBatch deadlineSpark + Ray GPUClusterForecast compute05:00 ERP POCutoverBusiness SLACompletes in <3h

1.Global Model vs Per-SKU: A single global TFT model learns cross-SKU promo patterns, avoiding 50M tiny models.

2.1-Hour Buffer: Targeting 3h completion inside a 4h SLA leaves room for MILP retries.

Global Temporal Fusion Transformers on Spark/Ray score 50M series inside a strict 4-hour nightly SLA.

02
foundation

Lakehouse Ingestion & Multi-Signal Architecture.

Why this matters: Unify streaming POS/ERP events with external promo and weather data.

Think of Lakehouse Ingestion & Multi-Signal Architecture as the intuition layer for Design a Supply Chain Inventory & Demand Forecasting System: Unify streaming POS/ERP events with external promo and weather data.

POS checkouts and ERP inventory adjustments stream via Kafka into Apache Iceberg for real-time stockout alerting, while supplier lead-time logs and weather/promo calendars join nightly in the Feature Store before distributed TFT inference.

Data Backbone

Kafka + Iceberg Feature Lakehouse Pipeline

POS + ERP + WeatherRaw signalsKafka + IcebergUnified storageSpark/Ray TFTQuantile engineMinT + MILPOptimizerExecution tierBuilds 730d tensors

1.ACID Time-Travel: Iceberg snapshots allow exact reproduction of last Tuesday's forecast inputs.

2.Exogenous Signals: Future-known promo calendars and 14-day weather forecasts boost TFT accuracy.

An Iceberg Feature Lakehouse unifies real-time POS/ERP state with batch promo and weather calendars.

Engineering Decision Framework
Problem
How to implement Design a Supply Chain Inventory & Demand Forecasting System without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
When durability and read throughput pull in opposite directions, unify POS sales, ERP stock, supplier lead times, and weather/promo signals in an Iceberg Feature Lakehouse feeding distributed Spark/Ray TFT training and a global MILP optimizer.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Design a Supply Chain Inventory & Demand Forecasting System experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
intermediate

Distributed Ray/Spark TFT Quantile Inference.

Why this matters: Scale Temporal Fusion Transformer inference across 50M series using GPU workers.

Training 50M separate ARIMA models fails on sparse SKUs and takes too long.

A global Temporal Fusion Transformer (TFT) trained across all SKUs shares seasonal and promotional representations.

Distributed ML

Category-Sharded Ray GPU TFT Inference

Iceberg CategoryShardsPartitioned inputRay Data StreamerData loader32x GPU TFT WorkersQuantile scorerMonotonicity GuardOutput validatorFeeds GPU workers

1.Quantile Crossing Fix: Sort or clamp (P10, P50, P90) outputs so P90 never dips below P50.

2.Cold-Start SKUs: Global TFT uses static item metadata (category, price) to forecast brand-new SKUs.

Streaming Arrow batches into a global TFT on Ray GPUs scores 50M series in ~90 minutes.

04
intermediate

Parallel Category-Scoped MinT Reconciliation.

Why this matters: Reconcile 50M forecasts without inverting a 50M x 50M matrix.

Think of Parallel Category-Scoped MinT Reconciliation as the intuition layer for Design a Supply Chain Inventory & Demand Forecasting System: Reconcile 50M forecasts without inverting a 50M x 50M matrix.

A single global MinT matrix over 50M nodes is intractable. Because product categories (e.g., Dairy, Electronics) have disjoint replenishment hierarchies, we partition reconciliation by Category x Country, reducing each MinT solve to ~50K nodes that finish in seconds per Spark executor.

Scalable MinT

Category-Partitioned Diagonal WLS MinT

Category PartitionIndependent unitDiagonal WLS MatrixFast covarianceSpark MapInPandasDistributed solverCoherent QuantilesClean MRP inputSolves linear system

1.Non-Negativity Clip: MinT projections can occasionally produce tiny negative values; clip >= 0 and re-balance.

2.O(N) Scaling: Using diagonal WLS covariance makes 50M-node reconciliation fast and memory-safe.

Partitioning by disjoint product categories and using diagonal WLS makes MinT scale linearly.

05
intermediate

Decomposed MILP Purchase Order Optimization.

Why this matters: Generate constrained Purchase Orders and Transfer Orders within 30 minutes.

Think of Decomposed MILP Purchase Order Optimization as the intuition layer for Design a Supply Chain Inventory & Demand Forecasting System: Generate constrained Purchase Orders and Transfer Orders within 30 minutes.

Solving one MILP with 50M integer variables would time out. We decompose by Regional DC + Supplier Vendor group, optimizing multi-SKU truckloads, MOQ rounding, and DC cubic capacity in parallel across Spark workers using HiGHS.

Order Optimization

Vendor-Decomposed MILP Replenishment

MRP Netting EngineNet demandDC x VendorPartitionParallel scopeHiGHS MILP SolverOrder optimizerIdempotent ERP SinkExecution outputSolves truckloads

1.Idempotent PO Keys: Key every PO by (plan_date, dc_id, vendor_id) so retries never double-order.

2.Case-Pack Rounding: Suppliers ship in full cases/pallets; MILP models exact discrete pack multiples.

Decomposing MILP by DC and vendor solves truckload and capacity constraints in parallel.

06
advanced

Real-Time Intraday Stockout & Disruption Alerts.

Why this matters: React to sudden viral spikes or port delays without waiting for the nightly batch.

Think of Real-Time Intraday Stockout & Disruption Alerts as the intuition layer for Design a Supply Chain Inventory & Demand Forecasting System: React to sudden viral spikes or port delays without waiting for the nightly batch.

While POs run nightly, a viral social-media mention can wipe out regional stock by noon. A Flink streaming job monitors live Kafka POS velocity against remaining DC safety stock, firing intraday emergency Transfer Orders and Stockout Alerts within 60 seconds.

Intraday Agility

Flink Intraday Burn-Rate & Emergency Transfer

Live Kafka POSReal-time demandFlink Burn MonitorRunout predictorStockout Alert BusEarly warningEmergency TransferFast mitigationFlags <4h runway

1.60-Second Detection: Intraday Flink alerts catch viral sell-outs 12 hours before nightly batch runs.

2.Cross-DC Rebalance: Re-routing surplus stock from neighboring DCs avoids expedited air-freight.

Streaming Flink burn-rate checks catch intraday viral spikes long before the nightly batch.

07
advanced

Forecast Value Added (FVA) & Human Override Tracking.

Why this matters: Measure whether planner manual overrides actually improve or hurt forecast accuracy.

Think of Forecast Value Added (FVA) & Human Override Tracking as the intuition layer for Design a Supply Chain Inventory & Demand Forecasting System: Measure whether planner manual overrides actually improve or hurt forecast accuracy.

Supply chain planners often manually override ML forecasts. Logging both the raw TFT/MinT output and the final overridden number in Iceberg enables Forecast Value Added (FVA) tracking—automatically flagging planners or SKUs where overrides consistently worsen WAPE/Bias.

Governance & FVA

ML Baseline vs. Planner Override FVA Loop

ML + MinT ForecastControl forecastPlanner Override UIHuman judgmentWeekly FVAScorecardAccuracy auditFeature GapDiscoveryModel upgradeLogs override WAPE

1.Reason Codes: Requiring reason codes (e.g., 'local event') turns overrides into new model features.

2.Bias Audit: FVA eliminates optimism/pessimism bias in manual planner adjustments.

Forecast Value Added auditing measures whether human overrides improve or degrade WAPE.

Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

How do you make MinT hierarchical reconciliation and MILP optimization tractable for 50M SKU-Store series within a 4-hour nightly window?

Recommended Learning Flow