Bird
Raised Fist0
DynamoDBquery~20 mins

Identifying access patterns first in DynamoDB - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Access Pattern Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
Query Result for Single Partition Key Access

You have a DynamoDB table with PartitionKey as the primary key. You run this query to get all items with PartitionKey = 'User#123'. What will be the output?

DynamoDB
SELECT * FROM Table WHERE PartitionKey = 'User#123';
AOnly one item with PartitionKey 'User#123' will be returned, even if multiple exist.
BAll items with PartitionKey 'User#123' will be returned.
CQuery will fail because PartitionKey must be unique.
DNo items will be returned unless SortKey is specified.
Attempts:
2 left
💡 Hint

Think about how DynamoDB handles queries on partition keys.

🧠 Conceptual
intermediate
2:00remaining
Choosing Partition Key for Efficient Access

You want to design a DynamoDB table to store orders. You expect frequent queries by CustomerID and occasional queries by OrderDate. Which is the best choice for the partition key to optimize access patterns?

AUse <code>OrderDate</code> as the partition key.
BUse a composite key with <code>OrderDate</code> as partition key and <code>CustomerID</code> as sort key.
CUse a random UUID as the partition key.
DUse <code>CustomerID</code> as the partition key.
Attempts:
2 left
💡 Hint

Think about which attribute is used most often in queries.

📝 Syntax
advanced
2:00remaining
Identify the Correct DynamoDB Query Syntax

Which of the following DynamoDB query expressions correctly retrieves items with PartitionKey = 'User#456' and SortKey starting with 'Order#'?

DynamoDB
Assume table has PartitionKey and SortKey attributes.
AQueryInput={ TableName: 'Table', KeyConditionExpression: 'PartitionKey = :pk and begins_with(SortKey, :sk)', ExpressionAttributeValues: { ':pk': 'User#456', ':sk': 'Order#' } }
BQueryInput={ TableName: 'Table', KeyConditionExpression: 'PartitionKey = :pk and SortKey = :sk', ExpressionAttributeValues: { ':pk': 'User#456', ':sk': 'Order#' } }
CQueryInput={ TableName: 'Table', FilterExpression: 'begins_with(SortKey, :sk)', ExpressionAttributeValues: { ':sk': 'Order#' } }
DQueryInput={ TableName: 'Table', KeyConditionExpression: 'PartitionKey = :pk or begins_with(SortKey, :sk)', ExpressionAttributeValues: { ':pk': 'User#456', ':sk': 'Order#' } }
Attempts:
2 left
💡 Hint

Remember that KeyConditionExpression must use AND and can use begins_with for sort keys.

❓ optimization
advanced
2:00remaining
Optimizing Access Patterns with Secondary Indexes

You have a DynamoDB table with primary key CustomerID and OrderID. You want to efficiently query orders by OrderStatus. What is the best way to optimize this access pattern?

AUse a Scan operation filtering by <code>OrderStatus</code>.
BAdd <code>OrderStatus</code> as a sort key to the primary key.
CCreate a Global Secondary Index (GSI) with <code>OrderStatus</code> as partition key.
DStore <code>OrderStatus</code> in a separate table.
Attempts:
2 left
💡 Hint

Think about how to query efficiently by an attribute not in the primary key.

🔧 Debug
expert
3:00remaining
Debugging a Query Returning No Results

You run this DynamoDB query to get all orders for CustomerID = 'Cust#789' with OrderDate after '2023-01-01'. The query returns no results, but you know matching items exist. What is the likely cause?

