Skip to content
Back to Operations & SRE

Demand Forecasting

Forecast demand from historical trends, seasonality, and business events to pre-provision capacity.

Why

Auto-scaling is reactive — it scales after the traffic arrives, which means the first 2-5 minutes of a spike run on insufficient capacity (latency spikes, errors). For predictable spikes (Black Friday, product launch, marketing email send), forecasting lets you pre-provision: scale up 30 minutes before the spike, so the capacity is ready when the traffic hits. The forecast combines historical trends (traffic grows 5% MoM), seasonality (traffic doubles in Q4), and business events (marketing email at 10am will 3x traffic for 1h). This turns capacity from a reactive scramble ('the service is down, scale ASAP!') into a planned operation ('we expect 3x traffic at 10am, pre-scaled at 9:50'). Teams that forecast and pre-provision report 90% fewer capacity-related incidents during predicted events, because the capacity is already there.

When

For predictable events: seasonal peaks, product launches, marketing sends, and known traffic patterns.

How

1. Collect historical traffic data
   - Per-service request rate, by hour, for the last 12-24 months
   - Identify seasonality: daily (business hours), weekly (weekday vs weekend), yearly (Q4 peak)

2. Fit a forecast model
   - Simple: linear growth + seasonal decomposition (statsmodels, Prophet)
   - Advanced: ML model with features (marketing spend, day-of-week, holidays)
   - Don't over-fit; a simple model that's right 80% of the time beats a complex one that's wrong

3. Incorporate business events
   - Marketing: "email send at 10am → expect 3x traffic for 1h" → pre-scale at 9:50
   - Product: "launch on Tuesday → expect 10x traffic for 2 days" → pre-scale Monday
   - Sales: "Black Friday → expect 5x traffic" → pre-scale Wednesday

4. Pre-provision capacity ahead of the forecast spike
   - Scale up 30m before the spike (gives pods time to warm up, caches to fill)
   - Scale down 30m after the spike subsides (saves cost)
   - Use scheduled scaling (K8s HPA with schedule, or a cron job that adjusts replicas)

5. Track forecast accuracy and improve
   - "Forecast was 3x, actual was 2.5x" → over-provisioned 20%, fine
   - "Forecast was 3x, actual was 5x" → under-provisioned, incident; improve the model
   - Forecast accuracy is a metric; review quarterly

Example

# Forecast (Prophet, checkout service):
model = Prophet(yearly_seasonality=True, weekly_seasonality=True)
model.fit(history)  # 24 months of hourly checkout traffic
future = model.make_future_dataframe(periods=168, freq='H')  # next 7 days
forecast = model.predict(future)
# Forecast: Black Friday (Nov 24) → 5x normal traffic, 10am-8pm

# Pre-provision (K8s scheduled HPA):
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: checkout
spec:
  behavior:
    scaleUp:
      stabilizationWindowSeconds: 0  # scale up immediately
  metrics:
    - type: Resource
      resource:
        name: cpu
        target: { type: Utilization, averageUtilization: 70 }
---
# Scheduled scale-up before Black Friday:
apiVersion: v1
kind: CronJob
metadata:
  name: checkout-black-friday-pre-scale
spec:
  schedule: "0 9 24 11 *"  # 9am on Nov 24 (1h before spike)
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: kubectl
              command: ["kubectl", "scale", "deploy/checkout", "--replicas=50"]

# Forecast accuracy tracking:
#   Black Friday 2025: forecast 5x, actual 4.8x → 4% over, ✅
#   Product launch:    forecast 10x, actual 15x → 33% under, ⚠ improve model
#   Marketing email:   forecast 3x, actual 3.1x → 3% over, ✅

Common Problems

  • ⚠Relying only on auto-scaling — it's reactive, so the first 2-5m of a spike run on insufficient capacity; pre-provision for predictable events.
  • ⚠Forecast model is a black box — when it's wrong, nobody knows why; use a simple, interpretable model and track accuracy.
  • ⚠Pre-scaling too late — scaling at 10am for a 10am spike means the pods aren't ready; scale 30m before.
  • ⚠No forecast accuracy tracking — the model is wrong every time but nobody notices because there's no metric; track forecast vs actual.

Best Practices

  • ✓Forecast from historical trends + seasonality + business events; pre-provision 30m before predicted spikes so capacity is ready when traffic hits.
  • ✓Use a simple, interpretable model (linear + seasonal decomposition, Prophet); track forecast vs actual accuracy quarterly.
  • ✓Combine forecasting with reactive auto-scaling: forecast handles predictable spikes, auto-scaling handles the unpredictable remainder.
  • ✓Scale down 30m after the spike subside to save cost; pre-provisioning is for the spike, not permanent over-provisioning.