Optimistic lockingĀ is a method to make sure that the client-side merchandise that you’re updating (or deleting) is similar because the merchandise in DynamoDB. Optimistic concurrency is determined by checking a worth upon save to make sure that it has not modified. If you happen to use this technique, then your database writes are shielded from being overwritten by the writes of others ā and vice-versa.
By default, the DynamoDB write operations (PutItem
,Ā UpdateItem
,Ā DeleteItem
) areĀ unconditional: every of those operations will overwrite an current merchandise that has the desired main key.
DynamoDB optionally helps conditional writes for these operations. A conditional write will succeed provided that the merchandise attributes meet a number of anticipated circumstances. In any other case, it returns an error. Conditional writes are useful in lots of conditions. For instance, you may want aĀ PutItem
Ā operation to succeed provided that there may be not already an merchandise with the identical main key. Or you may stop anĀ UpdateItem
Ā operation from modifying an merchandise if one in all its attributes has a sure worth. Conditional writes are useful in circumstances the place a number of customers try to change the identical merchandise.
Within the AWS SDK for PHP, there’s aĀ PessimisticLockingStrategy
Ā class for DynamoDB. This locking technique makes use of pessimistic locking (much like how the native PHP session handler works) to make sure that classes will not be edited whereas one other course of is studying/writing to it. Pessimistic locking may be costly and may improve latencies, particularly in circumstances the place the person can entry the session greater than as soon as on the similar time (e.g. ajax, iframes, or a number of browser tabs).