0
votes

I have a use-case where there we many many different application for the sake of simplicity , lets assume I have 2 applications App-A , App-B

App-A updates dynamoDBTable and due to consistency of data , I was thinking to use Pessimistic locking with App-A

App-B , only reads the DynamoDBTable (other attribute which will not be updated by App-A), hence does not require locking. Also App-B is a front-end application ans latency is a issue. hence I wont want to App-B to acquire locks in a similar fashion as App-A

Can , I use App-A with DynamoDB locks to perform its consistent operations and NOT use DynamoDB locks from App-B ?

1

1 Answers

0
votes

DynamoDB does not support pessimistic locking out of the box. You can implement pessimistic locking using the optimistic lock and atomic operation primitives provided by DynamoDB but at the cost of latency and additional consumed capacity.

For your use case, it sounds like there is a client (an application) that only reads data, so in this case there is no need for locks.

For the other client, which makes updates, it is better if you can design the client to use optimistic locking such that it reads the respective data from the table, attempts to update it and if the update fails due to consistency check it re-processes the operation. The reprocessing part depends on what it is the client is doing but the general pattern is the similar in most cases:

  1. read data from table; make note of version of data
  2. process the data and attempt to update table, with condition check based on the previously read version from #1
  3. if the update succeeds, there is nothing left to do
  4. if the update fails due to version condition check fail, go back to #1 and retry

If you're still curious about implementing pessimistic locking in DynamoDb, have a look at this post: https://aws.amazon.com/blogs/database/building-distributed-locks-with-the-dynamodb-lock-client/ that goes into the design of a distributed lock, based on DynamoDB, that can be used by two, or more clients to synchronize access to any resource (not just data in a DynamoDB table)