0
0
DynamoDBquery~20 mins

Why single-table design matters in DynamoDB - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Single-Table Design Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why use single-table design in DynamoDB?

Which of the following best explains why single-table design is important in DynamoDB?

AIt reduces the number of tables, improving query efficiency by using composite keys and indexes.
BIt forces you to use relational joins like in SQL databases.
CIt allows storing data in multiple unrelated tables to avoid complexity.
DIt requires creating many tables to separate each entity type.
Attempts:
2 left
💡 Hint

Think about how DynamoDB handles queries and indexes.

query_result
intermediate
2:00remaining
Query result with single-table design

Given a DynamoDB table with partition key 'PK' and sort key 'SK', storing users and their orders in the same table, what will this query return?

Query: PK = 'USER#123' AND begins_with(SK, 'ORDER#')
DynamoDB
Table data example:
PK          | SK          | Attribute
USER#123    | ORDER#001   | {amount: 50}
USER#123    | ORDER#002   | {amount: 75}
USER#123    | PROFILE    | {name: 'Alice'}
USER#456    | ORDER#001   | {amount: 20}
AReturns all orders for user 123: ORDER#001 and ORDER#002 items.
BReturns the user profile only.
CReturns all items with PK 'USER#123', including profile and orders.
DReturns orders for all users.
Attempts:
2 left
💡 Hint

Look at how the sort key condition filters items.

📝 Syntax
advanced
2:00remaining
Identify the correct DynamoDB query syntax for single-table design

Which of the following DynamoDB query snippets correctly queries all orders for user with ID '123' using single-table design?

DynamoDB
Assume table has PK as 'PK' and SK as 'SK'.
Aquery({ KeyConditionExpression: 'PK = :pk AND SK = :sk', ExpressionAttributeValues: { ':pk': 'USER#123', ':sk': 'ORDER#' } })
Bquery({ FilterExpression: 'PK = :pk AND SK LIKE :sk', ExpressionAttributeValues: { ':pk': 'USER#123', ':sk': 'ORDER#%' } })
Cquery({ KeyConditionExpression: 'PK = USER#123 AND SK starts_with ORDER#' })
Dquery({ KeyConditionExpression: 'PK = :pk AND begins_with(SK, :sk)', ExpressionAttributeValues: { ':pk': 'USER#123', ':sk': 'ORDER#' } })
Attempts:
2 left
💡 Hint

Check the correct use of KeyConditionExpression and begins_with function.

optimization
advanced
2:00remaining
Optimizing access patterns in single-table design

You want to efficiently retrieve all comments for a blog post and the post's metadata from a single DynamoDB table. Which design approach best supports this?

AUse a global secondary index with the comment ID as partition key.
BStore posts and comments in separate tables to avoid mixing data.
CUse the same partition key for the post and its comments, and different sort key prefixes to distinguish item types.
DStore comments as a JSON array inside the post item.
Attempts:
2 left
💡 Hint

Think about how single-table design groups related items.

🔧 Debug
expert
2:00remaining
Debugging a failing query in single-table design

A developer runs this DynamoDB query to get all orders for user '123', but it returns no results:

query({
  KeyConditionExpression: 'PK = :pk AND SK = :sk',
  ExpressionAttributeValues: { ':pk': 'USER#123', ':sk': 'ORDER#' }
})

What is the most likely reason?

AThe partition key value ':pk' is incorrect and should be 'USER#001'.
BThe query uses '=' for SK, but SK values include order IDs like 'ORDER#001', so no exact match occurs.
CThe query is missing a FilterExpression to filter orders.
DDynamoDB does not support querying with KeyConditionExpression.
Attempts:
2 left
💡 Hint

Consider how sort keys are structured in single-table design.