Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the main purpose of a sort key in DynamoDB?
A sort key helps organize and order items within the same partition key, allowing efficient querying and sorting of related data.
Click to reveal answer
beginner
How does a sort key differ from a partition key in DynamoDB?
The partition key determines the partition where data is stored, while the sort key orders items within that partition.
Click to reveal answer
beginner
Can a DynamoDB table have a sort key without a partition key?
No, a sort key must always be used together with a partition key to form a composite primary key.
Click to reveal answer
intermediate
How does using a sort key improve query flexibility in DynamoDB?
It allows queries to retrieve items with the same partition key but filtered or sorted by the sort key values.
Click to reveal answer
beginner
Give an example of a real-life scenario where a sort key is useful.
In an online store, the partition key could be the customer ID, and the sort key could be the order date to list all orders by date for each customer.
Click to reveal answer
What does the sort key in DynamoDB help you do?
ADetermine the partition where data is stored
BOrder items within the same partition key
CEncrypt data in the table
DCreate indexes automatically
✗ Incorrect
The sort key orders items within the same partition key, enabling sorted queries.
Can a DynamoDB table have only a sort key without a partition key?
ANo, a partition key is required
BYes, always
COnly if the table is small
DOnly for global secondary indexes
✗ Incorrect
A partition key is always required; the sort key complements it to form a composite key.
Which of these is a valid use of a sort key?
ADefining the table's read capacity
BEncrypting data at rest
CBacking up the database
DStoring multiple orders by date for a single customer
✗ Incorrect
Sort keys help organize multiple related items, like orders by date for one customer.
How does a sort key affect query results?
AIt filters and sorts items within a partition
BIt changes the table's schema
CIt increases storage size
DIt deletes duplicate items
✗ Incorrect
Sort keys allow filtering and sorting of items sharing the same partition key.
What is a composite primary key in DynamoDB?
AA key that stores JSON data
BA key that encrypts data
CA key made of partition key and sort key
DA key used only for backups
✗ Incorrect
A composite primary key combines partition key and sort key to uniquely identify items.
Explain the purpose of a sort key in DynamoDB and how it works with the partition key.
Think about how you find and order related items in a folder.
You got /4 concepts.
Describe a real-world example where using a sort key would be helpful in a DynamoDB table.
Consider something like customers and their orders or messages sorted by date.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of a sort key in a DynamoDB table?
easy
A. To store large binary data efficiently
B. To uniquely identify each item across all partitions
C. To organize and order items within the same partition key
D. To encrypt data at rest automatically
Solution
Step 1: Understand partition and sort keys roles
The partition key groups items, and the sort key orders items within that group.
Step 2: Identify the sort key's purpose
The sort key organizes related items so they can be retrieved in order and filtered efficiently.
Final Answer:
To organize and order items within the same partition key -> Option C
Quick Check:
Sort key = Organize items in partition [OK]
Hint: Sort key orders items inside a partition [OK]
Common Mistakes:
Confusing sort key with partition key uniqueness
Thinking sort key encrypts data
Assuming sort key stores large binary data
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 Timestamp using AWS CLI?
aws dynamodb create-table --table-name MyTable --attribute-definitions AttributeName=UserID,AttributeType=S AttributeName=Timestamp,AttributeType=N --key-schema AttributeName=UserID,KeyType=HASH AttributeName=Timestamp,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 uses UserID as HASH and Timestamp as RANGE, which is correct.
B. Missing partition key equality condition in key-condition-expression
C. Incorrect data type for expression attribute value
D. Missing sort key in attribute definitions
Solution
Step 1: Recall query key condition requirements
DynamoDB query requires partition key equality condition in key-condition-expression.
Step 2: Identify error cause
Query uses only 'OrderID > :oid' without partition key equality, causing error.
Final Answer:
Missing partition key equality condition in key-condition-expression -> Option B
Quick Check:
Partition key equality is mandatory in query [OK]
Hint: Query must have partition key equality condition [OK]
Common Mistakes:
Using range operators on partition key
Omitting partition key in query condition
Confusing query with scan operation
5. You want to model a one-to-many relationship where each CustomerID can have multiple Invoices sorted by InvoiceDate. Which DynamoDB table design best uses the sort key to achieve this?
hard
A. Partition key: CustomerID, Sort key: InvoiceDate
B. Partition key: InvoiceDate, Sort key: CustomerID
C. Partition key: CustomerID only, no sort key
D. Partition key: InvoiceID, Sort key: InvoiceDate
Solution
Step 1: Understand one-to-many modeling in DynamoDB
Use partition key for the 'one' side and sort key to order the 'many' items.
Step 2: Apply to CustomerID and Invoices
CustomerID as partition key groups invoices; InvoiceDate as sort key orders them.
Final Answer:
Partition key: CustomerID, Sort key: InvoiceDate -> Option A
Quick Check:
Sort key models one-to-many order [OK]
Hint: Partition key = one side, sort key = many side order [OK]