How we built a flexible pipeline for forecasting time series of any metrics

Alexander Elizarov24 Jul 2025

Problem

An analytics team at Yandex had to forecast many business metrics, from search queries and search share to the DAU of individual services. Each forecast started as a copy of an old Jupyter notebook that was refactored or rewritten, which became slow as tasks and data refreshes multiplied. Customers also wanted every metric cut by device, OS and browser, and forecasts made separately for each cut did not add up to the same total. Share metrics were hard to forecast and explain, and anomalous periods such as COVID distorted the models.

Example from the article: forecasting search queries by OS (iOS, Android, Linux, Windows, macOS) and separately by device (phones, tablets, desktop) gives two different forecasts of total queries.

Solution in brief

Represent all breakdowns as a tree, forecast only the leaf series, and build every aggregate and share from those forecasts. Clean the series automatically with etna and ruptures, forecast with Prophet plus postprocessing, and tune parameters with Optuna. Keep metric-specific logic in one class and one YAML config per metric, so the pipeline itself stays generic.

Questions this case answers
  • How to forecast hundreds of related metric series across several overlapping breakdowns so that aggregates stay additive and consistent
  • How to forecast a ratio metric reliably when the ratio series itself is hard to model and to explain
  • How to automate cleaning of outliers and trend shifts in business time series while keeping manual overrides for rare events
  • How to forecast many metric series cut by device, OS and browser so that the totals always match the sum of the parts?

Tools and methods

  • Breakdown tree (NetworkX) — keeps totals consistent by forecasting only leaves
  • etna, ruptures — automatic outlier and trend-shift detection
  • Prophet — interpretable forecast of trend, seasonality and holidays
  • Optuna with time-series cross-validation — hyperparameter search on MAPE
  • YAML config + model class — per-metric settings without touching the pipeline
Continue reading — it's free

Google or a one-time email code. No password.