Skip to content

Running DAX and DynamoDbEnhanced client both for DynamoDbTemplate or two DynamoDbTemplates #1645

Description

@ipsi-apant

Type: Feature

Is your feature request related to a problem? Please describe.
DynamoDbAutoConfiguration is either configuring DAX DynamoDbClient or a sync client. This a hard line at the moment and restricts running both clients together.
We are planning to use sync client for write operations and DAX client for read operations.

Describe the solution you'd like
Currently only option I see is to completely configure two clients separately, which will move away from spring-cloud-aws library for dynamodb. Plus it will increase the time to work on all the boiler plate for these clients.
Is there a way to configure both with DynamoDbTemplate features? This would be great.

Also, I have added comment here requesting support for async client.
#944 (comment)

Describe alternatives you've considered
The alternative would be to configure both clients separately and we will loose some of the functionality of DynamoDbTemplate, plus this will open the door for maintenance.

Following is the sample example for retrieving records using both clients. This lacks some of DynamoDbTemplate features and auto configurations.

public class DynamoDbDualClientExample {

    public static void main(String[] args) {
        String daxClusterEndpoint = "dax://://amazonaws.com";

        // 1. Initialize the standard DynamoDB Sync Client
        DynamoDbClient standardClient = DynamoDbClient.builder()
                .build(); 

        // 2. Initialize the DAX Client
        DynamoDbClient daxClient = DaxClient.builder()
                .endpoint(daxClusterEndpoint)
                .build();

        String tableName = "Products";
        String productId = "12345";

        // Scenario A: Fast, cached, eventually consistent read using DAX
        GetItemResponse cachedResponse = daxClient.getItem(GetItemRequest.builder()
                .tableName(tableName)
                .key(java.util.Map.of("ProductId", AttributeValue.builder().s(productId).build()))
                .build());

        // Scenario B: Critical, strongly consistent read using standard DynamoDB
        GetItemResponse consistentResponse = standardClient.getItem(GetItemRequest.builder()
                .tableName(tableName)
                .key(java.util.Map.of("ProductId", AttributeValue.builder().s(productId).build()))
                .consistentRead(true) // Strongly consistent reads must bypass DAX
                .build());
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions