After studying this material, you should be able to:
When engineers deploy containers, they must specify resource limits:
numCpus: 8
memoryInMB: 18000
diskSizeInMB: 50000
networkInMbps: 1000
The natural human tendency is to guess high. Engineers either:
Think of it like setting a speed limit on every road in a country — manually, one by one:
| Problem | Real-World Impact |
|---|---|
| Too many functions to track | Hundreds of thousands of containers daily |
| Infrastructure keeps changing | EC2 upgrades alter actual resource needs |
| Engineers fear reducing limits | One failure = immediate over-provisioning |
| No feedback loop | Nobody knows what resources are actually used |
Key Insight: Over-provisioning is not just wasteful — it compounds over time as new workloads are added and old configs are never cleaned up.
SRT is an automated pipeline that:
CREATED → EVALUATING → APPLIED
↘ REJECTED
Think of this like a drug approval process:
Elasticsearch stores the high-level summary per execution:
{
"tags.functionName": "VideoEncoder.encodeV1",
"tags.cpuCount": 8,
"tags.memoryInMB": 18000,
"tags.stratum.success": true
}
Iceberg stores the detailed time-series data:
{
"cpu_requested": 8,
"resource_usage": [
{ "cpu_usage": 1.13, "memory_mb": 3701 },
{ "cpu_usage": 2.25, "memory_mb": 3584 },
{ "cpu_usage": 4.16, "memory_mb": 6750 }
]
}
| Store | Best For | Query Pattern |
|---|---|---|
| Elasticsearch | Fast lookups, filtering by status | "Show me all failed runs today" |
| Iceberg | Historical analysis, time-series | "What was peak memory over 30 days?" |
Key Insight: You cannot right-size what you cannot measure. Sub-minute resolution data is essential for catching peak usage spikes.
Every day, a scheduled job reads 30 days of historical data and applies this logic:
For each function + resource type:
1. Calculate p99 and p99.9 usage percentiles
2. Add a safety buffer
3. Compare to current allocation
4. If savings exist → create recommendation
Memory recommendation generated:
{
"current_value": 18000,
"recommended_value": 15300,
"stats": {
"usage": {
"avg": 5296,
"p99": 6750,
"p999": 7820
}
}
}
Reading this data:
Key Insight: Using percentiles (p99, p99.9) rather than averages protects against rare spikes while still enabling significant reductions.
Historical data cannot predict future unusual inputs. A video encoder might occasionally receive an unusually complex file that needs more memory than typical.
Each container runs a watcher process that monitors usage in real time:
If memory_usage > 85% of limit:
Cancel execution
Retry on container with: new_size = original_size × 1.5
If disk_usage > 95% of limit:
Cancel execution
Retry on container with: new_size = original_size × 1.5
Visualizing this for VideoEncoder.encodeV1:
Normal run: [=====> ] 15,300 MB limit — completes fine
Heavy input: [===============>] Hits 85% threshold
↓
Retry on: [=====> ] 22,950 MB container
Key Insight: This decouples "typical case optimization" from "edge case handling." You optimize for the 99.9% of runs while still safely handling outliers.
A single test is not enough because:
Both must pass before a recommendation is applied.
Run 3,000 executions:
- Baseline cluster: current config (18,000 MB)
- Experimental cluster: new config (15,300 MB)
Check:
✓ Slowness increase < threshold?
✓ Retry rate < threshold?
Split real traffic:
- Baseline: existing containers
- Experimental: right-sized containers
- Minimum 500 samples each
Check same two conditions.
"syntheticExperiment": {
"result": "SUCCESS",
"slownessIncreasePct": 0.0,
"retryRatePct": { "baseline": 0.0, "experimental": 0.0 }
},
"productionExperiment": {
"result": "SUCCESS",
"slownessIncreasePct": 1.0,
"retryRatePct": { "baseline": 0.0, "experimental": 0.0 }
}
1% slowness increase is acceptable. Zero retry rate increase confirms safety.
After applying a recommendation to VideoEncoder.encodeV2, an unexpected spike occurred. Because early versions had no automated rollback, engineers had to manually intervene — slow and risky.
Fast window (30 minutes):
Alert threshold: retry rate > 3%
Purpose: Catch sudden spikes quickly
Slow window (24 hours):
Alert threshold: retry rate > 2%
Purpose: Catch gradual degradation
Normal baseline: ~0.1% retry rate Acceptable variance: up to 2–3% Auto-revert trigger: exceeds thresholds above
If threshold breached:
Immediately restore previous configuration
(Do NOT attempt dynamic adjustment — keep it simple)
Key Insight: Simple, predictable rollback is safer than clever dynamic adjustment during an incident. Speed of recovery matters more than elegance.
What happened: A large single-step reduction was applied. An unexpected workload pattern caused retry rates to spike. Manual recovery was slow.
Three changes made as a result:
| Change | Before | After |
|---|---|---|
| Step size | Full reduction at once | Maximum 15% reduction per cycle |
| Recovery | Manual intervention | Automated rollback |
| Emergency stop | None | Global kill switch for all functions |
Old approach:
18,000 MB ──────────────────→ 15,300 MB (one jump)
New approach:
18,000 MB → 15,300 MB → 13,005 MB → 11,054 MB
(confirm) (confirm) (confirm)
1 week wait 1 week wait 1 week wait
Key Insight: Incremental changes with mandatory cooldown periods allow you to observe real production behavior before taking the next step.
CPU: 8 cores → 4 cores (50% reduction)
Memory: 18,000 MB → 15,300 MB (40% reduction — first step)
Performance impact: None measurable
Retry rate impact: None
┌─────────────────────────────────────────────────────┐
│ SRT Pipeline Overview │
├─────────────────────────────────────────────────────┤
│ MEASURE → Collect sub-minute usage data │
│ ANALYZE → Calculate p99/p99.9 + safety buffer │
│ RECOMMEND → Generate CREATED recommendation │
│ TEST → Synthetic → Production experiments │
│ APPLY → Update production configuration │
│ MONITOR → Watch retry rates for 90 days │
│ REVERT → Auto-rollback if thresholds breached │
└─────────────────────────────────────────────────────┘