Bird
Raised Fist0
DynamoDBquery~20 mins

BatchWriteItem in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
BatchWriteItem Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
What is the result of this BatchWriteItem operation?

Consider a DynamoDB table named Users with primary key UserId. You run the following BatchWriteItem request to insert two new users:

{
  "RequestItems": {
    "Users": [
      {"PutRequest": {"Item": {"UserId": {"S": "u1"}, "Name": {"S": "Alice"}}}},
      {"PutRequest": {"Item": {"UserId": {"S": "u2"}, "Name": {"S": "Bob"}}}}
    ]
  }
}

What will the response contain if both writes succeed?

A{"UnprocessedItems": {}}
B{"UnprocessedItems": {"Users": [{"PutRequest": {"Item": {"UserId": {"S": "u1"}, "Name": {"S": "Alice"}}}}]}}
C{"Error": "ProvisionedThroughputExceededException"}
D{"ConsumedCapacity": [{"TableName": "Users", "CapacityUnits": 2}]}
Attempts:
2 left
💡 Hint

If all writes succeed, DynamoDB returns an empty UnprocessedItems map.

🧠 Conceptual
intermediate
2:00remaining
Which limitation applies to BatchWriteItem requests?

When using BatchWriteItem in DynamoDB, which of the following is a true limitation?

AYou can write unlimited items as long as the total size is under 100 MB.
BYou can write up to 25 items or 16 MB of data per request, whichever limit is hit first.
CBatchWriteItem supports conditional writes on items.
DYou can only write items to one table per BatchWriteItem request.
Attempts:
2 left
💡 Hint

Check the official AWS DynamoDB limits for batch writes.

📝 Syntax
advanced
2:00remaining
Which BatchWriteItem request syntax is valid?

Identify the valid JSON syntax for a BatchWriteItem request that deletes an item with UserId 'u3' from the Users table.

A
{
  "RequestItems": {
    "Users": {
      "DeleteRequest": {"Key": {"UserId": {"S": "u3"}}}
    }
  }
}
B
{
  "RequestItems": {
    "Users": [
      {"Delete": {"Key": {"UserId": "u3"}}}
    ]
  }
}
C
{
  "RequestItems": {
    "Users": [
      {"DeleteRequest": {"Key": {"UserId": {"S": "u3"}}}}
    ]
  }
}
D
{
  "RequestItems": [
    {"Users": {"DeleteRequest": {"Key": {"UserId": {"S": "u3"}}}}}
  ]
}
Attempts:
2 left
💡 Hint

Remember the structure: RequestItems maps table names to lists of write requests.

❓ optimization
advanced
2:00remaining
How to handle unprocessed items efficiently after BatchWriteItem?

After calling BatchWriteItem, some items are returned in UnprocessedItems. What is the best practice to handle these unprocessed items?

ARetry the unprocessed items with exponential backoff until all are processed.
BDelete the unprocessed items from your application to avoid duplicates.
CSplit unprocessed items into single-item requests and send them immediately without delay.
DIgnore unprocessed items as they will be processed automatically by DynamoDB.
Attempts:
2 left
💡 Hint

Think about how to avoid throttling and ensure all writes succeed.

🔧 Debug
expert
2:00remaining
Why does this BatchWriteItem request fail with ValidationException?

You run this BatchWriteItem request to put two items into the Products table:

{
  "RequestItems": {
    "Products": [
      {"PutRequest": {"Item": {"ProductId": {"S": "p1"}, "Price": {"N": "20"}}}},
      {"PutRequest": {"Item": {"ProductId": {"S": "p2"}, "Price": 15}}}
    ]
  }
}

Why does this request cause a ValidationException?

AThe JSON syntax is invalid due to a missing comma after the second PutRequest.
BThe ProductId attribute must be a number, not a string.
CBatchWriteItem does not support multiple PutRequests in one call.
DThe second item's Price attribute is missing the DynamoDB data type wrapper.
Attempts:
2 left
💡 Hint

Check the attribute value formats for DynamoDB items.

Practice

(1/5)
1.

What is the main purpose of the BatchWriteItem operation in DynamoDB?

easy
A. To create a new table in DynamoDB
B. To read multiple items from different tables
C. To add or delete multiple items in a single request
D. To update a single item with new attributes

Solution

  1. Step 1: Understand BatchWriteItem functionality

    The BatchWriteItem operation allows you to write (add or delete) multiple items in one request to save time and reduce network calls.
  2. Step 2: Compare options with BatchWriteItem purpose

    Only To add or delete multiple items in a single request correctly describes adding or deleting multiple items in one request, which matches BatchWriteItem's purpose.
  3. Final Answer:

    To add or delete multiple items in a single request -> Option C
  4. Quick Check:

    BatchWriteItem = add/delete many items [OK]
Hint: BatchWriteItem = batch add or delete items [OK]
Common Mistakes:
  • Confusing BatchWriteItem with BatchGetItem
  • Thinking it updates items instead of add/delete
  • Assuming it creates tables
