We have a business rule that one account can only have 3 projects at any given time.
In order to keep it efficient, we track the number of projects in an "userData" field instead of doing a COUNT query
Consider the following example objects already in DynamoDB:
userData : { createdProjects : 2 }
project1 : { id : 1 }
project2 : { id : 2 }
In order to enforce this rule, we've done the following when creating a project (pseudo code)
in transaction:
putItem(key = "project3", object = { id : 3 })
updateItem(
key = "userData",
expression = "createdProjects = createdProjects + 1"
condition = "createdProjects < 3"
)
Now, if the user tries to create a project at the same time with two computers let's say, will DynamoDB guarantee that he won't be able to create more than 3?
I know there are similar questions like this one, but I wanted to know if this also works in a transaction, because my condition is in another object.
Also, is my pseudo code the best approach? open to other ways