Soru

Zorluk: OrtaData Store Operations with Amazon DynamoDB

A developer is building a user management module for a web application. The user data is stored in an Amazon DynamoDB table where the partition key is UserIDUserID. The developer needs to support two new query patterns: retrieving all users in a specific city (CityCity) sorted by their registration date (RegistrationDateRegistrationDate), and retrieving a user's details by their unique email address (EmailEmail). The solution must optimize read latency and minimize consumed capacity. Which two actions should the developer take to meet these requirements?

  1. Create a global secondary index (GSI) with CityCity as the partition key and RegistrationDateRegistrationDate as the sort key.Cevap
  2. Create a global secondary index (GSI) with EmailEmail as the partition key.Cevap
  3. C
    Create a local secondary index (LSI) with EmailEmail as the sort key.
  4. D
    Perform a Scan operation on the base table using a FilterExpression on the EmailEmail attribute.
  5. E
    Perform a Scan operation on the base table filtering by the CityCity attribute, and then sort the results in the application code.

Cevap

Create a global secondary index (GSI) with City as the partition key and RegistrationDate as the sort key, and create a GSI with Email as the partition key.
To support queries on attributes other than the base table partition key without executing full scans, the developer must use Global Secondary Indexes (GSIs). A GSI with City as the partition key and RegistrationDate as the sort key directly satisfies the city-based lookup and sorts the data efficiently. A GSI with Email as the partition key allows lookups by email without needing the UserID.

Adım Adım Çözüm

1
Analyze the access pattern for retrieving users by City sorted by RegistrationDate.
Identify that because City is not the base table partition key, a Global Secondary Index (GSI) must be created with City as the partition key and RegistrationDate as the sort key to allow sorted queries.
GSIs support partition and sort keys that differ from the base table, and DynamoDB automatically sorts index items by the sort key within each partition.
2
Analyze the access pattern for retrieving user details by Email.
Identify that Email is a unique attribute but not the base table partition key. Creating a GSI with Email as the partition key allows direct, low-latency lookups.
A Local Secondary Index (LSI) cannot be used because querying it still requires the base table partition key (UserID), which is not available in an email-only lookup.
3
Evaluate and reject Scan operations.
Discard scan-based solutions since they read the entire table, leading to linear cost scaling and high latency.
Using Query operations on GSIs is the most efficient and cost-effective approach for these access patterns.

Anahtar Kavram

Using Global Secondary Indexes (GSIs) to support query patterns that use partition keys different from the base table primary key, avoiding expensive Scan operations.
Bu soruyu puanla