Does DynamoDB `UpdateItem` operation read data with strong consistency while `UpdateExpression` is specified?

0

So I have such use case for this operation. I am appending an item to a list attribute with UpdateExpression, and what I also have is that if this attribute does not exist, just create new one.

So expression looks like this

SET history = list_append(if_not_exists(history, :historyEmpty), :historyRecord)

However I am doing this call twice in a very short time span and I we have observed that second call might overwrite the first one. For example, if first call was done with :historyRecord = [{ data: 'data' }], and second one was done with :historyRecord = [{ data: 'data2'}] I will only have the second one in the database. This does not happen all the time tho, only if those two calls happened closely in time and that is why I suspect it might be related to read consistency. (first operation happens during an API call, and second one is during a state machine that gets started from that API call). The expected behavior is to have historyRecord = [{ data: 'data' }, { data: 'data2' }] in the database.

已提問 1 年前檢視次數 762 次
1 個回答
1

DynamoDB does not do any reads when executing a write operation. Furthermore, it provides serializable isolation, so when you execute 2 requests concurrently, one of those items will get executed before the other and the second request will always see the most up to date data (the results of the first request).

I suspect that perhaps there is an issue in your logic when executing the requests, as both values should exist when all processes are complete. Ensure you are not overwriting data by calling PutItem etc...

profile pictureAWS
專家
已回答 1 年前
  • I think you misunderstood. I am not doing two operations. I do only a single operation, which is UpdateItem. Which, I was thinking does reading by itself since it needs to resolve if_not_exists in updateExpression.

  • Understood, but my answer remains relevant. DynamoDB does not read, there's no consistency at play. All write operations go to the leader node of a partition, meaning it will only see the most up-to-date values for that item. if_not_exists is resolved at the underlying storage level, on the SSD disk, in a serializable way. All single operation writes (PutItem, UpdateItem, DeleteItem) provide full ACID guarantees.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南