Troubleshooting and Optimization · Topic 5 of 5
Caching and Performance Bottleneck Detection
Choose ElastiCache, DAX, CloudFront or API Gateway caching, find performance bottlenecks with CloudWatch and X-Ray, and use AI tools to spot optimizations.
- 5 min
- DAX is for DynamoDB only; strongly consistent reads bypass its cache.
- DAX item and query caches default to a five minute TTL.
- Lazy loading caches only what is read; write through keeps data fresh.
What it is
A cache keeps a copy of data that is expensive to fetch or compute in a faster place, so repeat requests skip the slow path. Caching cuts latency and reduces load on the database or backend.
A bottleneck is the one component that limits overall speed. You cannot tune what you have not found, so detection comes first, then caching and other fixes.
How it works
Choosing the cache
| Cache | Sits in front of | Best for |
|---|---|---|
| Amazon ElastiCache | Any data store, such as RDS or an API | General purpose in memory cache that your code reads and writes |
| DynamoDB Accelerator (DAX) | DynamoDB only | Microsecond reads for read heavy tables, with almost no code change |
| Amazon CloudFront | Web, API and S3 origins | Static and cacheable content close to users |
| API Gateway cache | A REST API stage | Caching integration responses per stage |
Amazon ElastiCache
ElastiCache offers Valkey, Redis OSS and Memcached engines. Valkey and Redis OSS add replication, high availability, persistence and rich data structures. Memcached is simpler and has no replication.
Your code decides how the cache is filled:
- Lazy loading (cache aside): read the cache first; on a miss, read the database and write the result to the cache. Only requested data is cached, but a miss costs extra time and data can go stale.
- Write through: update the cache whenever you write to the database. Data stays fresh, but you cache items that may never be read.
- TTL: every entry gets an expiry, which bounds staleness.
DynamoDB Accelerator
DAX is a managed in memory cache that is API compatible with DynamoDB. You point the DAX client at the cluster endpoint instead of using the DynamoDB client.
- Eventually consistent reads (the default) are served from the cache on a hit.
- Strongly consistent reads pass through to DynamoDB and are not cached.
- The item cache holds GetItem and BatchGetItem results, and the query cache holds Query and Scan result sets. Both default to a five minute TTL.
Use DAX for a repeated read heavy workload against DynamoDB. It does not help write heavy tables or workloads that need strongly consistent reads.
Amazon CloudFront
CloudFront caches responses at edge locations. The cache lifetime comes from the cache policy's minimum, default and maximum TTL, and from the origin's Cache-Control (max-age, s-maxage) or Expires headers. Without a cache policy the default TTL is 24 hours.
- To update an object before it expires, create an invalidation, or better, use versioned file names such as app.v2.js so the new name is a cache miss.
- The cache key decides what makes two requests different. Including extra headers, cookies or query strings lowers the hit rate, so include only what the origin needs.
API Gateway caching
Caching is enabled per stage on REST APIs. The default TTL is 300 seconds and the maximum is 3,600; a TTL of 0 disables it. By default only GET methods are cached. Choose which request parameters form the cache key. Cache hits and misses show as CacheHitCount and CacheMissCount in CloudWatch.
Detecting bottlenecks
| Tool | What it shows |
|---|---|
| CloudWatch metrics and dashboards | Duration, Throttles, ConcurrentExecutions, queue age, database latency and capacity use |
| X-Ray service map and traces | Which service or downstream call adds the time |
| CloudWatch Logs Insights | Slowest requests, error patterns, REPORT line memory and duration |
| CloudWatch Contributor Insights | The top contributors, such as the most accessed or throttled DynamoDB keys, which reveals a hot partition |
Read the pattern: rising Duration with flat traffic points at a slow dependency, Throttles point at a limit, and a few keys dominating DynamoDB throttling points at a hot partition key.
AI tools for optimization
- CloudWatch investigations: analyzes telemetry for an issue and suggests related metrics, logs and likely causes.
- Kiro and Amazon Q Developer: chat in the IDE can review a function, point out repeated calls inside loops or work that could be cached, and suggest refactors. The Q Developer IDE plugins end on April 30, 2027, and Kiro replaces them.
- AWS Compute Optimizer: recommends Lambda memory settings from observed usage.
These produce suggestions. Test each one and compare metrics before and after the change.
How the exam asks about this
- "A read heavy DynamoDB table needs microsecond latency with minimal code change" -> put DAX in front of the table.
- "Users in other Regions load static assets slowly" -> serve them through CloudFront with a suitable TTL.
- "Which tool shows which downstream call adds the most latency to a request?" -> the X-Ray service map and trace timeline.
What to remember for the exam
- DAX is for DynamoDB only; strongly consistent reads bypass its cache.
- DAX item and query caches default to a five minute TTL.
- Lazy loading caches only what is read; write through keeps data fresh.
- CloudFront default TTL is 24 hours without a cache policy; use versioned file names or invalidations to update content.
- API Gateway cache is per stage, with a default TTL of 300 seconds and a maximum of 3,600.
- X-Ray finds the slow service; Logs Insights finds the slow requests; Contributor Insights finds hot keys.
A cache that is too aggressive serves stale data. If a scenario needs the latest value on every read, DAX and long TTLs are the wrong answer.
Common mistakes
Putting DAX in front of strongly consistent reads. Those reads are passed to DynamoDB, so DAX adds a hop and no benefit.
Caching without a TTL. Entries linger and users see old data. Set an expiry that matches how fast the data changes.
Optimizing before measuring. Adding a cache to a component that is not the bottleneck adds cost and complexity with no gain.
Check yourself
Why would DAX not speed up a workload that uses strongly consistent reads?
DAX passes strongly consistent reads through to DynamoDB and does not cache them.
How can you push a changed CloudFront object to users immediately?
Create an invalidation, or avoid the problem by publishing the new content under a versioned file name.
Which tool reveals a DynamoDB hot partition key?
CloudWatch Contributor Insights, which shows the most accessed and throttled keys.
Topic 5 of 5 in Troubleshooting and Optimization
Test yourself on Troubleshooting and Optimization
The full AWS DVA-C03 question bank has 850 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.