A partition key is the primary attribute used to distribute data across partitions in DynamoDB. It determines where the data is stored and helps in fast data retrieval.
Click to reveal answer
beginner
What role does the sort key play in DynamoDB?
The sort key allows DynamoDB to store multiple items with the same partition key but different sort keys. It helps organize and query data within the same partition.
Click to reveal answer
intermediate
How do partition key and sort key work together in DynamoDB?
Together, the partition key and sort key form a composite primary key. The partition key decides the partition, and the sort key orders items within that partition for efficient queries.
Click to reveal answer
intermediate
Why is choosing a good partition key important?
A good partition key evenly distributes data across partitions, preventing hotspots and ensuring fast, scalable performance.
Click to reveal answer
beginner
Can a DynamoDB table have only a partition key without a sort key?
Yes, a DynamoDB table can have just a partition key as its primary key. This means each item must have a unique partition key value.
Click to reveal answer
What does the partition key in DynamoDB determine?
AThe order of items within a partition
BThe physical location of data storage
CThe size of the database
DThe encryption method
✗ Incorrect
The partition key determines the physical partition where data is stored, enabling fast access.
What is the purpose of a sort key in DynamoDB?
ATo sort items within the same partition key
BTo distribute data across partitions
CTo encrypt data
DTo backup data
✗ Incorrect
The sort key organizes items with the same partition key, allowing efficient queries within that partition.
Can a DynamoDB table have a composite primary key?
AComposite keys are not supported
BNo, only partition key is allowed
COnly sort key is allowed
DYes, partition key and sort key together
✗ Incorrect
A composite primary key consists of a partition key and a sort key.
What happens if the partition key is not well chosen?
AData will be encrypted automatically
BSort key will be ignored
CData may be unevenly distributed causing slow performance
DThe database size will increase
✗ Incorrect
Poor partition key choice can cause hotspots, slowing down the database.
Is it mandatory to have a sort key in DynamoDB?
ANo, tables can have only a partition key
BYes, always required
COnly for encrypted tables
DOnly for global tables
✗ Incorrect
DynamoDB tables can have just a partition key without a sort key.
Explain how partition key and sort key work together in DynamoDB to organize data.
Think about how data is grouped and sorted inside the database.
You got /4 concepts.
Describe why choosing a good partition key is important for DynamoDB performance.
Imagine how traffic flows on roads and how congestion slows things down.
You got /4 concepts.
Practice
(1/5)
1.
What is the main role of a partition key in AWS DynamoDB?
easy
A. It groups data into partitions for efficient storage and retrieval.
B. It sorts data within a partition in ascending order.
C. It encrypts the data before storing it.
D. It defines the backup schedule for the table.
Solution
Step 1: Understand partition key purpose
The partition key is used to group data into partitions, which helps DynamoDB distribute and store data efficiently.
Step 2: Differentiate from sort key
The sort key orders data inside each partition but does not group data across partitions.
Final Answer:
It groups data into partitions for efficient storage and retrieval. -> Option A
Quick Check:
Partition key = groups data [OK]
Hint: Partition key groups data, sort key orders it inside partitions [OK]
Common Mistakes:
Confusing partition key with sort key
Thinking partition key sorts data
Assuming partition key controls backups
2.
Which of the following is the correct way to define a DynamoDB table with a partition key named UserId and a sort key named OrderDate in AWS CLI?
A. Attribute names cannot contain uppercase letters.
B. Attribute types must be different for partition and sort keys.
C. KeyType values must both be HASH for composite keys.
D. Partition key and sort key are swapped; OrderId should be HASH, OrderDate RANGE.
Solution
Step 1: Check key roles
Partition key must be HASH and sort key must be RANGE in key schema.
Step 2: Identify swapped keys
OrderId should be the partition key (HASH), but here OrderDate is set as HASH and OrderId as RANGE, which is incorrect.
Final Answer:
Partition key and sort key are swapped; OrderId should be HASH, OrderDate RANGE. -> Option D
Quick Check:
Partition = HASH, Sort = RANGE order matters [OK]
Hint: Partition key always HASH, sort key always RANGE [OK]
Common Mistakes:
Swapping HASH and RANGE key types
Assuming attribute types must differ
Thinking uppercase letters are invalid
5.
You want to design a DynamoDB table to store user activity logs. Each user can have multiple logs per day. Which key design is best to efficiently query all logs for a user on a specific day?
hard
A. Partition key: UserId, Sort key: ActivityDateTime
B. Partition key: ActivityDateTime, Sort key: UserId
C. Partition key: UserId_ActivityDate, Sort key: ActivityTime
D. Partition key: ActivityType, Sort key: UserId
Solution
Step 1: Understand query needs
You want to query logs by user and by specific day efficiently.
Step 2: Design keys for efficient queries
Combining UserId and ActivityDate as partition key groups logs per user per day. Using ActivityTime as sort key orders logs within that day.
Final Answer:
Partition key: UserId_ActivityDate, Sort key: ActivityTime -> Option C
Quick Check:
Composite partition key groups user-day logs [OK]
Hint: Combine user and date in partition key for day queries [OK]
Common Mistakes:
Using ActivityDateTime as partition key alone
Swapping partition and sort keys
Not combining keys to match query pattern
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.