Cenxui
Cenxui

Reputation: 1403

What is the AWS Dynamo DB write consistence?

I know that AWS Dynamo DB read has eventually and strongly consistence. And I read a document it says that The individual PutItem and DeleteItem operations specified in BatchWriteItem are atomic; however BatchWriteItem as a whole is not. But I still don't understand how is the write method behavior is synchronized or not.

If this is an awkward question, please tell me.

Upvotes: 1

Views: 436

Answers (1)

Mike Dinescu
Mike Dinescu

Reputation: 55760

BatchWriteItem is a batch API - meaning it allows you to specify a number of different operations to be submitted to Dynamo for execution in the same request. So when you submit a BatchItemRequest you are asking DynamoDB to perform a number of either PutItem or DeleteItem requests for you.

The claim that the individual PutItem and DeleteItem requests are atomic means that each of those is atomic with respect to other requests that may be wanting to modify the same item (identified by it's partition/sort keys) - meaning it's not possible for data corruption to occur within the item because two PutItem requests executed at the same time each modifying some part of the item and thus leaving it in an inconsistent state.

But then, the claim is that the whole BatchWriteItem request is not atomic. That just means that the sequence of PutItem and/or DeleteItem requests is not guaranteed to be isolated, so you could have other PutItem or DeleteItem requests - whether single or batch execute at the same time as the BatchWriteItem request which could affect the state of the table(s) in-between the individual PutItem/DeleteItem requests that make up the batch.

To Illustrate the point, let's say you have a BatchItemRequest that consists of the following 2 calls:

  • PutItem (partitionKey = 1000; name = 'Alpha'; value = 100)
  • DeleteItem (partitionKey = 1000)

And that at approximately the same time you've submitted this request there is another request that has the following operation in it:

  • DeleteItem (partitionKey = 1000)

It is possible that the second delete item request might delete the item before the first request executes and so while the PutItem succeeds, the DeleteItem in the first request would fail with a not found because the item has been deleted by the other delete request. This is one example of how the whole batch operation is not atomic.

Upvotes: 2

Related Questions