01 · Why AWS Lambda: Idle Cost, Capacity Planning and Risky In-Place Deploys

🇨🇳 中文版 | 📦 GitHub: https://github.com/geekchow/aws-lambda-guide

Where you are: Stage 1 of 6 (Why).

After this file you will know: what hurt before Lambda, why VMs and containers did not fully cure it, and which constraints shaped Lambda's design --- including why versions, aliases and provisioned concurrency had to exist.


1. The world before: you rent a server, you own its problems

Imagine ShopFast in 2012. Its checkout service runs on four EC2 (Elastic Compute Cloud) virtual machines behind a load balancer.

Pain What it looks like concretely
Paying for idle Traffic at 03:00 is 2% of peak, but all four VMs (Virtual Machines) bill 24 × 7. Typical utilization: 10--20%.
Capacity guesswork Black Friday needs 20× capacity for 6 hours. Provision too little → checkout falls over; too much → money burned for weeks of lead time.
Slow elasticity An auto-scaling group boots a new VM in minutes. A traffic spike that peaks in 30 seconds is over before help arrives.
Undifferentiated toil Kernel patches, OS (Operating System) upgrades, log agents, disk-full pages at 02:00 --- none of it is checkout logic.
Risky deploys Deploying = SSH-ing (Secure Shell) or rolling new code in place over running servers. Rollback means re-deploying the old artifact and hoping it still builds.

#mermaid-svg-LXI4zIRB8euYFvCP{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-LXI4zIRB8euYFvCP .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-LXI4zIRB8euYFvCP .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-LXI4zIRB8euYFvCP .error-icon{fill:#552222;}#mermaid-svg-LXI4zIRB8euYFvCP .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-LXI4zIRB8euYFvCP .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-LXI4zIRB8euYFvCP .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-LXI4zIRB8euYFvCP .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-LXI4zIRB8euYFvCP .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-LXI4zIRB8euYFvCP .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-LXI4zIRB8euYFvCP .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-LXI4zIRB8euYFvCP .marker{fill:#333333;stroke:#333333;}#mermaid-svg-LXI4zIRB8euYFvCP .marker.cross{stroke:#333333;}#mermaid-svg-LXI4zIRB8euYFvCP svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-LXI4zIRB8euYFvCP p{margin:0;}#mermaid-svg-LXI4zIRB8euYFvCP .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-LXI4zIRB8euYFvCP .cluster-label text{fill:#333;}#mermaid-svg-LXI4zIRB8euYFvCP .cluster-label span{color:#333;}#mermaid-svg-LXI4zIRB8euYFvCP .cluster-label span p{background-color:transparent;}#mermaid-svg-LXI4zIRB8euYFvCP .label text,#mermaid-svg-LXI4zIRB8euYFvCP span{fill:#333;color:#333;}#mermaid-svg-LXI4zIRB8euYFvCP .node rect,#mermaid-svg-LXI4zIRB8euYFvCP .node circle,#mermaid-svg-LXI4zIRB8euYFvCP .node ellipse,#mermaid-svg-LXI4zIRB8euYFvCP .node polygon,#mermaid-svg-LXI4zIRB8euYFvCP .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-LXI4zIRB8euYFvCP .rough-node .label text,#mermaid-svg-LXI4zIRB8euYFvCP .node .label text,#mermaid-svg-LXI4zIRB8euYFvCP .image-shape .label,#mermaid-svg-LXI4zIRB8euYFvCP .icon-shape .label{text-anchor:middle;}#mermaid-svg-LXI4zIRB8euYFvCP .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-LXI4zIRB8euYFvCP .rough-node .label,#mermaid-svg-LXI4zIRB8euYFvCP .node .label,#mermaid-svg-LXI4zIRB8euYFvCP .image-shape .label,#mermaid-svg-LXI4zIRB8euYFvCP .icon-shape .label{text-align:center;}#mermaid-svg-LXI4zIRB8euYFvCP .node.clickable{cursor:pointer;}#mermaid-svg-LXI4zIRB8euYFvCP .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-LXI4zIRB8euYFvCP .arrowheadPath{fill:#333333;}#mermaid-svg-LXI4zIRB8euYFvCP .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-LXI4zIRB8euYFvCP .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-LXI4zIRB8euYFvCP .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-LXI4zIRB8euYFvCP .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-LXI4zIRB8euYFvCP .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-LXI4zIRB8euYFvCP .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-LXI4zIRB8euYFvCP .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-LXI4zIRB8euYFvCP .cluster text{fill:#333;}#mermaid-svg-LXI4zIRB8euYFvCP .cluster span{color:#333;}#mermaid-svg-LXI4zIRB8euYFvCP div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-LXI4zIRB8euYFvCP .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-LXI4zIRB8euYFvCP rect.text{fill:none;stroke-width:0;}#mermaid-svg-LXI4zIRB8euYFvCP .icon-shape,#mermaid-svg-LXI4zIRB8euYFvCP .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-LXI4zIRB8euYFvCP .icon-shape p,#mermaid-svg-LXI4zIRB8euYFvCP .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-LXI4zIRB8euYFvCP .icon-shape .label rect,#mermaid-svg-LXI4zIRB8euYFvCP .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-LXI4zIRB8euYFvCP .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-LXI4zIRB8euYFvCP .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-LXI4zIRB8euYFvCP :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} Lambda 2014
After: function-centric
Traffic curve
Environments created

