Auto Scaling & stateless design

Elastic, self-healing, horizontally-scaled tiers.

Advanced30 min · lesson 11 of 15

Elasticity — matching capacity to demand automatically — is what makes cloud architecture cost-effective and resilient. Auto Scaling and load balancing together deliver capacity that grows, shrinks, and self-heals.

Auto Scaling groups

An EC2 Auto Scaling group maintains a desired number of instances, adds or removes them based on demand (target-tracking on CPU or request count, scheduled scaling for known patterns), and replaces unhealthy instances automatically — giving you both elasticity and self-healing. Spanning the group across multiple AZs and fronting it with a load balancer is the canonical resilient web tier: traffic spreads across healthy instances in several AZs, capacity follows load, and failed instances are replaced without intervention. Scaling works best when the tier is stateless, so any instance can serve any request and instances can be added or terminated freely.

the elastic, self-healing web tier
ALB (across AZ-a/b/c)
└─ Auto Scaling group min=2 desired=4 max=12
├─ target tracking: keep avg CPU ~50% → scale out/in automatically
├─ health checks: replace unhealthy instances
└─ multi-AZ: capacity spread for availability
# Keep the app STATELESS (session state in DynamoDB/ElastiCache) so any
# instance serves any request and scaling/replacement is seamless.

Stateless design and scaling databases

Horizontal scaling (adding instances) is the cloud-native approach and depends on statelessness — keep session and shared state in a shared store (DynamoDB, ElastiCache) rather than on individual instances, so there are no sticky dependencies. Vertical scaling (bigger instances) has limits and downtime, so it is a last resort. Databases scale differently: reads scale out with read replicas and caching (ElastiCache/DAX), while writes typically scale vertically or, for NoSQL, through DynamoDB’s automatic throughput scaling and good partition-key design. Designing every tier to scale horizontally, with state externalized, is what lets an architecture handle growth and spikes gracefully while only paying for the capacity in use.

Scaling patterns
1stateless app tier
state in DynamoDB/ElastiCache
2Auto Scaling across AZs
capacity follows demand
3read replicas + cache
scale database reads
4pay for what you use
scale in when idle
Externalize state, scale the app tier horizontally across AZs, and scale reads with replicas/caches — elastic and cost-efficient.
Stateful instances break horizontal scaling
Storing session or application state on individual instances means requests must stick to specific servers, and scaling in or replacing an instance loses data. Keep the app tier stateless with shared state in DynamoDB or ElastiCache, so Auto Scaling can add, remove, and replace instances freely — statelessness is the prerequisite for real elasticity.