The interview problem

Practice prompt

A retailer forecasts tomorrow's item–store demand from sales history, but popular items frequently sell out before closing. Design a forecasting pipeline that handles hidden demand, explain what is identifiable from the observations and propose an evaluation that does not reward understocking.

Original ML-design practice, not a reported company interview. Numerical examples are hypothetical. Primary AWS documentation and research references retrieved September 27, 2026. Interview date: not applicable.

1. Define the counterfactual target

The desired target is demand under a specified availability, price and assortment scenario, not simply next day's recorded sales. In a simplified lost-sales model with no replenishment during the interval, sales S = min(D, C), where D is latent demand and C is saleable inventory. If S is below C and there are no other barriers to purchase, D = S. If S = C, we know only D ≥ C.

This model assumes unmet demand disappears rather than becoming a backorder, and that availability does not itself change underlying customer arrivals or substitutions. Real retail can violate both assumptions. State the simplification before fitting a distribution to it. A stockout can change demand for related items and future customer behavior.

AWS's missing-values guidance uses unavailable products as an example of sales observations that should not be confused with ordinary demand. Missing records, genuine observed zero demand and stockout-censored zero sales require different data states. This guide develops an original censoring-aware solution rather than treating all three as fill-with-zero cases.

2. Reconstruct availability before modeling

sales + inventory movements + shelf/online availability
                           ↓
             interval-level availability reconstruction
                           ↓
        uncensored / censored / unknown-quality labels
                           ↓
        distribution model + explicit observation process
                           ↓
     demand quantiles → inventory-policy evaluation → rollout

Collect saleable inventory, replenishments, returns, stock adjustments, opening hours, assortment and price changes with event times and ingestion times. Recorded warehouse inventory may not equal shelf availability. Inventory drift, delayed updates and checkout restrictions can produce apparent zeros unrelated to customer interest.

Use shorter intervals when replenishment or stockouts occur within a day. Preserve unknown availability rather than guessing an exact censoring threshold. Separate data-quality exclusion from genuine in-stock zero sales, and report excluded coverage. Features at forecast issuance must be available then; future realized stockouts cannot be used as if known beforehand.

Keep latent-demand forecasts separate from sales forecasts conditional on a planned inventory level. The latter may legitimately predict low sales under low stock, while the former is needed to challenge that low-stock policy. Feeding the previous policy's constraints into both without distinction can perpetuate underordering.

3. Use inequalities instead of invented labels

For a chosen count distribution Pθ(D | x), an uncensored observation contributes log Pθ(D = s | x). A sold-out interval with capacity c contributes log Pθ(D ≥ c | x). The second term is a tail probability, not a point label at c. Compute it with numerically stable survival probabilities rather than subtracting two nearly equal floating-point values.

Take a Poisson illustration with mean λ = 4 and capacity c = 2. P(D = 0) = e⁻⁴ ≈ 0.018316 and P(D = 1) = 4e⁻⁴ ≈ 0.073263. Thus observing a sellout contributes P(D ≥ 2) = 1 − 5e⁻⁴ ≈ 0.908422. Treating those two sales as an exact demand label instead uses P(D = 2) = 8e⁻⁴ ≈ 0.146525, a different observation model.

Expected observed sales are 0 × P(D=0) + 1 × P(D=1) + 2 × P(D≥2) ≈ 1.890106, although expected demand is four. Expected lost demand is 4 − 1.890106 ≈ 2.109894. A forecaster that learns 1.89 perfectly from these sales is still unsuitable as an unconstrained demand forecast.

At capacity zero, S = 0 regardless of demand and P(D ≥ 0) = 1. This interval contributes no demand information through this simplified likelihood. It does not justify a zero demand estimate. Likewise, if every interval sells out at the same low cap, very large means can all explain the data well; censoring-aware fitting does not magically identify the hidden tail.

4. Choose assumptions that can be challenged

