Dynamo DB: Transactions
Conditional writes / Optimistic updates (Can be done in any database)
This is way where the client first reads the value, then does a conditional write where the condition is that the value should equal to what the client read. If the value has changed due to another write/update operation, the client’s conditional write will fail and then has to retry.
This approach doesn’t use locks but requires more work on the client side.
performance ? is this the best approach ?
Transactions: All or nothing
TransactGetItems
: Read multiple rows but fails if an another write operations modified the rows that are being read. This allows you to get a snapshot of the rows at a given time.TransactWriteItems
: Write/Update multiple rows but fails if any other write modifies the same rows. NO LOCKS, i.e, any other thread/process is allowed to read while the transaction is taking place as well as a write operation but then the tx will fail.
In DynamoDB cluster, transactions are Serializable
, i.e, all transactions run one after another. In fact, all requests are serialized.
Atomic counters
Pitfalls
- Lots of potential collisions due to no locks
- The way to work around or the only way to work around, is the failed transaction will fail and then retry once other transactions succeed. This will consume more write units (more money).