Multiple actions in one update in DynamoDB - Time & Space Complexity
When updating a DynamoDB item with several changes at once, it's important to know how the work grows as the number of changes increases.
We want to understand how the time to update changes when we add more actions in a single update.
Analyze the time complexity of the following code snippet.
UpdateItem {
Key: { id: "123" },
UpdateExpression: "SET attr1 = :val1, attr2 = :val2, attr3 = :val3",
ExpressionAttributeValues: {
":val1": "value1",
":val2": "value2",
":val3": "value3"
}
}
This code updates one item by setting three attributes in a single update request.
- Primary operation: Applying each update action to the item attributes.
- How many times: Once for each attribute being updated (3 times in this example).
Each additional attribute update adds a small extra step to the work done.
| Input Size (number of updates) | Approx. Operations |
|---|---|
| 3 | 3 update actions |
| 10 | 10 update actions |
| 100 | 100 update actions |
Pattern observation: The work grows directly with the number of update actions.
Time Complexity: O(n)
This means the time to complete the update grows in a straight line as you add more actions.
[X] Wrong: "Doing multiple updates in one request takes the same time as one update."
[OK] Correct: Each update action adds work, so more actions mean more time, not the same time.
Understanding how multiple updates affect time helps you explain and predict performance in real DynamoDB tasks.
"What if we batch multiple update requests instead of combining actions in one update? How would the time complexity change?"