QueryInput={
  TableName: 'Orders',
  KeyConditionExpression: 'CustomerID = :cid and OrderDate > :date',
  ExpressionAttributeValues: { ':cid': 'Cust#789', ':date': '2023-01-01' }
}
AOrderDate is not part of the primary key or sort key, so it cannot be used in KeyConditionExpression.
BThe date format '2023-01-01' is invalid for DynamoDB queries.
CCustomerID value is case-sensitive and 'Cust#789' does not match stored keys.
DExpressionAttributeValues keys must be prefixed with a hash (#) symbol.
Attempts:
2 left
💡 Hint

Check which attributes can be used in KeyConditionExpression.

Practice

(1/5)
1. Why is it important to identify access patterns before designing a DynamoDB table?
easy
A. Because it tells how many users will use the app.
B. Because it helps to choose the right programming language for the app.
C. Because access patterns determine the keys and indexes needed for efficient queries.
D. Because it decides the color scheme of the app interface.

Solution

  1. Step 1: Understand the role of access patterns

    Access patterns describe how the app will retrieve data, which guides table design.
  2. Step 2: Connect access patterns to keys and indexes

    Keys and indexes in DynamoDB are chosen based on these patterns to make queries fast and efficient.
  3. Final Answer:

    Because access patterns determine the keys and indexes needed for efficient queries. -> Option C
  4. Quick Check:

    Access patterns = keys/indexes choice [OK]
Hint: Access patterns guide key/index design for fast queries [OK]
Common Mistakes:
  • Thinking access patterns affect UI design
  • Confusing access patterns with user count
  • Believing access patterns decide programming language
2. Which of the following is the correct way to describe an access pattern in DynamoDB?
easy
A. A list of all table columns.
B. A query that the app will run to get data.
C. The number of items in the table.
D. The size of the database backup.

Solution

  1. Step 1: Define what an access pattern is

    An access pattern is a way the app queries or retrieves data from the database.
  2. Step 2: Match the options to this definition

    Only "A query that the app will run to get data." describes a query the app will run, which fits the access pattern meaning.
  3. Final Answer:

    A query that the app will run to get data. -> Option B
  4. Quick Check:

    Access pattern = app query [OK]
Hint: Access pattern means how app queries data [OK]
Common Mistakes:
  • Confusing access pattern with table schema
  • Thinking access pattern is about data size
  • Mixing access pattern with backup info
3. Given an app needs to get user orders by user ID and order date, which access pattern should be planned first?
medium
A. Query orders by user ID and sort by order date.
B. Scan all orders and filter by user ID.
C. Get orders by order date only.
D. Query orders by product ID.

Solution

  1. Step 1: Identify the required data retrieval

    The app needs orders filtered by user ID and sorted by order date.
  2. Step 2: Choose the access pattern matching this need

    Querying by user ID and sorting by order date matches the requirement and is efficient.
  3. Final Answer:

    Query orders by user ID and sort by order date. -> Option A
  4. Quick Check:

    Access pattern = query by user ID + order date [OK]
Hint: Match access pattern to app's data retrieval need [OK]
Common Mistakes:
  • Using scan instead of query causes slow performance
  • Ignoring sorting by order date
  • Querying by unrelated keys like product ID
4. You designed a DynamoDB table without identifying access patterns first. Your app queries are slow. What is the likely cause?
medium
A. The table keys and indexes do not support the app's query needs.
B. The app has too many users.
C. The table has too many columns.
D. The app is using the wrong programming language.

Solution

  1. Step 1: Understand the impact of missing access pattern planning

    Without access patterns, keys and indexes may not match query needs, causing slow queries.
  2. Step 2: Eliminate unrelated causes

    User count, column number, or programming language do not directly cause slow DynamoDB queries.
  3. Final Answer:

    The table keys and indexes do not support the app's query needs. -> Option A
  4. Quick Check:

    Missing access patterns = wrong keys/indexes = slow queries [OK]
Hint: Slow queries often mean keys/indexes mismatch access patterns [OK]
Common Mistakes:
  • Blaming app user count for query speed
  • Thinking table columns affect query speed directly
  • Assuming programming language affects DynamoDB speed
5. An app needs to retrieve customer profiles by email and also list all customers in a city. How should you identify access patterns to design the DynamoDB table?
hard
A. Store all customers in one table without keys and scan for queries.
B. Create separate tables for email and city queries.
C. Use email as the only key and ignore city queries.
D. Plan one access pattern to query by email and another to query by city using a secondary index.

Solution

  1. Step 1: Identify the two access patterns

    The app needs to get customers by email and also list customers by city.
  2. Step 2: Design keys and indexes accordingly

    Use email as the primary key and create a secondary index on city to support both queries efficiently.
  3. Final Answer:

    Plan one access pattern to query by email and another to query by city using a secondary index. -> Option D
  4. Quick Check:

    Multiple access patterns = primary key + secondary index [OK]
Hint: Use secondary indexes for multiple access patterns [OK]
Common Mistakes:
  • Ignoring secondary indexes for city queries
  • Using scans instead of queries
  • Creating separate tables unnecessarily
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard