AWS Builder Center
How We Built a Predictive AWS Lambda Pre-Warming System and 
Reduced Cold Starts by 40%

How We Built a Predictive AWS Lambda Pre-Warming System and Reduced Cold Starts by 40%

By combining machine learning with AWS serverless services, our team developed a predictive pre-warming system capable of anticipating traffic patterns and minimizing cold-start latency. This article shares the architecture, evaluation process, and key takeaways from the project.

A cold start costs a few hundred milliseconds. It sounds small until you're the one staring at a Lambda invocation that just added 800ms of latency to a real-time API, and you realize that "small" delay is exactly the kind of thing that makes a demo feel broken in front of a room full of people. That moment is where this project started for me.
I'm Piyush Trivedi, a Computer Engineering student at Pune Institute of Computer Technology (PICT) and the Group Leader for our AWS Student Builder Group. Over the past few months, I led the technical development of a project that came out of exactly that frustration, could we predict, ahead of time, which serverless functions were about to get hit and warm them up before the request even arrived, instead of reacting after the fact?
Working alongside my teammates Rudrani Shinde, Atharva Kalam, and Snehal Phatale, we built, tested, and documented a full adaptive cold-start prediction and pre-warming system for AWS Lambda. This article walks through how we built it, what broke along the way, and the numbers we ended up with at the end.

The Problem: Cold Starts Are Predictable, But We Treat Them Like They Aren't

 Serverless computing on AWS Lambda is great precisely because idle containers get deallocated , you don't pay for compute you're not using. The trade-off is the cold start, the next invocation after a period of inactivity has to provision a fresh container, load the runtime, and initialize your handler before it can do any actual work.
The default fixes are blunt instruments. Scheduled pings and provisioned concurrency keep functions warm around the clock, whether or not anyone is about to call them , which works, but burns budget fast across a large function fleet with uneven traffic. We wanted something proactive instead of reactive, forecast the next few minutes of invocation activity per function, and only pre-warm the functions that are actually about to be needed.

The "Unlock": Framing It As a Time-Series Forecasting Problem

The unlock for us came from realizing that invocation patterns aren't random — they carry real temporal structure ,diurnal cycles, weekly patterns, bursts tied to specific workloads. If call rates have structure, they're forecastable. That reframing is what turned "reduce cold starts" from a vague infra goal into a concrete machine learning problem we could actually attack, ingest historical invocation logs, model them as time series, predict the near future, and act on that prediction.
This is also where being part of the AWS Student Builder Group mattered directly the SBG gave us the structure, mentorship, and AWS service familiarity, the AWS service familiarity, and the peer accountability to take this from a whiteboard idea to a working, system instead of letting it stay a nice idea in a group chat.

Architecture Overview

We designed the system as a five-layer pipeline: Data Processing, Model Training, Decision Policy, AWS Execution, and Monitoring. Historical workload trace data flows in, gets transformed into structured time windows, is scored by a forecasting model, filtered through a decision policy, and finally triggers real warm-up calls against AWS infrastructure — with a feedback loop closing it all back to the monitoring layer
Architecture Diagram

Concretely ,we ingested workload trace data from the Google 2019 Cluster Sample dataset on Kaggle — a public release of Google's production cluster scheduler traces — aggregated it into five-minute invocation windows, and restricted analysis to the top 100 collections by invocation frequency — yielding 30,000 time-series windows in total. We treated each collection as a stand-in for a serverless function and its scheduled tasks as invocation events, which let us work with real, large-scale ,bursty workload behavior instead of synthetic traffic.
Since the raw trace doesn't include container lifecycle records the way a native Lambda log would, we simulated cold starts using an inactivity threshold rule, a window counts as a cold start if the gap since the last non-zero invocation exceeds 30 minutes, which lines up with AWS Lambda's empirically observed container keep-alive duration.
Dataset used: Google 2019 Cluster Sample (Kaggle) —  www.kaggle.com/datasets/derrickmwiti/google-2019-cluster-sample . It's a sampled release of Google's cluster workload traces, which is why our methodology adapts general cluster-scheduling task data to model serverless-style invocation patterns rather than pulling from an AWS-native log.

The AWS Services We Used — and Why

Service
Role in the System
AWS Lambda
Hosts the lightweight warm-up target functions that get invoked to keep containers active, and (conceptually) the functions being protected from cold starts.
AWS EventBridge
Runs a recurring 5-minute scheduler rule that triggers the prediction endpoint every cycle ,this is the heartbeat of the whole pre-warming loop.
Amazon CloudWatch
Backs a real-time dashboard tracking cold start rate, adaptive threshold evolution, prediction MAE, and over-provisioning rate.
IAM (role-based policies)
Enforces least-privilege access across every component in the pipeline.
Bonus tip from the brief we were given,link to specific places you've actually worked - here, that means our EventBridge scheduler rule and CloudWatch dashboard configuration, not just the service names.

