0
0
DynamoDBquery~20 mins

Error handling and retries in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
DynamoDB Error Handling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output when a conditional write fails due to a condition check?

Consider the following DynamoDB operation using the AWS SDK:

const params = {
  TableName: 'Users',
  Key: { 'UserId': '123' },
  UpdateExpression: 'SET Age = :newAge',
  ConditionExpression: 'Age = :oldAge',
  ExpressionAttributeValues: {
    ':newAge': 30,
    ':oldAge': 25
  }
};

try {
  await dynamodb.update(params).promise();
  console.log('Update succeeded');
} catch (err) {
  console.log('Update failed:', err.code);
}

If the current Age of user 123 is 28, what will be printed?

AUpdate failed: ValidationException
BUpdate succeeded
CUpdate failed: ConditionalCheckFailedException
DUpdate failed: ResourceNotFoundException
Attempts:
2 left
💡 Hint

Think about what happens when the condition in ConditionExpression is not met.

query_result
intermediate
1:30remaining
What happens when a DynamoDB request exceeds provisioned throughput?

When a DynamoDB query exceeds the provisioned throughput limits, what error code is returned by the service?

AResourceInUseException
BThrottlingException
CLimitExceededException
DProvisionedThroughputExceededException
Attempts:
2 left
💡 Hint

Look for the specific error related to throughput limits in DynamoDB.

📝 Syntax
advanced
2:30remaining
Which retry strategy code snippet correctly retries a DynamoDB operation on throughput errors?

Given the following retry logic, which option correctly implements exponential backoff with jitter for retrying a DynamoDB operation?

DynamoDB
async function retryOperation(operation, maxRetries) {
  let retries = 0;
  while (retries < maxRetries) {
    try {
      return await operation();
    } catch (err) {
      if (err.code === 'ProvisionedThroughputExceededException') {
        const delay = Math.pow(2, retries) * 100 + Math.random() * 100;
        await new Promise(res => setTimeout(res, delay));
        retries++;
      } else {
        throw err;
      }
    }
  }
  throw new Error('Max retries reached');
}
AThe code retries only once and does not handle jitter.
BThe code correctly implements exponential backoff with jitter and retries on throughput errors.
CThe code retries immediately without delay, causing rapid retries.
DThe code retries on all errors, not just throughput errors.
Attempts:
2 left
💡 Hint

Check if the delay increases exponentially and includes randomness.

🔧 Debug
advanced
2:00remaining
Why does this DynamoDB retry loop never stop?

Consider this retry loop for a DynamoDB operation:

let retries = 0;
while (retries < 5) {
  try {
    await dynamodb.putItem(params).promise();
    break;
  } catch (err) {
    if (err.code === 'ProvisionedThroughputExceededException') {
      retries++;
    }
  }
}

Why might this loop never exit even after 5 retries?

ABecause there is no delay between retries, causing immediate repeated failures.
BBecause the retries counter is never incremented.
CBecause the break statement is outside the try block.
DBecause the error code is misspelled and never matches.
Attempts:
2 left
💡 Hint

Think about what happens if retries happen too fast.

🧠 Conceptual
expert
3:00remaining
What is the best practice for handling idempotency in DynamoDB retries?

When retrying write operations in DynamoDB due to transient errors, what is the recommended approach to ensure idempotency and avoid duplicate writes?

AUse a unique client-generated idempotency token as a condition attribute to prevent duplicate writes.
BRetry blindly without any checks because DynamoDB automatically prevents duplicates.
CDelete the item before retrying the write operation.
DUse a random delay before each retry to reduce duplicates.
Attempts:
2 left
💡 Hint

Think about how to uniquely identify each write attempt.