0
0
DynamoDBquery~20 mins

Partition key selection in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Partition Key Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why is choosing a good partition key important in DynamoDB?

Imagine you have a DynamoDB table storing user orders. Which reason best explains why selecting a good partition key matters?

AIt prevents the need for a sort key in the table design.
BIt guarantees that all data is stored in a single partition for faster access.
CIt allows DynamoDB to automatically create indexes without user input.
DIt ensures data is evenly distributed across partitions to avoid hot spots and improve performance.
Attempts:
2 left
💡 Hint

Think about how DynamoDB stores data internally and what happens if too many items share the same partition key.

query_result
intermediate
2:00remaining
What is the result of this partition key choice?

Given a DynamoDB table with partition key 'Country' and sort key 'UserID', what happens if most users are from the same country?

DynamoDB
Table: Users
Partition Key: Country
Sort Key: UserID
Data: 90% users have Country = 'USA', 10% others

Question: How does this affect performance?
AThe 'USA' partition becomes a hot partition causing throttling and slower queries.
BData is evenly distributed because sort key balances the load.
CDynamoDB automatically splits the 'USA' partition to handle load.
DQueries on 'USA' users will be faster due to data locality.
Attempts:
2 left
💡 Hint

Consider how DynamoDB partitions data based on the partition key only.

📝 Syntax
advanced
2:00remaining
Which partition key definition is valid in DynamoDB table creation?

Choose the correct AWS CLI command snippet to create a DynamoDB table with a partition key named 'UserID' of type string.

DynamoDB
aws dynamodb create-table --table-name Users --attribute-definitions ... --key-schema ... --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
A--attribute-definitions AttributeName=UserID,AttributeType=N --key-schema AttributeName=UserID,KeyType=HASH
B--attribute-definitions AttributeName=UserID,AttributeType=S --key-schema AttributeName=UserID,KeyType=HASH
C--attribute-definitions AttributeName=UserID,AttributeType=BOOL --key-schema AttributeName=UserID,KeyType=HASH
D--attribute-definitions AttributeName=UserID,AttributeType=SS --key-schema AttributeName=UserID,KeyType=HASH
Attempts:
2 left
💡 Hint

Check the valid attribute types for partition keys in DynamoDB.

optimization
advanced
2:00remaining
How to optimize partition key for a high-traffic IoT sensor data table?

You have a DynamoDB table storing sensor readings. Each sensor sends data every second. Which partition key design best avoids hot partitions?

AUse 'SensorID' as partition key to distribute data evenly across sensors.
BUse a constant value as partition key to simplify queries.
CUse 'SensorID' concatenated with date (e.g., 'SensorID#20240601') as partition key.
DUse 'Timestamp' as partition key to group data by time.
Attempts:
2 left
💡 Hint

Think about how to spread writes evenly when sensors send frequent data.

🔧 Debug
expert
2:00remaining
Why does this DynamoDB query cause throttling despite low overall traffic?

Given a table with partition key 'UserID' and sort key 'OrderDate', a query filters orders for UserID='123'. Despite low total traffic, the query is throttled. What is the likely cause?

DynamoDB
Query:
{
  TableName: 'Orders',
  KeyConditionExpression: 'UserID = :uid',
  ExpressionAttributeValues: { ':uid': '123' }
}
AUserID='123' has many orders causing a hot partition and throttling.
BThe query syntax is invalid causing throttling errors.
CSort key 'OrderDate' is missing in the query causing throttling.
DProvisioned throughput is too high causing throttling.
Attempts:
2 left
💡 Hint

Consider what happens if one partition key value has a lot of data.