Soru

Zorluk: OrtaData Store Operations with Amazon DynamoDB

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.)

  1. Create a Global Secondary Index (GSI) with AuthorCategory as the partition key and PublishDate as the sort key.Cevap
  2. Create a Global Secondary Index (GSI) with AuthorCategory as the partition key and ViewCount as the sort key.Cevap
  3. C
    Perform a Scan operation on the base table with a FilterExpression on AuthorCategory and sort the results in the application logic.
  4. D
    Create 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.
  5. E
    Increase the base table's provisioned Read Capacity Units (RCUs) to handle full table scans for each query, preventing ProvisionedThroughputExceededException errors.

Cevap

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.

Adım Adım Çözüm

1
Analyze the access pattern requirements.
The application needs to query articles by AuthorCategory (which is not the partition key of the base table, ArticleId) and sort them by PublishDate and ViewCount.
Understanding the required partition and sort keys for the queries is necessary to design the correct index structure.
2
Determine the appropriate index type.
Since the partition key of the queries (AuthorCategory) is different from the base table's partition key (ArticleId), Global Secondary Indexes (GSIs) must be used. Local Secondary Indexes (LSIs) cannot be used because they require the same partition key as the base table.
Choosing GSIs over LSIs ensures that queries can filter by a non-key attribute as the partition key.
3
Define the GSIs.
Create one GSI with AuthorCategory as the partition key and PublishDate as the sort key, and a second GSI with AuthorCategory as the partition key and ViewCount as the sort key.
This setup allows Query operations to return sorted results directly from the index, minimizing latency and Read Capacity Unit (RCU) consumption.

Anahtar Kavram

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.
Bu soruyu puanla