Autoscaling, every kindAutoscaling, đủ mọi loại
"Add autoscaling" means a different machine in every service. Before reaching for a policy, answer three things: what unit gets added (an instance, a task, a replica, a capacity unit, nothing you can see), which engine adds it (EC2 Auto Scaling, Application Auto Scaling, or the service itself), and what tells it to (an alarm, a target, a clock, a forecast, or the requests themselves).
"Thêm autoscaling" là một cỗ máy khác nhau ở mỗi service. Trước khi chọn policy, trả lời ba điều: đơn vị nào được thêm (instance, task, replica, capacity unit, hay thứ bạn không nhìn thấy), bộ máy nào thêm nó (EC2 Auto Scaling, Application Auto Scaling, hay chính service), và cái gì ra lệnh (alarm, mục tiêu, đồng hồ, dự báo, hay chính lượng request).
At a glanceNhìn một hình
One request path, every layer annotated with how it scales. The orange notes are where scaling lags or stops — the places exam questions aim at.
Một đường đi của request, mỗi tầng ghi rõ nó scale thế nào. Các ghi chú màu cam là chỗ scaling bị chậm hoặc dừng — đúng những chỗ đề thi nhắm vào.
You configure the scalingBạn tự cấu hình scaling
- EC2 fleets — ASG with min / desired / max and a policy.Fleet EC2 — ASG với min / desired / max và một policy.
- ECS services, EKS pods and nodes.ECS service, pod và node EKS.
- DynamoDB provisioned, Aurora replicas, ElastiCache shards, SageMaker endpoints.DynamoDB provisioned, Aurora replica, shard ElastiCache, SageMaker endpoint.
- Lambda provisioned concurrency (on a schedule or utilization).Lambda provisioned concurrency (theo lịch hoặc mức sử dụng).
It scales by itselfTự nó scale
- Lambda, S3, SQS, SNS, Fargate per task, API Gateway.Lambda, S3, SQS, SNS, Fargate theo task, API Gateway.
- DynamoDB on-demand, Kinesis on-demand.DynamoDB on-demand, Kinesis on-demand.
- Aurora Serverless v2, Redshift Serverless, OpenSearch / ElastiCache Serverless — you only set min / max.Aurora Serverless v2, Redshift Serverless, OpenSearch / ElastiCache Serverless — bạn chỉ đặt min / max.
- RDS storage autoscaling — one checkbox and a ceiling.RDS storage autoscaling — một checkbox và một mức trần.
1 · Three products called "Auto Scaling"1 · Ba sản phẩm cùng tên "Auto Scaling"
There are really two engines. EC2 Auto Scaling owns instances and everything around their life (health checks, hooks, warm pools). Application Auto Scaling owns nothing — it just turns a dial that another service exposes. AWS Auto Scaling is a front-end over both. Thật ra chỉ có hai bộ máy. EC2 Auto Scaling sở hữu instance và mọi thứ quanh vòng đời của nó (health check, hook, warm pool). Application Auto Scaling không sở hữu gì — nó chỉ vặn một núm mà service khác đưa ra. AWS Auto Scaling là một giao diện phía trên cả hai.
If the thing being added is an EC2 instance you manage, it's the left box. If it's anything else with a "count" — tasks, read capacity, replicas, provisioned concurrency — it's the right box, configured from that service's own console.
Nếu thứ được thêm là EC2 instance do bạn quản lý, đó là hộp trái. Nếu là thứ gì khác có "số lượng" — task, read capacity, replica, provisioned concurrency — đó là hộp phải, cấu hình từ chính console của service đó.
2 · What gets added — from boxes to nothing visible2 · Cái gì được thêm — từ cái máy tới thứ không nhìn thấy
The further right, the finer the unit and the less you configure. On the left you pick instance types and write policies; on the right you set a ceiling and AWS does the rest. Exam questions saying "least operational overhead" are pushing you rightwards. Càng sang phải, đơn vị càng nhỏ và bạn càng ít phải cấu hình. Bên trái bạn chọn instance type và viết policy; bên phải bạn đặt một mức trần và AWS lo phần còn lại. Câu hỏi có cụm "least operational overhead" đang đẩy bạn sang phải.
Speed follows size: a new instance is minutes, a task seconds, an ACU step near-instant, a Lambda environment sub-second. That's why reactive scaling on the left needs help (warm pools, forecasts) and on the right mostly doesn't.
Tốc độ đi theo kích thước: instance mới mất vài phút, task vài giây, một bước ACU gần như tức thì, môi trường Lambda dưới một giây. Vì vậy scale phản ứng ở bên trái cần trợ giúp (warm pool, dự báo) còn bên phải phần lớn thì không.
3 · The five policy types3 · Năm kiểu policy
All five answer "when do we add capacity?" — differently. Same demand curve below (grey), four different capacity responses (blue). Look at where blue sits under grey: that gap is users waiting. Cả năm đều trả lời "khi nào thêm capacity?" — theo cách khác nhau. Cùng một đường nhu cầu bên dưới (xám), bốn cách đáp ứng capacity khác nhau (xanh). Nhìn chỗ đường xanh nằm dưới đường xám: khoảng hở đó là người dùng phải chờ.
Not shown: you can stack them. The common production combo is predictive (or scheduled) for the baseline + target tracking for the surprises. When several policies fire at once, the ASG takes the one that gives the most capacity.
Không vẽ ra: có thể chồng chúng lên nhau. Combo phổ biến trong production là predictive (hoặc scheduled) cho nền + target tracking cho bất ngờ. Khi nhiều policy cùng kích hoạt, ASG chọn cái cho nhiều capacity nhất.
| Policy | TriggerKích hoạt | You defineBạn định nghĩa | Best forHợp với | WhereCó ở |
|---|---|---|---|---|
| Simple | One CloudWatch alarmMột CloudWatch alarm | Add / remove N, then wait the cooldownThêm / bớt N, rồi chờ cooldown | Legacy — avoidĐời cũ — tránh | ASG |
| Step | CloudWatch alarm, by breach sizeCloudWatch alarm, theo độ vượt | Bands: +1 at 60 %, +3 at 80 %…Các bậc: +1 ở 60 %, +3 ở 80 %… | Custom metrics, uneven responseMetric tuỳ biến, đáp ứng không đều | ASG · App AS |
| Target tracking | Alarms it creates and ownsAlarm do nó tự tạo và quản lý | One metric + target valueMột metric + giá trị mục tiêu | The default answerĐáp án mặc định | ASG · App AS |
| Scheduled | Date / cronNgày / cron | New min / desired / max at a timemin / desired / max mới vào một thời điểm | Known events, business hoursSự kiện biết trước, giờ hành chính | ASG · App AS |
| Predictive | Forecast from ≥ 24 h of historyDự báo từ ≥ 24 h lịch sử | Metric + "forecast only" or "forecast and scale"Metric + "chỉ dự báo" hoặc "dự báo và scale" | Recurring daily / weekly cycles, slow bootChu kỳ ngày / tuần lặp lại, khởi động chậm | ASG · ECS |
- Good target-tracking metrics rise and fall with the number of instances: average CPU,
ALBRequestCountPerTarget, network in/out. A queue's raw depth is not — divide it by instance count to get backlog per instance, publish that as a custom metric, track it.Metric tốt cho target tracking tăng giảm theo số instance: CPU trung bình,ALBRequestCountPerTarget, network in/out. Độ dài queue thô không phải — chia cho số instance để ra backlog per instance, publish làm custom metric, rồi track nó. - Cooldown (simple scaling) = wait after any action. Instance warmup (step, target tracking) = don't count a new instance's metrics until it's ready. Both exist to stop flapping; warmup is the modern one.Cooldown (simple scaling) = chờ sau mỗi hành động. Instance warmup (step, target tracking) = chưa tính metric của instance mới cho tới khi nó sẵn sàng. Cả hai đều để chống dao động; warmup là cái hiện đại.
4 · Inside an ASG — the instance's life4 · Bên trong ASG — vòng đời một instance
Most ASG exam questions are about the edges of an instance's life: how it gets in faster, how it proves it's healthy, how it leaves cleanly, and which one gets picked to leave. Phần lớn câu hỏi ASG xoay quanh hai đầu vòng đời instance: vào nhanh hơn thế nào, chứng minh còn khoẻ ra sao, rời đi sạch sẽ thế nào, và cái nào bị chọn để rời đi.
The two dashed boxes are the only places you can run your own code inside the ASG's flow. Everything else — when to launch, who to kill — is policy.
Hai hộp nét đứt là chỗ duy nhất bạn chạy được code của mình bên trong luồng của ASG. Mọi thứ khác — khi nào launch, giết ai — đều là policy.
- "Instances fail behind the ALB but the ASG never replaces them" → the ASG is using the default EC2 health check. Switch the health check type to include ELB."Instance lỗi sau ALB nhưng ASG không thay" → ASG đang dùng health check EC2 mặc định. Đổi health check type sang có ELB.
- Instance refresh rolls a new launch template across the group with a minimum healthy percentage — the in-place way to roll out a new AMI.Instance refresh cuốn launch template mới qua cả group với tỉ lệ healthy tối thiểu — cách tại chỗ để roll out AMI mới.
- Mixed instances policy = On-Demand base + Spot above it across several instance types. Capacity rebalancing launches a replacement when a Spot instance gets a rebalance recommendation, before the 2-minute notice.Mixed instances policy = nền On-Demand + Spot phía trên, trải nhiều instance type. Capacity rebalancing launch instance thay thế khi Spot nhận rebalance recommendation, trước cả cảnh báo 2 phút.
5 · Containers — two layers to scale5 · Container — hai tầng phải scale
Adding tasks or pods is useless if there's no machine to put them on. So container platforms scale twice: the workload layer reacts to load, the capacity layer reacts to pending work that doesn't fit. Fargate (and EKS Auto Mode) hand the second layer to AWS. Thêm task hay pod là vô ích nếu không có máy để đặt chúng. Vì vậy nền tảng container scale hai lần: tầng workload phản ứng theo tải, tầng capacity phản ứng theo việc đang chờ không vừa chỗ. Fargate (và EKS Auto Mode) giao tầng thứ hai cho AWS.
The trigger for the bottom layer is never CPU — it's work that can't be placed (tasks stuck in PROVISIONING, pods stuck Pending). Scaling the machines on CPU alone is the classic wrong answer.
Thứ kích hoạt tầng dưới không bao giờ là CPU — mà là việc không đặt được chỗ (task kẹt ở PROVISIONING, pod kẹt Pending). Scale máy chỉ theo CPU là đáp án sai kinh điển.
6 · Databases and data — same idea, different knobs6 · Database và dữ liệu — cùng ý tưởng, khác núm vặn
Data services usually offer a provisioned + autoscaling mode and an on-demand / serverless mode. Provisioned is cheaper at steady load but reacts in minutes; on-demand reacts instantly but costs more per unit. The spike shape decides. Service dữ liệu thường có chế độ provisioned + autoscaling và chế độ on-demand / serverless. Provisioned rẻ hơn khi tải đều nhưng phản ứng mất vài phút; on-demand phản ứng ngay nhưng đắt hơn mỗi đơn vị. Hình dạng spike quyết định.
Grey = requests, blue = what the table can absorb, red = throttled requests. Auto scaling can't beat a spike shorter than the time its alarms need. "Unpredictable, spiky, new workload" → on-demand. "Steady and known, cost matters" → provisioned + auto scaling (plus reserved capacity).
Xám = request, xanh = mức bảng chịu được, đỏ = request bị throttle. Auto scaling không đánh bại được spike ngắn hơn thời gian alarm của nó cần. "Khó đoán, nhiều spike, workload mới" → on-demand. "Đều và biết trước, quan tâm chi phí" → provisioned + auto scaling (thêm reserved capacity).
| Service | Provisioned + autoscalingProvisioned + autoscaling | Hands-off modeChế độ tự lo | Watch outChú ý |
|---|---|---|---|
| DynamoDB | App Auto Scaling on RCU / WCU (target utilization)App Auto Scaling trên RCU / WCU (mức sử dụng mục tiêu) | On-demandOn-demand | On-demand can still throttle if you jump far past 2× the previous peak at once.On-demand vẫn có thể throttle nếu nhảy vọt quá xa 2× đỉnh trước đó trong một lúc. |
| Aurora | Replica auto scaling — adds readers (≤ 15) on avg CPU or connectionsReplica auto scaling — thêm reader (≤ 15) theo CPU trung bình hoặc số kết nối | Serverless v2 — the instance itself grows / shrinks in ACUs; min 0 = auto-pauseServerless v2 — chính instance phình / co theo ACU; min 0 = tự dừng | Replica scaling helps reads only; the writer scales up (Sv2) or by a bigger instance, never out.Replica scaling chỉ giúp đọc; writer scale lên (Sv2) hoặc đổi instance lớn hơn, không bao giờ scale ra. |
| RDS | No compute autoscaling — resize the instance yourselfKhông có autoscaling compute — tự đổi size instance | Storage autoscaling up to a max you setStorage autoscaling tới mức trần bạn đặt | Fires at < 10 % free for 5 min; then waits 6 h before growing again.Kích hoạt khi còn < 10 % trống trong 5 phút; sau đó chờ 6 h mới tăng tiếp. |
| ElastiCache | App Auto Scaling on shards and replicas (cluster mode enabled)App Auto Scaling trên shard và replica (cluster mode enabled) | ElastiCache ServerlessElastiCache Serverless | Shards = more memory / write throughput; replicas = more reads.Shard = thêm bộ nhớ / throughput ghi; replica = thêm đọc. |
| Kinesis Data Streams | None built in — UpdateShardCount from your own LambdaKhông có sẵn — tự gọi UpdateShardCount từ Lambda |
On-demand capacity modeChế độ capacity on-demand | On-demand absorbs up to 2× the peak of the last 30 days.On-demand đỡ tới 2× đỉnh của 30 ngày gần nhất. |
| Redshift | Concurrency scaling adds transient clusters for query burstsConcurrency scaling thêm cluster tạm cho đợt query dồn dập | Redshift Serverless (RPUs)Redshift Serverless (RPU) | Concurrency scaling = more queries at once, not a faster single query.Concurrency scaling = nhiều query cùng lúc hơn, không phải một query nhanh hơn. |
| EMR | Custom policies on instance groups (App AS)Policy tự viết trên instance group (App AS) | Managed scaling — EMR reads YARN metrics, you set min / maxManaged scaling — EMR đọc metric YARN, bạn đặt min / max | Scale task nodes (no HDFS) on Spot; keep core nodes steady.Scale task node (không có HDFS) bằng Spot; giữ core node ổn định. |
7 · Lambda — scaling you don't configure, limits you do7 · Lambda — scaling không cần cấu hình, giới hạn thì có
Lambda scales one execution environment per concurrent request, on its own. What you control is how the account's concurrency pool is shared: reserve a slice for a function, pre-warm a slice so it has no cold starts, leave the rest common. Lambda tự scale, mỗi request đồng thời một môi trường thực thi. Thứ bạn kiểm soát là cách chia pool concurrency của account: giữ riêng một phần cho một function, làm ấm sẵn một phần để không cold start, phần còn lại dùng chung.
"One function eats all concurrency and starves the rest" → reserved concurrency on it (as a cap). "Latency-sensitive API, cold starts unacceptable at 9 a.m." → provisioned concurrency, scheduled with Application Auto Scaling.
"Một function ăn hết concurrency làm các function khác chết đói" → đặt reserved concurrency cho nó (làm mức trần). "API nhạy độ trễ, không chấp nhận cold start lúc 9 giờ sáng" → provisioned concurrency, lên lịch bằng Application Auto Scaling.
Exam reflexesPhản xạ khi thi
- "Scale EC2 workers on SQS queue depth" → custom metric backlog per instance + target tracking. Not raw
ApproximateNumberOfMessagesVisiblewith a simple policy."Scale EC2 worker theo độ dài SQS queue" → custom metric backlog per instance + target tracking. Không phảiApproximateNumberOfMessagesVisiblethô với simple policy. - "Traffic peaks every weekday at 9 a.m." → predictive (or scheduled) scaling. "Black Friday on a known date" → scheduled."Traffic đạt đỉnh mỗi sáng ngày thường lúc 9 giờ" → predictive (hoặc scheduled) scaling. "Black Friday vào ngày biết trước" → scheduled.
- "Instances take 10 minutes to boot, scale-out too slow" → warm pool, or bake a golden AMI, or scale ahead with predictive."Instance mất 10 phút để khởi động, scale-out quá chậm" → warm pool, hoặc dựng golden AMI, hoặc scale trước bằng predictive.
- "Must finish in-flight work / upload logs before an instance is terminated" → terminate lifecycle hook. "Never terminate this instance on scale-in" → scale-in protection."Phải xong việc đang làm / upload log trước khi instance bị terminate" → lifecycle hook lúc terminate. "Đừng bao giờ terminate instance này khi scale-in" → scale-in protection.
- "Unhealthy behind the load balancer but not replaced" → ASG health check type ELB."Unhealthy sau load balancer nhưng không bị thay" → health check type của ASG là ELB.
- "DynamoDB throttles during sudden spikes even with auto scaling" → on-demand mode (or DAX for read-heavy hot keys)."DynamoDB bị throttle khi spike đột ngột dù đã bật auto scaling" → chế độ on-demand (hoặc DAX cho key nóng đọc nhiều).
- "Aurora read load varies through the day" → Aurora replica auto scaling. "Dev / test DB idle most of the time" → Aurora Serverless v2 with min 0 ACU."Tải đọc của Aurora thay đổi trong ngày" → Aurora replica auto scaling. "DB dev / test hầu như rảnh" → Aurora Serverless v2 với min 0 ACU.
- "ECS tasks stuck in PROVISIONING" → capacity provider managed scaling (or move to Fargate). "EKS pods Pending" → Cluster Autoscaler / Karpenter."ECS task kẹt ở PROVISIONING" → capacity provider managed scaling (hoặc chuyển sang Fargate). "Pod EKS kẹt Pending" → Cluster Autoscaler / Karpenter.
- "Kinesis shards are hard to size, traffic unpredictable" → on-demand capacity mode. "RDS keeps running out of disk" → storage autoscaling."Khó tính số shard Kinesis, traffic khó đoán" → chế độ on-demand. "RDS liên tục hết đĩa" → storage autoscaling.
- "Capacity flaps up and down" → instance warmup / cooldown, and target tracking's slow scale-in. "Several policies fire" → the ASG picks the largest capacity."Capacity dao động lên xuống" → instance warmup / cooldown, và scale-in chậm của target tracking. "Nhiều policy cùng kích hoạt" → ASG chọn capacity lớn nhất.