The interview problem
A retailer forecasts next week's unit demand separately for stores, regions and the whole company. The regional model predicts 120 units for a small two-store region, while store models predict 70 and 30. Build a forecasting service whose published totals agree, explain how to choose which forecasts to adjust, and handle uncertainty and hierarchy changes.
Original ML-design practice, not a reported company interview. Counts and errors are hypothetical. Technical references retrieved September 27, 2026.
1. Define the quantity before enforcing arithmetic
Use the same target week, forecast creation time, unit definition and eligible stores at every level. Demand is not necessarily observed sales: stockouts can censor the target. Returns, transfers and canceled orders need consistent treatment. A parent cannot equal the sum of children if it includes online demand that no child contains.
Represent bottom-level series as a vector b and all reported series as y = Sb, where S is a versioned summing matrix. For the two-store example, y = (total, A, B) and S has rows (1,1), (1,0), (0,1). Overlapping groupings such as geography and product category can still be represented through shared disjoint bottom-level cells; avoid counting the same unit twice.
Coherence means satisfying these identities. It does not mean the forecasts are accurate, unbiased or useful for inventory decisions. Define business evaluation weights separately from the structural identities.
2. Establish simple coherent baselines
Bottom-up forecasting trusts the store models and sums them: (100,70,30). It is simple and preserves local detail, but can aggregate noisy sparse forecasts. Top-down forecasting trusts the total and divides it using stated shares. With shares 70% and 30%, it produces (120,84,36). Historical shares can fail when a store opens or a promotion changes demand.
Do not choose a method only because it makes the dashboard add up. Compare these baselines with reconciliation that uses all levels, on rolling historical forecast origins and untouched future outcomes.
3. Reconcile a concrete inconsistency
Start with base forecasts (120,70,30). Under equal error weights, choose a and b to minimize (a + b − 120)² + (a − 70)² + (b − 30)². Setting derivatives to zero gives 2a + b = 190 and a + 2b = 150. Therefore a = 76⅔, b = 36⅔ and total = 113⅓.
The total moves down by 6⅔ and each store moves up by 6⅔. The sum of squared adjustments is 3 × (20/3)² = 133⅓. Bottom-up changes the total by 20, giving adjustment cost 400. This demonstrates minimum adjustment under equal weights; it does not demonstrate smaller future forecast error.
Suppose the total forecast's error variance is 400, while each store's is 25, with zero cross-series error covariance in this illustrative model. Weighted reconciliation minimizes (a+b−120)²/400 + (a−70)²/25 + (b−30)²/25. Symmetry gives equal store adjustments d, satisfying d = (20 − 2d)/16. Thus d = 10/9, stores become approximately 71.111 and 31.111, and the total becomes 102.222. The less reliable total moves more.
4. Estimate error structure carefully
In matrix form, a common linear reconciliation is ỹ = S(SᵀW⁻¹S)⁻¹SᵀW⁻¹ŷ, where W is the base forecast-error covariance for the relevant horizon. This displayed inverse form assumes positive-definite W and full-column-rank S; singular estimates need regularization or an appropriate alternative solver. Use numerical linear solves rather than explicitly computing inverses. MinT's optimality applies within its stated linear unbiased reconciliation framework with the relevant error covariance; it is not an unconditional production superiority claim.
Build aligned forecast-error vectors at historical origins using only information then available. Shared weather or promotions can make store errors correlated. Ignoring that dependence can count nearly duplicated evidence as independent. Separate horizons when their error structures differ, or justify a simplifying approximation through backtests.
With thousands of series and little history, a dense sample covariance can be singular or unstable. Compare diagonal variance weighting and shrinkage with simpler bottom-up forecasts. A complex covariance estimate that changes wildly across retraining runs can make reconciliation worse. Track condition numbers, adjustment magnitudes and performance by hierarchy level.
5. Publish a consistent forecast snapshot
versioned observations + hierarchy → base models at each level
historical forecast errors → horizon-specific reconciliation parameters
base forecast snapshot → reconcile + constraint checks → atomic published version
↘ backtests and adjustment diagnosticsEach published version binds forecast origin, horizon, hierarchy, base model versions, reconciliation method and parameters. Validate leaf completeness and matrix identities before promotion. Publish the entire hierarchy snapshot atomically and require readers to pin its version across queries, so a consumer cannot read this week's total and last week's store forecasts.
If one store forecast is missing, use an explicit fallback model or block the affected publication; do not silently treat it as zero. For new stores with little history, provide a documented cold-start baseline and uncertainty. If a store moves regions, historical training data and evaluation must use clearly defined as-of or restated membership, with no accidental future information.
Scale by exploiting sparse hierarchy structure and independent blocks when valid. A dense 10,000 × 10,000 covariance has 100 million entries, or 800 MB at eight bytes per entry before factorization and temporary arrays. Doubling series count quadruples dense storage. Partitioning can reduce cost but may discard important cross-block relationships; measure that trade-off.
6. Preserve nonnegativity and uncertainty deliberately
Linear reconciliation can yield negative store demand. If the target must be nonnegative, solve a constrained weighted least-squares problem over b ≥ 0 and then compute Sb. Clipping every node independently generally breaks coherence. This constrained procedure changes the linear estimator and its theoretical properties; evaluate it as its own method.
Expected unit demand can be fractional. If an ordering system needs integer quantities, keep the forecast separate from the downstream allocation decision. Rounding store forecasts and independently rounding the total can make them disagree. A constrained allocation can impose an integer total, minimum orders and inventory costs explicitly.
Marginal quantiles do not generally add. As an original example, two independent stores each have demand 0 or 10 with equal probability. Each store's 75th percentile is 10. Their total is 0,10,20 with probabilities 0.25,0.50,0.25, so its 75th percentile, defined as the smallest value with cumulative probability at least 0.75, is 10 rather than 20.
For probabilistic reconciliation, generate joint sample paths preserving relevant dependence, reconcile each path, then calculate node-level summaries. Each sample can be coherent even though the displayed marginal interval endpoints do not sum. Reconciliation alone does not guarantee calibrated intervals; evaluate coverage and distributional scores afterward.
7. Distinguish useful adjustment from enforced agreement
Use rolling-origin tests with hierarchy and features available at each origin. Compare base, bottom-up, top-down, equal-weight, variance-weighted and shrinkage methods using fixed evaluation rules. Report errors by level and business-critical slices, avoiding an aggregate score dominated merely by the number of leaves. Metrics involving percentage error need care for zero-demand series.
Monitor coherent-identity residuals as a correctness check and forecast loss as a quality check. Large corrections may indicate drift, a hierarchy mismatch or a broken base model. If the observed truth is (100,70,30), bottom-up is perfect and equal-weight reconciliation is worse despite being coherent. This counterexample prevents mistaking a mathematical projection for an accuracy guarantee.
Include downstream inventory simulations with shortage and overstock costs. A more accurate mean forecast can still be inappropriate for an asymmetric stocking decision that needs a different quantile. Keep managerial overrides versioned and reconcile or flag the resulting inconsistency instead of silently changing one parent number.
8. Follow-ups and self-review
Follow-ups: Why does the noisy total move more in the weighted example? Its error variance gives it less weight. Can an approved total be a fixed business constraint? Yes, but that is a different constrained problem, and inconsistent hard constraints may have no solution. Why do coherent samples yield non-additive quantiles? Quantiles summarize different portions of each marginal distribution. Can hierarchy changes be treated as a metadata-only edit? No: they change aggregation, features and evaluation populations.
Score 0–2 each for target and hierarchy definition, correct worked reconciliation, covariance estimation without leakage, coherent versioned publication, and uncertainty/constraint handling. A strong answer keeps consistency, statistical accuracy and operational utility separate.
Sources and next steps
- Hyndman and Athanasopoulos: forecast reconciliation — reconciliation formulation and covariance approximations.
- Reconciled distributional forecasts — joint forecast paths and probabilistic reconciliation.
The two-store calculations, quantile counterexample, storage estimate and publishing architecture are original worked practice.
Continue your preparation
Choose a connected learning path or browse more ML system design questions. Read our editorial method and attribution policy.