Question

Difficulty: MediumData Store Operations with Amazon DynamoDB

A developer is designing a subscription management system using Amazon DynamoDB. The table stores customer subscriptions with `SubscriptionID` as the partition key. Over 99%99\% of the subscriptions are in the "Active" status, while less than 1%1\% are in the "PendingCancellation" status. The developer needs to build a dashboard that lists all subscriptions in the "PendingCancellation" status. Which two actions should the developer take to retrieve this data in the most cost-effective and performant manner?

  1. Create a Global Secondary Index (GSI) with a sparse attribute (such as `CancellationDate`, which is only populated on subscriptions with a pending cancellation status) as the partition key.Answer
  2. Use the `Query` API operation to retrieve the subscriptions from the global secondary index.Answer
  3. C
    Use the `Scan` API operation with a FilterExpression to retrieve all subscriptions from the main table where `SubscriptionStatus` equals `PendingCancellation`.
  4. D
    Initialize the AWS SDK client inside the application code by hardcoding the access keys of an IAM user with read access to the DynamoDB table.
  5. E
    Increase the provisioned Read Capacity Units (RCUs) of the main table to resolve read throttling, assuming the performance issues are due to overall table capacity limits rather than the scanning of inactive partitions.

Answer

Create a Global Secondary Index (GSI) with a sparse attribute as the partition key and use the Query API operation to retrieve the subscriptions from the index.
The correct approach is to create a Global Secondary Index (GSI) with a sparse attribute (like a cancellation date that is only present for subscriptions pending cancellation) as the partition key, and then use the Query API on this index. In DynamoDB, an item is only written to a GSI if the GSI's partition key attribute is present in that item. Since only 1%1\% of subscriptions have this attribute, the index size remains very small, saving storage and write costs. Querying this GSI directly retrieves only the matching items, making the operation extremely efficient.

Step-by-Step Solution

1
Analyze the distribution of data and access patterns.
Since only less than 1%1\% of the data is in the target 'PendingCancellation' status, performing queries or scans on the main table is inefficient.
Scanning the main table requires reading all items, which is expensive and slow.
2
Design a sparse index strategy to filter data at the database level.
Creating a Global Secondary Index (GSI) with a partition key attribute that is only populated for the target status (a sparse attribute) ensures that the GSI only contains the relevant items.
This avoids indexing the 99%99\% active subscriptions, reducing GSI storage and write costs.
3
Select the correct API operation to retrieve the indexed items.
Using the Query API operation on the GSI's partition key retrieves only the target items directly.
Query operations are highly efficient and only consume Read Capacity Units (RCUs) proportional to the returned items.

Key Concept

Optimizing DynamoDB data retrieval for sparse attributes using Global Secondary Indexes (GSIs) and the Query API rather than Table Scans.
Rate this question