Dynamodb hard
An application performs a `PutItem` with a `ConditionExpression`. The condition fails (e.g., the item already exists), and the database rejects the write. How many WCUs are consumed?
- A 0 WCUs: Since no data was written to the persistent storage.
- B The full WCU cost of the payload: DynamoDB must perform the 'Read' and 'Compare' work on the primary node to evaluate your condition. You pay for the compute and IO effort of the evaluation regardless of the outcome.
- C 0.5 WCUs fixed fee for the failed check.
- D 1 RCU (it is converted to a read charge).
Answer: B. The full WCU cost of the payload: DynamoDB must perform the 'Read' and 'Compare' work on the primary node to evaluate your condition. You pay for the compute and IO effort of the evaluation regardless of the outcome.
Conditional checks are NOT free 'if-statements'. To check if `version=5`, DynamoDB must fetch the item into memory on the primary node and run the logic. Since this work consumes system resources, you are billed the same WCU cost as if the write had succeeded. Over-using conditional writes can lead to high 'failed' costs in high-contention systems.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- DynamoDB has a strict 400KB limit on the size of a single item. What is the recommended design pattern if you need to store larger documents (e.g., 5MB PDFs)?
- What is the primary role of the 'Partition Key' in ensuring DynamoDB's infinite horizontal scalability?
- Why is the `Query` operation generally preferred over `Scan` for production workloads in DynamoDB?
- DynamoDB is a 'fully managed' serverless database. What is a primary operational benefit of this model for an engineering team?
- In 'Provisioned Capacity' mode, how is the performance budget of a DynamoDB table defined?
- When would an architect choose to implement DAX (DynamoDB Accelerator) in front of an existing DynamoDB table?