Amazon DynamoDB (50 Qs)•Part 3: Advanced Architecture, Scale & Internals (Senior / Lead)
Conditional Writes and Optimistic Locking.
senior LevelSystem Design
In Simple Words: Prevents concurrent overwrite race conditions without database locks:
- Add a
versionnumber attribute to the item. - Perform updates with a
ConditionExpression:SET balance = balance - 50, version = version + 1 WHERE id = 1 AND version = 3 - If another process updated the version first, DynamoDB throws
ConditionalCheckFailedException, allowing the application to retry.