0
0
DynamoDBquery~20 mins

GSI key selection strategy in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GSI Key Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Choosing the Partition Key for a GSI

In DynamoDB, when creating a Global Secondary Index (GSI), which of the following is the best reason to choose a partition key that has high cardinality (many unique values)?

ATo evenly distribute read and write traffic across partitions and avoid hot partitions.
BTo make the index smaller by grouping many items under the same key.
CTo ensure the GSI always returns results sorted by the partition key.
DTo reduce the number of attributes stored in the GSI.
Attempts:
2 left
💡 Hint

Think about how DynamoDB spreads data and traffic across partitions.

query_result
intermediate
2:00remaining
Querying a GSI with Partition and Sort Keys

Given a DynamoDB table with a GSI where the partition key is Category and the sort key is Price, what will be the result of this query?

Query the GSI for Category = 'Books' and Price between 10 and 20.

Assuming the GSI contains these items:

  • {Category: 'Books', Price: 15, Title: 'Book A'}
  • {Category: 'Books', Price: 25, Title: 'Book B'}
  • {Category: 'Books', Price: 12, Title: 'Book C'}
  • {Category: 'Electronics', Price: 15, Title: 'Gadget'}
AReturns all items with Category 'Books' regardless of Price.
BReturns 'Book B' only because Price is 25.
CReturns no items because Price is not the partition key.
DReturns 'Book A' and 'Book C' only.
Attempts:
2 left
💡 Hint

Remember how partition and sort keys work in queries.

📝 Syntax
advanced
2:00remaining
Identifying the Correct GSI Key Schema Syntax

Which of the following JSON snippets correctly defines a GSI key schema with a partition key named UserId and a sort key named Timestamp in a DynamoDB table?

A{ "IndexName": "UserActivityIndex", "KeySchema": [ { "AttributeName": "Timestamp", "KeyType": "HASH" }, { "AttributeName": "UserId", "KeyType": "RANGE" } ] }
B{ "IndexName": "UserActivityIndex", "KeySchema": [ { "AttributeName": "UserId", "KeyType": "HASH" }, { "AttributeName": "Timestamp", "KeyType": "RANGE" } ] }
C{ "IndexName": "UserActivityIndex", "KeySchema": [ { "AttributeName": "UserId", "KeyType": "RANGE" }, { "AttributeName": "Timestamp", "KeyType": "HASH" } ] }
D{ "IndexName": "UserActivityIndex", "KeySchema": [ { "AttributeName": "UserId", "KeyType": "PRIMARY" }, { "AttributeName": "Timestamp", "KeyType": "SORT" } ] }
Attempts:
2 left
💡 Hint

Recall the correct key types for partition and sort keys in DynamoDB.

optimization
advanced
2:00remaining
Optimizing GSI for Query Performance

You have a DynamoDB table storing orders with attributes: OrderId, CustomerId, Status, and OrderDate. You want to create a GSI to efficiently query all orders by CustomerId and sort them by OrderDate. Which GSI key selection strategy is best?

ASet <code>OrderDate</code> as the partition key and <code>CustomerId</code> as the sort key of the GSI.
BSet <code>Status</code> as the partition key and <code>OrderDate</code> as the sort key of the GSI.
CSet <code>CustomerId</code> as the partition key and <code>OrderDate</code> as the sort key of the GSI.
DSet <code>OrderId</code> as the partition key and <code>Status</code> as the sort key of the GSI.
Attempts:
2 left
💡 Hint

Think about how you want to query the data and which attribute groups the data logically.

🔧 Debug
expert
2:00remaining
Diagnosing a Hot Partition Issue in a GSI

You created a GSI with Status as the partition key and CreatedAt as the sort key. Your application experiences throttling and slow queries. The Status attribute only has three possible values: 'Pending', 'Completed', and 'Cancelled'. What is the most likely cause of the problem?

AThe low cardinality of the partition key 'Status' causes hot partitions due to uneven traffic distribution.
BThe sort key 'CreatedAt' is not indexed properly, causing slow queries.
CThe GSI is missing a projection of the 'Status' attribute.
DThe table's primary key conflicts with the GSI partition key.
Attempts:
2 left
💡 Hint

Consider how the number of unique partition key values affects traffic distribution.