0
0
DynamoDBquery~20 mins

Partition key distribution 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
1:30remaining
Why is a good partition key important in DynamoDB?

Imagine you have a large table in DynamoDB. Why does choosing a good partition key matter for performance?

AIt automatically backs up the table data to another region.
BIt makes the table smaller by compressing data automatically.
CIt encrypts the data stored in the table for security.
DIt evenly spreads data and requests across partitions to avoid hot spots.
Attempts:
2 left
💡 Hint

Think about how DynamoDB stores data internally and handles requests.

query_result
intermediate
1:30remaining
What is the output of this DynamoDB query?

Given a DynamoDB table with partition key 'UserID' and sort key 'Timestamp', what will this query return?

Query: KeyConditionExpression = UserID = 'user123' AND Timestamp BETWEEN 100 AND 200
AAll items for 'user123' with Timestamp between 100 and 200 inclusive.
BAll items for all users with Timestamp between 100 and 200.
CAll items for 'user123' with Timestamp exactly 100 or 200 only.
DAn error because BETWEEN cannot be used with sort keys.
Attempts:
2 left
💡 Hint

Remember how KeyConditionExpression works with partition and sort keys.

📝 Syntax
advanced
1:30remaining
Identify the syntax error in this DynamoDB query expression

Which option contains a syntax error in the KeyConditionExpression for DynamoDB?

KeyConditionExpression: "UserID = :uid AND Timestamp > :start AND Timestamp < :end"
AUserID = :uid AND Timestamp >= :start AND Timestamp <= :end
BUserID = :uid OR Timestamp BETWEEN :start AND :end
CUserID = :uid AND Timestamp BETWEEN :start AND :end
DUserID = :uid AND Timestamp > :start AND Timestamp < :end
Attempts:
2 left
💡 Hint

Check if all logical operators are allowed in KeyConditionExpression.

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

You have a DynamoDB table receiving many requests for a few partition key values, causing throttling. What is the best way to optimize partition key design?

ARemove the partition key and use only a sort key.
BUse a single static partition key for all items to simplify queries.
CAdd a random suffix to the partition key to spread traffic across more partitions.
DIncrease the provisioned throughput without changing the key design.
Attempts:
2 left
💡 Hint

Think about how to avoid hot partitions by spreading requests.

🔧 Debug
expert
2:30remaining
Why does this DynamoDB query cause a 'ValidationException' error?

Consider this query code snippet:

KeyConditionExpression = "UserID = :uid AND OrderDate = :date"
ExpressionAttributeValues = {":uid": "user1", ":date": "2023-01-01"}

Why does this cause a ValidationException?

ABecause the table does not have a sort key named 'OrderDate'.
BBecause the sort key condition uses '=' instead of a range operator like BETWEEN or >.
CBecause the sort key 'OrderDate' must use a range operator, '=' is not allowed.
DBecause the partition key 'UserID' is missing from ExpressionAttributeValues.
Attempts:
2 left
💡 Hint

Check the table schema and key names carefully.