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.

질문됨 일 년 전759회 조회
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
전문가
답변함 일 년 전
  • 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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