A developer is designing a content management system (CMS) that stores article metadata in an Amazon DynamoDB table. The table's partition key is ArticleId. The developer needs to support two new access patterns:
1. Retrieve all articles belonging to a specific AuthorCategory (such as 'Technology' or 'Finance') sorted by their PublishDate.
2. Retrieve all articles belonging to a specific AuthorCategory sorted by their ViewCount.
Which two solutions should the developer implement to meet these requirements with the lowest latency and optimal read capacity consumption? (Select TWO.)
- Create a Global Secondary Index (GSI) with AuthorCategory as the partition key and PublishDate as the sort key.Answer
- Create a Global Secondary Index (GSI) with AuthorCategory as the partition key and ViewCount as the sort key.Answer
- CPerform a Scan operation on the base table with a FilterExpression on AuthorCategory and sort the results in the application logic.
- DCreate a Local Secondary Index (LSI) with ArticleId as the partition key and PublishDate as the sort key, then use a Scan operation to filter results by AuthorCategory.
- EIncrease the base table's provisioned Read Capacity Units (RCUs) to handle full table scans for each query, preventing ProvisionedThroughputExceededException errors.
Answer
Create a Global Secondary Index (GSI) with AuthorCategory as the partition key and PublishDate as the sort key, and create another Global Secondary Index (GSI) with AuthorCategory as the partition key and ViewCount as the sort key.
To support queries with a partition key (AuthorCategory) that differs from the base table's partition key (ArticleId), Global Secondary Indexes (GSIs) must be created. The first GSI uses AuthorCategory as the partition key and PublishDate as the sort key, enabling sorted queries by publication date. The second GSI uses AuthorCategory as the partition key and ViewCount as the sort key, enabling sorted queries by view count. Using Query operations on these GSIs ensures low latency and efficient capacity consumption.
Step-by-Step Solution
Key Concept
Using Global Secondary Indexes (GSIs) in Amazon DynamoDB to support query patterns with partition keys different from the base table's partition key, avoiding inefficient Scan operations.