Start with seasonal in-stock baselines, then a shared count or quantile model that borrows information across comparable items and stores. A censored count likelihood needs a suitable distribution; Poisson's equality of mean and variance may be unrealistic. Compare alternatives and calibration rather than interpreting a convenient likelihood as truth.

Inventory levels are often chosen using prior forecasts and information about demand. The displayed likelihood assumes D and C are conditionally independent given x, or that the joint demand-and-capacity observation process is correctly modeled. If planners use unrecorded demand signals to set C, merely adding the cap as a feature does not establish that assumption. Conditional inference requires modeling enough relevant context or acknowledging informative censoring. Excluding all sold-out intervals can bias the sample toward low-demand days. Replacing every censored label with a model estimate can create an unobserved feedback loop that appears more certain after each iteration.

Use stockout timing, search interest and comparable in-stock locations as additional signals with explicit assumptions. Scaling two hours of sales to a whole day assumes a demand arrival pattern; morning-heavy shopping breaks uniform scaling. Comparable stores may differ in customers, promotions and substitution opportunities. Report sensitivity across plausible hidden-demand scenarios when data cannot resolve them.

5. Evaluate without pretending hidden demand is observed

Use time-based backtests on periods with trustworthy availability and independently tracked outcomes. Artificially censor known in-stock sequences at several caps, train or infer using only the censored view, and compare recovered estimates with the retained truth. This tests behavior under the imposed censoring mechanism; it does not prove performance under natural, potentially informative stockouts.

On genuinely censored intervals, sales are a lower bound under the simple model, not ground-truth unrestricted demand. Do not evaluate forecast accuracy against imputed labels produced by the same model. Track held-out observation likelihood where appropriate, calibration on observable cases and decision outcomes separately.

For a hypothetical replay, policy A has holding/waste cost 300 and lost-sales cost 900, total 1,200. Policy B has holding/waste cost 500 and lost-sales cost 500, total 1,000: a 16.67% reduction. B carries more inventory but has lower total modeled cost. The result depends on simulated demand, cost assumptions and lead times; it is not a measured production saving.

Validate through a bounded inventory experiment where feasible, tracking service level, waste, margin and substitutions across affected products. A store-level or market-level design may be needed when customer substitution couples items. Keep operational caps and rollback rules so an uncertain tail forecast cannot trigger unbounded ordering.

6. Expose uncertainty to the ordering system

Publish versioned demand distributions or quantiles together with horizon, price/assortment assumptions and data-quality coverage. Inventory policy uses lead-time demand and business costs; a point forecast alone does not determine the right stock level. Poorly identified items should carry wider uncertainty or an explicit fallback to a comparable-item baseline.

Monitor stockout fraction, availability-quality failures, forecast calibration where observable, ordering changes and new-policy exposure. Recheck label construction when inventory software changes. A sudden improvement in sales-label accuracy can merely mean the system learned a stricter stock cap.

Test late replenishment events, phantom stock, returns producing negative net sales, price changes, new items and all-zero-capacity histories. Choose whether to model gross demand and returns separately rather than feeding negative counts into a nonnegative demand likelihood.

7. Follow-ups and self-review

Follow-ups: Are sold-out sales exact labels? They are lower bounds under the stated model. Can all-stockout data recover arbitrary demand tails? Not without further information or assumptions. Is dropping stockouts unbiased? Not generally. Does successful artificial-censoring recovery settle real-world validity? No. Can a demand forecast be worse at predicting recorded sales but better for replenishment? The numerical example shows why.

Score 0–2 each for target/observation separation, availability reconstruction, censored likelihood, identifiability caveats and decision-based evaluation. A strong answer explains what the data does not reveal.

Sources and next steps

  • AWS Forecast: handling missing values — unavailable products and sales observations; documentation date not established.
  • FreshRetailNet-50K — 2025 research dataset focused on stockout-annotated censored demand; cited as research context, not used for the illustrative results.

The likelihood example, pipeline and policy-cost comparison are original. Continue with demand forecasting for the broader forecasting service.

Continue your preparation

Choose a connected learning path or browse more ML system design questions. Read our editorial method and attribution policy.