Question

Difficulty: MediumData Store Operations with Amazon DynamoDB

A developer is building a personal finance application that tracks user transactions. The transactions are stored in an Amazon DynamoDB table with AccountID as the partition key and TransactionTimestamp as the sort key. A dashboard needs to display all transactions for a specific account that are categorized as 'Entertainment' to analyze spending habits. The developer wants to retrieve this data with the lowest latency and minimal Read Capacity Unit (RCU) consumption. Which two strategies should the developer implement to meet these requirements? (Choose two.)

  1. Create a Global Secondary Index (GSI) with AccountID as the partition key and Category as the sort key, then use the Query API on the GSI.Answer
  2. Configure the GSI projection to include only the required attributes needed for the dashboard, such as TransactionTimestamp and Amount.Answer
  3. C
    Perform a Scan operation on the base table using a FilterExpression to return only the transactions where Category is equal to 'Entertainment'.
  4. D
    Perform a parallel Scan operation across the table using segments to speed up the retrieval of the 'Entertainment' transactions.
  5. E
    Configure the AWS SDK client inside the application code with hardcoded IAM User access keys to bypass IAM role assumption latency.

Answer

To optimize the data retrieval, the developer should create a Global Secondary Index (GSI) with AccountID as the partition key and Category as the sort key, querying this index directly. Furthermore, the GSI should project only the required attributes needed for the dashboard instead of all attributes to minimize RCU consumption.
To achieve the lowest latency and minimal RCU consumption, the developer should create a Global Secondary Index (GSI) with AccountID as the partition key and Category as the sort key. This allows the application to run targeted Query operations directly on the index instead of scanning. To optimize performance and cost further, the GSI projection should be limited to only the required attributes needed for the dashboard, which minimizes the amount of data transferred and read capacity consumed.

Step-by-Step Solution

1
Evaluate the query patterns on the base table.
The base table's primary key structure (AccountID + TransactionTimestamp) does not allow efficient filtering by Category.
Querying by a non-key attribute like Category on the base table would require scanning the entire table or partition, which is inefficient.
2
Design a secondary index to support the query pattern.
A Global Secondary Index (GSI) is created with AccountID as the partition key and Category as the sort key.
This allows the application to perform high-performance Query operations directly on the specific partition and sort key.
3
Optimize the index projection settings.
A projection type of INCLUDE or KEYS_ONLY is selected to only project the attributes needed by the dashboard (e.g., TransactionTimestamp and Amount).
Projecting fewer attributes keeps the GSI size small and minimizes RCU usage during queries.

Key Concept

Optimizing DynamoDB queries and read throughput using Global Secondary Indexes (GSIs) and projection attributes.
Rate this question