per concurrent request
Pay per request

and per ms
Provider patches and scales;

you publish versions
Before: server-centric
Traffic curve
Fixed fleet sized

for the peak
80 percent idle

capacity, paid
You patch, scale,

deploy in place

Caption: the shift Lambda made --- from sizing a fleet to letting capacity follow concurrent requests.

2. Why the existing answers were not enough

Predecessor What it fixed What it left broken
Physical servers --- Everything above, plus weeks of procurement.
VMs (EC2) + Auto Scaling Minutes instead of weeks; pay by the hour/second Still pay for idle; still patch an OS; scale-out takes minutes; scaling unit is a whole VM.
Containers (ECS/Kubernetes) Faster start, denser packing, immutable images You still operate a cluster (nodes, control plane, autoscalers); scale-to-zero is not native; capacity planning moves to the node pool.
PaaS (Platform as a Service, e.g. Heroku/Elastic Beanstalk) No OS patching Still sized in long-running instances ("dynos"); idle instances still bill.

The common limitation: the unit of capacity is a long-running server , so somebody must decide how many to keep running before demand arrives.

3. The constraints that shaped Lambda

To make "run code only when an event happens" a reality, a design must satisfy several constraints at once --- and each constraint explains a piece of Lambda you will meet later:

Constraint Consequence in Lambda's design Where you meet it
Scale to zero, scale to thousands, per request Capacity unit = one execution environment serving one request at a time; concurrency is the scaling metric. 05.4
Strong multi-tenant isolation at high density Each environment is a Firecracker microVM (micro Virtual Machine) --- VM-grade isolation with container-like startup. 05.6
Creating environments on demand costs latency The cold start exists. Some workloads cannot tolerate it → provisioned concurrency (pre-warmed environments). 05.3
The provider runs your code, so code must be reproducible Deployments become immutable versions: an exact, frozen snapshot of code + configuration. 05.1
Callers must not change every time you deploy A stable name that can be re-pointed → aliases, which also enable canary traffic shifting and instant rollback. 05.2
A runaway function must not take down its neighbors Account-level and per-function concurrency limits, throttling with HTTP (Hypertext Transfer Protocol) 429. 05.4
Pay only for what runs Billing in GB-s (Gigabyte-seconds) at 1 ms granularity, plus per request. 02 What

4. The "someone would have to invent it" test

If Lambda did not exist and you had to build "run my code on every event, pay nothing when idle", you would be forced to invent:

  1. a router that receives an event and decides whether it is allowed to run (limits),
  2. a pool of isolated sandboxes that can be found warm or created cold,
  3. a way to freeze what code runs so the provider can create identical sandboxes at any time (versions),
  4. a stable name callers use while the code behind it changes (aliases), and
  5. a knob to pre-create sandboxes for latency-sensitive paths (provisioned concurrency).

That list is the concept map of 03 Concept map.

Conclusion

The pain was never "servers are hard" in the abstract; it was that capacity had to be decided before demand arrived and deploys mutated live servers. Lambda answers the first with per-request, concurrency-based scaling in microVMs, and the second with immutable versions behind movable aliases. Cold starts are the price of the first answer; provisioned concurrency is the escape hatch.


Next → 02 What · Back to 00 Overview


📚 Back to series index

相关推荐
Johny_Zhao1 天前
Keepalived与Nginx架构选型
linux·nginx·信息安全·云计算·apache·shell·yum源·keepalive·系统运维
66IT6610 天前
Veeam ONE v13.1 发布:全新 HTML5 Web 客户端与 PostgreSQL 报告库
云计算·虚拟化·监控·数据保护·veeam
2601_9679801111 天前
Python 与云计算:AWS、GCP、Azure 实践
python·云计算·azure·aws·gcp
cc57250265312 天前
云计算技术应用专业大学期间考证怎么安排?
云计算
xbzb13 天前
镜像推上云:华为云 SWR 与阿里云 ACR 的建组织、加速器、上传与公开
阿里云·华为云·云计算·镜像·acr·swr
牛奶咖啡1317 天前
云计算平台应用实践——云计算与云平台
云计算·云平台·云平台的三大服务模式·云计算与云平台的关系·laas paas saas·云平台的主流架构·国内外的主流云平台对比与选型
逐流人18 天前
手工建集群到全自动发布:k8s集群部署与DevOps流水线整合实战
ci/cd·云原生·kubernetes·云计算·devops
wz975418 天前
走进云计算:从硬件到云平台,读懂数字化底层基石
云计算
Kari1119 天前
企业大模型RAG知识库从0到1搭建指南:腾讯云ADP+JOTO实战
人工智能·云计算·腾讯云