Implementation Walkthrough

1. Feature Engineering — Giving the Model Something to Learn From

Each five-minute window is described by six engineered features, all MinMax-normalized using statistics derived only from the training partition (to avoid leaking future information into the model)
Feature
What It Captures
invocation_count
Raw invocation events in the window — workload intensity.
rolling_mean
Mean over the preceding 6 windows (30-min lookback) — short-term trend.
rolling_std
Std. dev. over the preceding 6 windows — burstiness vs. stability.
time_of_day
Normalized timestamp (time mod 86400) — diurnal pattern.
day_of_week
Ordinal 0–6 (Mon–Sun) — weekly periodicity.
scheduling_class / priority
Normalized task metadata — batch vs. interactive workloads.
We split the data with a strictly temporal partition and no shuffling — 70% training (21,000 windows), 15% validation (4,500 windows), 15% testing (4,500 windows) — to make sure the model was never evaluated on anything that overlapped with its training signal in time.

2. Two-Tier Forecasting: ARIMA Baseline + Stacked LSTM

We didn't want to jump straight to deep learning without a credible baseline. So the pipeline has two tiers:
  • ARIMA (statistical baseline) — trained per collection, with (p, d, q) up to order 2 selected via AIC using statsmodels.
  • Stacked LSTM (primary engine) — consumes a sliding window of the 10 most recent time steps plus the 6-dimensional feature vector to predict the next window's invocation count.
# LSTM architecture (identified via grid search over 405 configs)
LSTM Layer 1 : 256 units, return_sequences=True
Dropout : 0.2
LSTM Layer 2 : 128 units
Dense (output): linear activation
Optimizer : Adam, lr = 1e-4
Loss : Mean Squared Error (MSE)
Batch size : 512
Callbacks : EarlyStopping (patience 10)
ReduceLROnPlateau (factor 0.5, patience 5, min 1e-8)

Training converged around epoch 47 on an NVIDIA GTX 1650 Ti (DirectML), taking about an hour end-to-end. ARIMA fitting, by comparison, took roughly two minutes , a good reminder that the statistical baseline earns its keep as a fast sanity check even when it's not the model you ship.

3. The Peak Recall Decision Policy

A forecast alone doesn't decide anything, you need a policy that turns "predicted invocation count" into a binary pre-warm or don't-pre-warm decision. This was the part of the project I personally found the most interesting to design, because it's where you have to explicitly choose what kind of mistake you're willing to make. We built a three-stage policy we called Peak Recall, designed to prioritize catching real load spikes over minimizing wasted warm-ups:
  • Stage 1 — Percentile threshold (p67): flag windows in the top 33% of the forecast distribution as high-load candidates.
  • Stage 2 — Absolute threshold (92): only windows whose predicted load also clears an absolute value of 92 proceed, filtering out noise from Stage 1.
  • Stage 3 — Temporal smearing: flagged windows are expanded to neighbouring windows (EMA alpha = 1.0 for zero-lag response, lead buffer of 2) to absorb timing uncertainty around burst edges.
PreWarm[j,t] = 1 if Ĉ[j,t+1] > λ_t AND Ĉ[j,t+1] > θ_abs
= 0 otherwise
# adaptive threshold updates every cycle via feedback:
λ[t+1] = λ_t + α • (OverProvRate_t − TargetRate) # TargetRate = 0.20

No threshold is hardcoded — λ adapts every cycle based on observed over-provisioning, which means the policy keeps recalibrating itself as traffic patterns shift instead of drifting out of date.

4. Wiring It Into Real AWS Infrastructure

This is the part that made the project feel real rather than academic. AWS EventBridge runs a rule firing every five minutes. In our prototype deployment, each trigger hits a FastAPI prediction endpoint, which runs LSTM inference, applies the Peak Recall policy, and dispatches warm-up calls to any collection that qualifies. A dedicated lightweight Lambda function is the actual warm-up target , it does just enough work to keep its container alive. Every component runs under least-privilege IAM roles, and the whole setup operates comfortably within AWS Free Tier limits, which mattered a lot to us as students self-funding the experimentation.

What Broke - and How We Fixed It

