Question

Difficulty: EasyData Store Operations with Amazon DynamoDB

An online learning platform stores student registration records in an Amazon DynamoDB table. The table uses StudentID as the partition key. A new feature requires retrieving a list of all students who registered in the last 3030 days. Registration dates are stored in an attribute named RegistrationDate. Which approach should the developer use to retrieve these records with the lowest latency and minimal Read Capacity Unit (RCU) consumption?

  1. Create a Global Secondary Index (GSI) with RegistrationDate as the partition key, and perform a Query operation on the GSI.Answer
  2. B
    Perform a Scan operation on the base table using a FilterExpression on RegistrationDate.
  3. C
    Perform a Scan operation on the base table, and double the provisioned Read Capacity Units (RCUs) to prevent ProvisionedThroughputExceededException errors.
  4. D
    Initialize the AWS SDK DynamoDB client using hardcoded AWS access keys in the application code, and perform a Scan operation.

Answer

Create a Global Secondary Index (GSI) with RegistrationDate as the partition key, and perform a Query operation on the GSI.
Creating a Global Secondary Index (GSI) with RegistrationDate as the partition key enables the application to use the Query operation. A Query operation targets only the items within the specified partition key value, significantly reducing latency and RCU consumption compared to scanning the entire table.

Step-by-Step Solution

1
Analyze the table key schema and query requirements.
The base table only supports querying by StudentID. Because the query needs to look up records by RegistrationDate (a non-key attribute), a direct Query operation on the base table is not possible.
DynamoDB Query operations require specifying the partition key of the index or table being queried.
2
Compare Query and Scan operations for data retrieval.
A Scan operation reads every item in the table, whereas a Query searches only items matching the partition key. A Scan is highly inefficient for large datasets.
To minimize latency and RCU consumption, the developer must find a way to perform a Query instead of a Scan.
3
Design a secondary index to enable the Query operation.
Create a Global Secondary Index (GSI) using RegistrationDate as the partition key. Perform a Query operation against this GSI to retrieve the records.
A GSI allows queries on alternate keys, returning only the desired records and consuming minimal RCUs.

Key Concept

Using Global Secondary Indexes (GSIs) and the Query operation instead of a Scan operation to retrieve data efficiently based on non-key attributes.
Rate this question