DAX does not have Query cache hits

0

Hello,

I have an architecture with 2 Lambdas, a DynamoDB table with PK+SK, and DAX. The use-case is as follow:

  • Lambda 1 put Items in DAX using PK and SK with standard DynamoDB interface
        Table table = dynamoClient.getTable(tableDetails.getTableName());
        PrimaryKey itemKey = new PrimaryKey();
        itemKey.addComponent(tableDetails.getTablePKName(), tableDetails.getTablePKValue());
        itemKey.addComponent(tableDetails.getTableSKName(), tableDetails.getTableSKValue());
        Item item = new Item().withPrimaryKey(itemKey).withJSON("document", jsonResult);
        PutItemOutcome output = table.putItem(item);
  • Lambda 2 query same items from DAX using only PK with standard DynamoDB interface
       Table table = dynamoClient.getTable(tableDetails.getTableName());
       QuerySpec spec = new QuerySpec().withHashKey(tableDetails.getTablePKName(), tableDetails.getTablePKValue());
       ItemCollection<QueryOutcome> items = table.query(spec);

None of the inserted items was detected in DAX by the query. The Metrics are for 10 instances of Lambda 1 and Lambda 2:

  • PutItem requests : 10
  • Query requests : 10
  • Query cache misses : 10
  • Query cache hits : 0

Why DAX does not have Query cache hits in this use-case ? The use-case does not support query with PK+SK. Are there some conditions for java code in this use-case ?

Update: Lambda 2 is a destination for Lambda 1, so for a PK, Lambda 2 runs always after Lambda 1.

Thank you,
Mihai ADAM

2 Answers
2
Accepted Answer

A simple answer to your question is that you are expecting write operations (Lambda 1) to update the Query cache, but it will not. Query cache is only populated from Query and Scan operations.

  • When you write to DAX, the items are cached in the Item cache, using a key (TableName, PK, SK?).
  • When you do a Query from DAX, you read from the Query cache, which uses the requests parameters in the request (TableName, KeyConditionExpression, ProjectionExpression, ExclusiveStartKey, Limit, among others).

From that information you should be able to understand why you are not getting cache its.

profile pictureAWS
EXPERT
answered 25 days ago
  • Hello,

    I had a use case in test when I ran the application several times with the exact same items. So, the same query was performed several times on same PKs (but I deleted the data from DynamoDB and reinserted with put), but there was still no hit ? Why did this behaviour occurred ?

    A collateral question is about the situation when DynamoDB data is deleted using Management Console. Will the DAX data synchronize itself with DynamoDB, in this case ?

    Is there a detailed documentation about these kind of use-cases for DAX ?

    Thank you,

    • standard interface: putItem, getItem, batchGetItem, batchWriteItem, transactGetItem, transactWriteItem, deleteItem, updateItem
      • Yes
    • does enhanced interface work with Item Cache ? Ex: putItem, getItem, deleteItem, updateItem
      • Yes
    • Does enhanced interface works with standard interface on same cache (same PK put with standard is get with enhanced) ?
      • Yes
  • If you delete the data via the management console, DAX will not know you done so, and will not sync up until the items are evicted or overwritten via DAX.

  • Hello,

    Yes, you are right, this is what I expected.
    Regarding "When you write to DAX, the items are cached in the Item cache", does it mean that with this cache are working the following methods:

    • standard interface: putItem, getItem, batchGetItem, batchWriteItem, transactGetItem, transactWriteItem, deleteItem, updateItem
    • does enhanced interface work with Item Cache ? Ex: putItem, getItem, deleteItem, updateItem
      Does enhanced interface works with standard interface on same cache (same PK put with standard is get with enhanced) ?

    Regarding "When you do a Query from DAX, you read from the Query cache", does it mean that with this cache are working the following methods:

    • standard & enhanced interfaces : table.query, table.scan

    Thank you,

0

Here are some points to consider that might explain why you're not seeing query cache hits in your use case:

  • DAX caches GetItem, BatchGetItem, Query, and Scan results, but exact match queries are required for cache hits.
  • DAX uses a write-through strategy, directly caching PutItem operations but not automatically caching Query results unless the exact query has been made before.
  • Querying only by PK generates a different cache key than inserting with PK+SK, leading to cache misses.
  • Even if Lambda 2 runs after Lambda 1, the absence of SK in the query changes the cache key, causing cache misses.
  • DAX configuration and the TTL of cached items can affect cache hit rates. Frequent updates or deletes can invalidate cache items.

So, to improve cache hits, you need to align query patterns with caching behavior, consider a cache warming strategy, and adjust DAX configurations for better cache utilization.

profile picture
EXPERT
answered a month ago
profile pictureAWS
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions