Skip to Content
Asterrr's Handbook
2 · New solutions

Caching

Where to cache (CloudFront, API Gateway, ElastiCache, DAX), how to raise the CloudFront cache hit ratio, and how to make a cache layer fault tolerant.

Exam tasks: 2.5 (design for performance: caching strategy), 3.3 (improve the performance of an existing solution)

The decision: which layer should answer the request so the expensive thing behind it (origin, API, database) does less work, and what happens to users when that cache fails or goes stale?

The layers

Edge locationAWS RegionmissmissCloudFront andOrigin ShieldS3 static assetsAPI Gatewaystage cacheLambdaDAXDynamoDBALBApp on EC2 orECSElastiCacheRDS or AuroraUsers
Cache at every layer. CloudFront at the edge, API Gateway stage cache, DAX for DynamoDB and ElastiCache in front of relational databases.
LayerCachesBest forWatch out for
CloudFrontHTTP responses at edge locationsStatic assets, cacheable API GETs, videoCache key choices decide the hit ratio
API Gateway cacheResponses per stage and methodRepeated identical REST API callsREST APIs only, billed per hour by size
ElastiCacheAnything your code puts in itDatabase query results, sessions, leaderboardsYour code handles misses and invalidation
DAXDynamoDB items and query resultsRead-heavy DynamoDB with microsecond needsEventually consistent reads only
Aurora or RDS read replicasNot a cache, but offload readsRead-heavy SQL with complex queriesReplica lag
300 s
Default API Gateway cache TTL. The maximum is 3,600 seconds, and 0 turns caching off.
0.5–237 GB
API Gateway cache sizes per stage.
5
Read replicas per ElastiCache (Valkey or Redis OSS) shard.
500
Maximum shards in a cluster-mode-enabled ElastiCache cluster.
Microseconds
DAX read latency, compared with single-digit milliseconds for DynamoDB itself.

CloudFront

Cache keys, policies, Origin Shield and TTL tuning now live on the Amazon CloudFront page.

Service pages

Scenarios

Scenario
A news site serves articles through CloudFront from an ALB origin. The cache hit ratio is 12% and the origin fleet is overloaded during breaking news. The cache policy forwards all query strings and all cookies. Articles vary only by the 'edition' query string. The origin needs the 'x-request-source' header for logging. What should the architect do to raise the hit ratio?
Scenario · choose 2
A gaming company stores player sessions and a global leaderboard in a single-node ElastiCache for Memcached cluster. A node failure logged out every player. Players in Europe and Asia complain of slow leaderboard reads from us-east-1. Which TWO changes address both problems?
Scenario
A product catalog on DynamoDB receives 200,000 reads per second, mostly for the same few thousand popular items, and the team wants microsecond latency with minimal code changes. Writes are light. Which option fits BEST?

Further reading

On this page