0

Does the DynamoDB Java SDKv2 offer a retry strategy for batchWriteItem calls? I'm looking for a retry strategy that retries items that would otherwise be returned as unprocessedItems.

In the DynamoDB Java SDKv1 there was the DynamoDBMapper default retry strategy to achieve this, see https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/dynamodbv2/datamodeling/DynamoDBMapperConfig.DefaultBatchWriteRetryStrategy.html.

I couldn't find anything related to retries out of the box for batch operations in the official javadoc, e.g. https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/dynamodb/DynamoDbClient.html#batchWriteItem(java.util.function.Consumer) or https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/enhanced/dynamodb/package-summary.html.

I was hoping I don't have to implement retries myself on top of the default or enhanced client.

1 Answer 1

1

Just ran into this issue a few days ago.

The document suggests a simple loop way now instead of complex retry strategy. And the loop code is simple :)

Document link:

Typically, you would call BatchWriteItem in a loop. Each iteration would check for unprocessed items and submit a new BatchWriteItem request with those unprocessed items until all items have been processed.

And aws also provides code example here

2
  • Thank you, looks like this is the recommendation, but in my opinion it also has some drawbacks. I wanted to have exponential backoff, so this already adds some complexity on my side, and code duplication potentially if I need to implement this for more operations.
    – yassin
    Commented May 21, 2024 at 11:01
  • 1
    @yassin looks like we have to do some coding to get exponential backoff working in the Java SDK v2. Seems sometimes DynamoDB isn't very developer-friendly. e.g., I have to deal with the 1MB query limit when trying to get the total count of a table :|
    – NeveMore
    Commented May 21, 2024 at 11:45

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.