Skip to main content
InterviewHubPRO
Section Overview
Q9

Question 9 of 50

Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

18%
Amazon DynamoDB (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)

What are Condition Expressions in DynamoDB writes?

junior LevelCode ExampleDynamoDB

In Simple Words: Condition expressions prevent race conditions and overwrites by executing writes only if specific item attributes meet criteria:

  • attribute_not_exists(PK) ensures an item cannot be overwritten if it already exists (idempotent creation).
  • version = :expectedVersion enables optimistic concurrency control.
typescript
// Optimistic Locking using ConditionExpression:
await client.send(new UpdateItemCommand({
  TableName: "Accounts",
  Key: { accountId: { S: "acc_99" } },
  UpdateExpression: "SET balance = balance - :amount, version = version + :inc",
  ConditionExpression: "balance >= :amount AND version = :currentVersion",
  ExpressionAttributeValues: {
    ":amount": { N: "50" },
    ":inc": { N: "1" },
    ":currentVersion": { N: "4" }
  }
}));