Soru

Zorluk: ZorData Store Operations with Amazon DynamoDB

An online education company uses an Amazon DynamoDB table named `CourseProgress` to track student progress. The table uses `StudentID` as the partition key and `CourseID` as the sort key. Over time, students accumulate thousands of records, but only a small fraction of these courses are fully completed. A dashboard frequently retrieves only the completed courses for a specific student. As the volume of in-progress course records grows, the dashboard queries become slower and consume a significant number of Read Capacity Units (RCUs). Which database design pattern or operation should a developer implement to retrieve the completed courses in the most cost-effective and performant manner?

  1. Create a Global Secondary Index (GSI) with `StudentID` as the partition key and a new attribute `CompletedDate` as the sort key. Only populate the `CompletedDate` attribute in the base table when a course is completed, and query the GSI to retrieve the records.Cevap
  2. B
    Perform a Scan operation on the base table with a FilterExpression that filters the results where the partition key matches the target student and the progress status is 'Completed'.
  3. C
    Query the base table using the `StudentID` partition key with a FilterExpression for completed courses, and increase the table's provisioned Read Capacity Units (RCUs) to prevent ProvisionedThroughputExceededException errors during peak times.
  4. D
    Implement parallel Scan operations using the AWS SDK, initializing the client with hardcoded IAM credentials that have read-only access to speed up the data retrieval process.

Cevap

Create a Global Secondary Index (GSI) with StudentID as the partition key and a new attribute CompletedDate as the sort key. Only populate the CompletedDate attribute in the base table when a course is completed, and query the GSI to retrieve the records.
Creating a Global Secondary Index (GSI) with the student identifier as the partition key and a completion date as the sort key, and only populating this completion date when the course is finished, creates a sparse index. In Amazon DynamoDB, items that do not contain the GSI's sort key attribute are not indexed. As a result, the GSI only contains records for completed courses, allowing the application to perform highly efficient Queries against the GSI that consume Read Capacity Units (RCUs) only for the completed courses, rather than reading and filtering all in-progress records.

Adım Adım Çözüm

1
Analyze the table structure and access patterns.
The table has StudentID as partition key and CourseID as sort key. The requirement is to fetch only completed courses for a specific student.
Understanding the base schema helps identify why standard queries become inefficient when filtering on non-key attributes.
2
Evaluate the impact of DynamoDB FilterExpressions.
A FilterExpression on a Query or Scan does not reduce RCU consumption because DynamoDB reads the items first and then filters them.
This explains why querying the base table and filtering is not cost-effective.
3
Design a sparse Global Secondary Index (GSI).
Create a GSI with StudentID as partition key and CompletedDate as sort key. Only write CompletedDate when a course is finished.
Since DynamoDB only indexes items where the GSI keys are present, this creates a sparse index containing only completed courses, optimizing both query performance and cost.

Anahtar Kavram

DynamoDB Sparse Indexes and Query Optimization
Bu soruyu puanla