2.

Which of the following is the correct structure for a BatchWriteItem request in DynamoDB?

{
  "RequestItems": {
    "TableName": [
      { "PutRequest": { "Item": { ... } } },
      { "DeleteRequest": { "Key": { ... } } }
    ]
  }
}
easy
A. RequestItems is an array of table names with PutRequest and DeleteRequest inside
B. RequestItems contains table names as keys and arrays of PutRequest or DeleteRequest objects as values
C. RequestItems is a list of items without specifying table names
D. RequestItems only accepts PutRequest objects, not DeleteRequest

Solution

  1. Step 1: Review BatchWriteItem request format

    The RequestItems key maps table names to arrays of write requests, each being either PutRequest or DeleteRequest.
  2. Step 2: Match options to correct format

    RequestItems contains table names as keys and arrays of PutRequest or DeleteRequest objects as values correctly describes the structure: table names as keys, arrays of PutRequest/DeleteRequest as values.
  3. Final Answer:

    RequestItems contains table names as keys and arrays of PutRequest or DeleteRequest objects as values -> Option B
  4. Quick Check:

    RequestItems = table name keys + Put/Delete arrays [OK]
Hint: RequestItems keys are table names with Put/Delete arrays [OK]
Common Mistakes:
  • Using array of table names instead of object with table keys
  • Omitting DeleteRequest option
  • Not nesting PutRequest/DeleteRequest inside arrays
3.

Given the following BatchWriteItem request, what will be the result if one item fails due to exceeding provisioned throughput?

{
  "RequestItems": {
    "Products": [
      { "PutRequest": { "Item": { "ID": { "S": "101" }, "Name": { "S": "Pen" } } } },
      { "PutRequest": { "Item": { "ID": { "S": "102" }, "Name": { "S": "Notebook" } } } }
    ]
  }
}
medium
A. The entire batch fails and no items are written
B. The request throws a syntax error
C. Both items are written regardless of failure
D. Only the failed item is returned in UnprocessedItems for retry

Solution

  1. Step 1: Understand BatchWriteItem error handling

    If some items exceed provisioned throughput, DynamoDB returns those items in UnprocessedItems for retry, not failing the entire batch.
  2. Step 2: Analyze the given scenario

    One item fails due to throughput, so only that item is unprocessed and returned for retry, while others succeed.
  3. Final Answer:

    Only the failed item is returned in UnprocessedItems for retry -> Option D
  4. Quick Check:

    UnprocessedItems = failed items for retry [OK]
Hint: Failed items appear in UnprocessedItems for retry [OK]
Common Mistakes:
  • Assuming all items fail if one fails
  • Thinking BatchWriteItem throws syntax error on throughput issues
  • Believing all items succeed regardless of errors
4.

Identify the error in this BatchWriteItem request snippet:

{
  "RequestItems": {
    "Orders": [
      { "PutRequest": { "Item": { "OrderId": "123", "Amount": 50 } } }
    ]
  }
}
medium
A. The attribute values are missing DynamoDB data types
B. The table name should be an array, not an object
C. PutRequest should be outside the array
D. BatchWriteItem cannot write to Orders table

Solution

  1. Step 1: Check attribute value format in BatchWriteItem

    DynamoDB requires attribute values to specify data types like {"S": "string"} or {"N": "number"} in BatchWriteItem requests.
  2. Step 2: Identify the error in the snippet

    Attributes "OrderId" and "Amount" lack data type wrappers, so the request is invalid.
  3. Final Answer:

    The attribute values are missing DynamoDB data types -> Option A
  4. Quick Check:

    Attribute values need data types like {"S": "text"} [OK]
Hint: Attribute values must include DynamoDB data types [OK]
Common Mistakes:
  • Omitting data types for attribute values
  • Misunderstanding table name structure
  • Placing PutRequest incorrectly
5.

You want to write 50 items to a DynamoDB table using BatchWriteItem. Since the API limits 25 items per batch, how should you handle this in your application?

hard
A. Split the 50 items into two batches of 25 and retry unprocessed items after each batch
B. Send all 50 items in one BatchWriteItem request and expect it to succeed
C. Write items one by one using PutItem to avoid batch limits
D. Use BatchGetItem instead to write multiple items

Solution

  1. Step 1: Recognize BatchWriteItem limits

    BatchWriteItem supports a maximum of 25 items per request, so 50 items must be split into multiple batches.
  2. Step 2: Implement batching and retry logic

    Split 50 items into two batches of 25 each. After each batch, check UnprocessedItems and retry those to ensure all items are written.
  3. Final Answer:

    Split the 50 items into two batches of 25 and retry unprocessed items after each batch -> Option A
  4. Quick Check:

    BatchWriteItem max 25 items; split and retry [OK]
Hint: Split items into max 25 per batch and retry unprocessed [OK]
Common Mistakes:
  • Sending more than 25 items in one batch
  • Ignoring unprocessed items and not retrying
  • Using BatchGetItem to write items
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard