5

Suppose that a given table already contains the following key value pair:

{ "id": "one", "num": 5000 }

If I write an update expression such as "ADD num :val" to add values as necessary can I expect this to be consistent in case of parallel requests?

codejammer
  • 1,636
  • 1
  • 14
  • 27
  • 1
    What is your underlying concern? In the example given you have no conditions on the update, so what do you mean by consistency? Both updates will increment the value. Check out [Conditional Updates](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html#WorkingWithItems.ConditionalUpdate) – F_SO_K Feb 15 '18 at 10:39
  • 2
    let's say the current value is 10. If I have two updates at the same instant one that adds 2 and another that adds 3 am I guaranteed to get 15 at the end (or will i end up getting 12 or 13?)? – codejammer Feb 15 '18 at 11:20
  • I see. Yes, each one is guaranteed in that case. You will get 15. – F_SO_K Feb 15 '18 at 11:34
  • @F_SO_K I'm sure you're right that the implicit read in some update operations is strongly consistent (this would also apply when adding items to a list, map, or set attribute or when using the if_not_exists function), but I couldn't find anywhere in the AWS doc that specifically says so -- do you have a source? – John Velonis Aug 28 '19 at 15:29

1 Answers1

2

It seems you're guaranteed that the result is consistent, i.e. if the current value is 10 and you add 2 and in another request 3 you will get 15.

I've asked a similar question regarding adding values to a set. An AWS employee answered that the result will be consistent. See https://forums.aws.amazon.com/thread.jspa?messageID=919205

Unfortunately this behavior is not a clearly documented at all.

Markus Kramer
  • 411
  • 5
  • 13