Skip to main content

Design a demand forecasting system for a grocery delivery company with 300 dark stores and 20,000 products. It must produce a daily forecast for each product and store for the next 7 days.

System design · Intermediate 3

Short answer

Clarify the decision the forecast drives, the horizon and the cost of overstock against stockouts. Then: clean sales history corrected for stockouts, features for calendar, festivals, price, promotions and weather, a simple seasonal baseline, one global gradient-boosted model across all series, backtesting over time, quantile forecasts for safety stock, and monitoring.

Deeper answer

First ask what the forecast is used for. Here it drives daily replenishment, so the horizon is 7 days and the level is product and store. Ask which error costs more: waste on fresh items, or stockouts on staples. That decides whether to forecast a quantile instead of the mean.

Data: past sales are not the same as demand. When a product was out of stock, sales were zero but demand was not, so those periods must be marked or corrected. Features include lags and rolling averages, day of week, festivals such as Diwali, salary dates, price, promotions and rain. With 6 million series, many of them sparse, one global model trained across all series, such as gradient boosting, works better than a model per series.

Trade-offs: a seasonal naive baseline is hard to beat for stable items, so always compare against it. Evaluate with backtesting over rolling time windows, with a metric such as weighted absolute percentage error, and check bias, because steady over-forecasting creates waste. At scale, the first problems are promotions with no history, festivals that move dates each year, and feedback from stock limits.

What a strong answer covers

Answer it out loud in the mock interview about 2.5 min

Follow-ups to expect

Common mistakes

Learn it

Regression

Practice System design questions

More on this topic

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.