Phase 3: Reliability Engineering

Demand forecasting with historical trends & growth models

Advanced ~3 min read
Think of it this way A friendly analogy. Read this if the technical version feels dense. Show Hide

Imagine you're getting ready for a new school year. You don't want to run out of pencils in the middle of a big test, or suddenly discover you have no glue for your science project. But you also don't want to buy a huge pile of notebooks you'll never use! That's why you try to guess what you'll need for the whole year. This clever guessing, for computers, is called "demand forecasting." It's super important for making sure websites and apps work smoothly and don't suddenly slow down or break because they weren't ready for a lot of people using them.

So, how do you make a good guess for your school supplies? You think about what happened last year. How many pens did you go through? Did you use up a pack of colored paper every month, or only for special projects? Computers do the same thing: they look at all their "past supplies" data, like how many people used a website at certain times, or how much digital "memory" they needed. They find patterns: maybe every day around lunchtime, lots of people use the app (a regular cycle), or maybe your art teacher has been assigning more drawing projects, so you're slowly using more sketchpads over time (a gradual trend). They even notice "seasonal" patterns, like how everyone needs new backpacks and pencils right before school starts, or lots of glitter and glue around holiday time.

But what if things are changing? What if you're starting a new after-school club that uses a ton of special craft supplies, or you're suddenly writing a lot more in a journal? That's where "growth models" come in. These are like different ways of predicting how your supply needs will grow. If you use up pens at a steady, predictable pace, that's like "linear growth." If you suddenly get super interested in a new hobby that uses up supplies really fast, like a sudden rush for beads because all your friends want to make friendship bracelets, that’s "exponential growth." And sometimes, no matter how much you want, you can only bring a certain number of crayons to class, so your crayon supply "growth" eventually stops because of a limit, which is "logistic growth."

By doing this kind of clever guessing – looking at the past and thinking about how things might grow – the people who manage big computer systems can make sure they always have enough "digital supplies." This means you can keep playing your favorite online game, send messages to your friends, or watch videos without the computer system running out of resources or crashing. They can be ready for anything, whether it's a regular daily rush or a big, sudden surge of new users!

For an SRE, demand forecasting isn't just a theoretical exercise; it's a critical tool for preventing outages, optimizing resource allocation, and ensuring cost efficiency. At its core, it involves analyzing historical telemetry data—metrics like QPS, concurrent users, CPU utilization, memory consumption, network I/O, and database connections—to identify patterns and predict future system load. This historical analysis allows us to discern regular cycles (e.g., daily peak hours, weekly traffic dips, monthly report generation spikes), identify underlying trends (e.g., gradual user base expansion), and detect seasonality (e.g., holiday rushes, back-to-school periods). Understanding these past behaviors is the foundation for anticipating future demands on your infrastructure.

While historical trends reveal what has happened, growth models help us predict what will happen given an underlying growth trajectory. Common models include linear regression for systems with stable, incremental growth; exponential growth for rapidly expanding services or viral adoption; and logistic growth for scenarios where growth eventually plateaus due to market saturation, resource constraints, or user limits. The choice of model is crucial and often informed by business context—a new feature launch might warrant an exponential model, while an established service might be better served by a linear or even logistic fit. SREs integrate these models with business-driven forecasts, such as projected user acquisition, marketing campaign impacts, or anticipated feature usage, to create a holistic demand picture.

The practical application for SREs is manifold: the forecasts directly inform capacity planning decisions, from setting dynamic auto-scaling group thresholds and planning future bare-metal server purchases to defining database replica counts and network bandwidth upgrades. By proactively modeling demand, SREs can secure lead times for hardware procurement, manage cloud spending by right-sizing instances, and ensure critical services remain performant under anticipated peak loads. It’s an iterative process, constantly refining models with new data and adjusting for unforeseen events, ensuring that your infrastructure is always a step ahead of user demand without over-provisioning unnecessarily.

Key Takeaways

  • Historical telemetry data reveals critical usage patterns, cycles, and seasonality.
  • Growth models (linear, exponential, logistic) predict future demand based on underlying trajectories.
  • Combine data-driven analysis with business intelligence for accurate forecasts.
  • Demand forecasting is an iterative process; continuously refine models with new data.
  • Proactive capacity planning via forecasting prevents outages and optimizes resource costs.

Code Example

python
import numpy as np
from scipy.stats import linregress

# Sample historical data: (day_number, QPS_value)
historical_data = np.array([
    (1, 1000), (2, 1050), (3, 1100), (4, 1150),
    (5, 1200), (6, 1250), (7, 1300), (8, 1350)
])

days = historical_data[:, 0]
qps = historical_data[:, 1]

# Perform linear regression to find a growth trend
slope, intercept, r_value, p_value, std_err = linregress(days, qps)

# Predict QPS for future days (e.g., day 10, 11, 12)
future_days = np.array([10, 11, 12])
predicted_qps = slope * future_days + intercept

print(f"Predicted QPS for future days {future_days}: {predicted_qps.round(0)}")

How this code works

This code demonstrates a basic method for demand forecasting by identifying a historical growth trend. It uses the numpy library to handle numerical data efficiently and scipy.stats.linregress to perform a linear regression. The overall job is to take past performance data (like QPS values over several days) and extrapolate a simple, consistent growth pattern to predict future demand.

The process starts with historical_data, an array storing pairs of day numbers and their corresponding QPS values. From this, separate days and qps arrays are extracted to prepare for analysis. linregress then calculates the slope and intercept of the straight line that best fits this historical data. This slope represents the average daily increase in QPS, while the intercept is the estimated starting QPS if the trend were extended back to day zero. Finally, these derived slope and intercept values are used with future_days to calculate predicted_qps. A subtle point is that linregress inherently assumes a linear growth pattern; it will always try to fit a straight line, which might not accurately capture demand if the true growth accelerates or decelerates.