Question

Difficulty: MediumData Store Operations with Amazon DynamoDB

A developer is building a digital streaming application where video metadata is stored in an Amazon DynamoDB table. The table's partition key is `VideoID` and the sort key is `UploadTimestamp`. The application frequently retrieves a list of videos within a specific category, sorted by their upload date, where the rating is greater than 4.04.0. The category attribute is not part of the primary key. Which two actions should the developer take to retrieve this data efficiently while minimizing the consumption of Read Capacity Units (RCUs)?

  1. Create a Global Secondary Index (GSI) with `Category` as the partition key and `UploadTimestamp` as the sort key, projecting only the required video metadata attributes.Answer
  2. Perform a `Query` operation on the Global Secondary Index using the `Category` value in the key condition expression and a filter expression for the rating.Answer
  3. C
    Perform a `Scan` operation on the base table with a filter expression containing both the `Category` and rating attributes.
  4. D
    Increase the provisioned Read Capacity Units (RCUs) on the base table and run parallel `Scan` operations to retrieve the matching items.
  5. E
    Initialize the DynamoDB service client in the application code by hardcoding static AWS access keys to reduce credentials lookup latency.

Answer

Create a Global Secondary Index (GSI) with the category as the partition key and the upload timestamp as the sort key, projecting only the required attributes. Then, perform a Query operation on the GSI using the category value in the key condition expression and a filter expression for the rating.
To search and sort by attributes that are not the base table's primary key, a Global Secondary Index (GSI) must be defined with the search attribute as the partition key and the sorting attribute as the sort key. Performing a Query operation on this GSI is highly efficient because it reads only the subset of items under the specified partition key. Projecting only necessary attributes further minimizes RCU footprint.

Step-by-Step Solution

1
Analyze the access pattern
The application needs to search by an attribute (`Category`) that is not the partition key of the base table, and sort by `UploadTimestamp`.
DynamoDB base tables can only be queried directly by their partition key. Searching by other attributes requires either a Scan or a Secondary Index.
2
Design the index structure
Create a Global Secondary Index (GSI) with `Category` as the partition key and `UploadTimestamp` as the sort key.
This allows query operations to target specific categories and obtain sorted results by timestamp without scanning the table. Projecting only required attributes reduces RCU consumption.
3
Select the API operation
Use the Query API on the GSI with a KeyConditionExpression for the category and a FilterExpression for the rating.
Query operations are much more efficient than Scan operations because they only read items that share the partition key value.

Key Concept

Using Global Secondary Indexes (GSIs) and Query operations to optimize data retrieval and minimize Read Capacity Unit consumption.
Estimated Time:1m 30s
Rate this question