Nothing about this worked on the first try, and I think that's the more useful part of the story than the final numbers.
  • Data leakage from the future: our first pass at feature scaling used statistics from the full dataset. Test performance looked suspiciously good. We fixed it by deriving all MinMax scaling exclusively from the training partition and enforcing a strictly temporal split with shuffling disabled.
  • Overfitting past ~epoch 30: validation loss started drifting away from training loss (0.28 train vs 0.35 val at epoch 30). EarlyStopping with patience 10 and ReduceLROnPlateau brought training to a clean stop at epoch 47 (train loss 0.120, val loss 0.180) instead of letting the model memorize noise.
  • An overly conservative policy missed real spikes: our first single-threshold version either pre-warmed almost nothing or almost everything depending on where we set the cut-off. Splitting the decision into percentile + absolute + smearing stages let us tune for recall specifically ,catching more real high-load events, while accepting a known, measurable amount of over-provisioning rather than an unpredictable one.
Fig. 2 - Predicted vs. actual invocation count over the test window (LSTM prediction overlay)


Cost & Performance Considerations

Being explicit about the cost trade-off matters, because "we reduced cold starts" is meaningless without saying what it cost to get there. Our Peak Recall configuration runs at roughly 31.17× the compute cost of the un-warmed baseline - high, but still about 10% cheaper than a naive always-warm strategy across the same fleet, which sits at roughly 3.04× baseline cost per function multiplied out across our over-provisioning rate. Inference itself is cheap ,ARIMA scores a window in about 50ms and the LSTM in about 100ms, both well within a 5-minute scheduling cycle.
Metric
Value
Cold start rate — baseline (no warm-up)
35.54%
Cold start rate — adaptive pre-warming
21.18%
Relative cold start reduction
40.43%
Over-provisioning rate
94.55%
Relative provisioning cost vs. baseline
31.17×
LSTM inference time per cycle
~100 ms
Being upfront: this over-provisioning rate is high by production standards. Peak Recall was deliberately tuned to prioritize catching load spikes over minimizing wasted warm-ups — a choice that's right for experimentation and evaluation but that we'd tune differently for a cost-sensitive production deployment. More on that in the lessons below.

Results

 On the held-out test partition, the Stacked LSTM clearly outperformed the ARIMA baseline:
Model
MAE
RMSE
Inference Time
ARIMA (baseline)
0.0874
0.5704
~50 ms
Stacked LSTM (proposed)
0.0010
0.0099
~100 ms
Improvement
98.8% ↓
98.2% ↓
—
Translated into system-level impact, the adaptive pre-warming pipeline reduced the simulated cold start rate from 35.54% to 21.18% - a 40.43% relative reduction compared to running with no warm-up strategy at all.
Fig. 3 - Cold start rate comparison bar chart (35.54% baseline vs. 21.18% adaptive)


Lessons Learned

A few things I'd tell a peer starting a similar project:
Build the boring baseline first. ARIMA cost us about two minutes of compute and gave us an honest yardstick to know whether the LSTM was actually earning its complexity - it was, by a wide margin, but we wouldn't have known that with confidence otherwise.
  • A prediction is not a decision. The gap between "the model forecasts high load" and "we should spend money warming a container" is exactly where a project like this lives or dies. That's the piece worth spending the most design time on.
  • Recall vs. precision is a business decision, not just a modeling one. Our 94.55% over-provisioning rate isn't a bug , it's a documented consequence of optimizing for catching load spikes. Next iteration, we're tuning Peak Recall to bring that below 50% without giving back the 40% cold-start reduction.
  • Simulated isn't the same as measured. Our cold starts are simulated from an inactivity rule, not pulled from a live production environment. That's an honest limitation, and it's the first thing on our roadmap to close.

How AWS Builder Center Empowers What Comes Next

This project moved from idea to a documented, benchmarked system because of the structure the AWS Student Builder Group and gave us a defined research track, AWS service access, and a community of peers who were building things in parallel and comparing notes. Writing this up here, rather than leaving it in a private repo, is part of how I want to keep contributing, making the messy middle of a technical project (the leakage bug, the overfitting, the threshold tuning) visible to the next student who's about to hit the same walls.
What I'm working toward next is extending this into an online or continual learning setup so the model adapts to workload shifts without waiting for the next offline retrain, and tuning Peak Recall toward a leaner over-provisioning rate. If you're a fellow SBG member interested in serverless performance, time-series forecasting, or just want to compare notes on your own AWS Builder Center project, I'd genuinely like to hear from you in the comments.

Resources

This article, which includes the complete architecture diagrams, algorithm listing, and dataset statistics referenced above.
  • Dataset: Google 2019 Cluster Sample, Kaggle — kaggle.com/datasets/derrickmwiti/google-2019-cluster-sample
  • Background: Reiss, Tumanov, Ganger, Katz & Kozuch, "Heterogeneity and Dynamicity of Clouds at Scale: Google Trace Analysis," ACM SoCC 2012 — the original methodology this trace family is built on.
Find me on  LinkedIn  |  GitHub .
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article