Lesson 3 of 6 Amazon DynamoDB

Caching DynamoDB Reads with DAX

This lesson explains how DynamoDB Accelerator (DAX), an in-memory cache for DynamoDB, cuts read latency from milliseconds to microseconds with almost no application changes.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe how DAX works as a write-through cache.
  • Decide when DAX helps and when it does not.

How DAX works

DynamoDB Accelerator (DAX) is an in-memory, write-through cache cluster that runs in the customer's VPC in front of one or more DynamoDB tables, reducing read latency from milliseconds to microseconds. It is API-compatible with DynamoDB through the DAX client, so applications change only the client they use, not their queries.

DAX keeps an item cache for GetItem results and a query cache for Query and Scan results, each with a time to live. Clusters span several Availability Zones for availability. DAX suits read-heavy workloads with repeated reads of the same items, but not workloads that require strongly consistent reads, which DAX passes through to DynamoDB.

The following diagram shows the read and write paths through DAX.

DynamoDB Accelerator in front of a table. The application uses the DAX client with the same DynamoDB API. DAX answers repeated reads from its item and query caches in microseconds, writes through to the table, and passes strongly consistent reads straight to DynamoDB.
Workloads that need strongly consistent reads gain nothing from DAX, because those reads bypass the cache.

When DAX helps

DAX is an in-memory cache built for DynamoDB: an application switches to the DAX client, and reads are answered from memory in microseconds. It helps read-heavy workloads that read the same items repeatedly, applications that need microsecond latency, and tables where a few popular items consume a large share of read capacity.

DAX does not help everywhere. Strongly consistent reads bypass the cache and go to DynamoDB. Writes pass through DAX to the table, so it does nothing for write-heavy workloads or write throttling. It caches only DynamoDB responses, so results computed from several sources belong in ElastiCache. The following table summarises when DAX helps.

HelpsDoes not help
Read-heavy workloads with repeated reads of the same itemsStrongly consistent reads, which pass through to DynamoDB
Microsecond latency requirementsWrite-heavy workloads or write throttling
Reducing read capacity on hot itemsCaching computed results from several sources (use ElastiCache)
Sort into groups

DAX or not?

Exam skills 3.3.5

Decide whether DAX helps each workload.

Log in to try this activity Interactive activities are free with an account.
Worked example

Microsecond reads for a product catalogue

DAX improves performance only for certain access patterns. The following table assesses several requirements and indicates whether DAX is suitable for each.

RequirementFits DAX?
Product details read thousands of times a second during salesYes: repeated eventually consistent reads served from memory
Account balances that must always be currentNo: strongly consistent reads bypass DAX
A write-heavy telemetry tableNo: DAX does not speed up writes
Minimal code changeYes: replace the DynamoDB client with the DAX client

The catalogue service adds a three-node DAX cluster across AZs in its VPC, cutting read latency to microseconds and the table's read capacity sharply.

Check yourself

Does DAX help a write-heavy workload?

Show answer

No. DAX caches reads, giving microsecond response times for repeated reads; writes still go to DynamoDB.

Exam Tips

Remember for the exam

  • For microsecond read latency for DynamoDB, use DAX.
  • DAX does not help write-heavy workloads or strongly consistent reads.
  • To cache DynamoDB reads with minimal code changes, use DAX rather than ElastiCache.