Problem Statement
Inventory management without forecasting leads to two costly failure modes: stockouts that block sales and frustrate customers, and overstocking that ties up capital and causes waste. Most small and medium businesses rely on intuition or simple reorder-point rules that ignore seasonality and trend shifts. The goal was to build a data-driven forecasting service that integrates with existing inventory systems, generates interpretable predictions, and provides actionable reorder recommendations rather than opaque model outputs.
Key Challenges:
- Short and irregular historical transaction records for many SKUs
- Seasonality patterns varying significantly across product categories
- Business user requirement for interpretable, explainable predictions
- Integration with existing inventory and purchasing workflows
- Graceful degradation when historical data is insufficient
System Architecture
Historical transaction data is loaded and preprocessed per SKU. A model selection layer chooses the appropriate forecasting approach based on data availability and pattern type. Predictions are post-processed to generate reorder recommendations factoring in lead times and safety stock buffers. Results are served via FastAPI for integration with inventory management systems.
Data Preparation
Pandas-based pipeline cleaning transaction records, aggregating to daily/weekly demand, handling missing periods (zero-sales days vs. no-data gaps), and computing derived features like rolling averages and seasonal indices.
Model Selection
Tiered model selection: exponential smoothing for short series, SARIMA for seasonal patterns, and gradient-boosted regressors with time features for SKUs with rich history. Cross-validation on held-out periods selects the best model per SKU.
Recommendation Engine
Forecasts are converted to reorder recommendations using configurable parameters: supplier lead time, desired service level, safety stock formula, and minimum order quantities — producing purchase orders rather than raw numbers.
API & Integration
FastAPI service exposing forecast retrieval, model retraining triggers, and recommendation queries. Designed for integration with ERP and inventory management systems via standard REST calls.
Key Engineering Challenges
Sparse Historical Data
Challenge: New or slow-moving products have few transactions, making statistical models unreliable.
Solution: Category-level aggregation to detect shared seasonal patterns, which are then applied to individual SKUs as a prior — enabling reasonable forecasts even with limited per-SKU history.
Interpretability Requirement
Challenge: Business users distrust black-box predictions; they need to understand why a reorder quantity was recommended.
Solution: Prediction explanations showing the trend, seasonal, and residual components separately, with plain-language summaries of the factors driving the recommendation.
Model Staleness
Challenge: Models trained on old data drift away from current demand patterns without retraining.
Solution: Scheduled weekly retraining pipeline per SKU, with a drift detector comparing recent actuals against forecast confidence intervals to trigger early retraining when performance degrades.
Safety Stock Calibration
Challenge: Overly conservative safety stock wastes capital; too little causes stockouts when demand spikes.
Solution: Service-level-driven safety stock formula using forecast error standard deviation, calibrated per product category and supplier reliability profile.
Solutions Implemented
- Tiered Model Selection: Automatic selection of the best-fit forecasting algorithm per SKU based on series length, variance, and detected seasonality.
- Category-Level Priors: Shared seasonal patterns across product families providing reliable seasonality estimates for data-sparse SKUs.
- Explainable Recommendations: Decomposed forecast components with plain-language justification for each reorder quantity generated.
- Drift Detection: Ongoing monitoring of forecast accuracy with automatic retraining triggers on performance degradation.
- ERP Integration Layer: REST API designed for plug-in integration with inventory management and purchasing modules.
Outcome & Impact
Compared to rule-based reordering
Less capital tied in excess stock
Keeping models current
Including sparse-history products