Soru

Zorluk: ZorData Store Operations with Amazon DynamoDB

A developer is building a backend for a conference ticketing application. The ticketing data is stored in an Amazon DynamoDB table with `BookingId` (a unique UUID) as the partition key and no sort key. The developer needs to implement two new requirements:

1. Retrieve all bookings for a specific `EventId` sorted by `BookingTimestamp` in descending order.
2. Process bulk attendee registrations where groups of up to 2020 bookings must be written or updated simultaneously. If any booking in the group fails (such as due to a sold-out status or validation error), none of the bookings in the group should be applied.

Which TWO actions should the developer take to meet these requirements efficiently?

  1. Create a Global Secondary Index (GSI) with `EventId` as the partition key and `BookingTimestamp` as the sort key, and use the `Query` API on the GSI.Cevap
  2. Use the `TransactWriteItems` API to execute the bulk registrations as a single transaction.Cevap
  3. C
    Use the `Scan` API with a `FilterExpression` on the base table to retrieve bookings for a specific `EventId` and sort them in application code.
  4. D
    Increase the provisioned Write Capacity Units (WCUs) on the base table to automatically resolve failures caused by transactional validation checks.
  5. E
    Initialize the AWS SDK DynamoDB client inside the application code using hardcoded AWS access key and secret access key credentials for authentication.

Cevap

Create a Global Secondary Index (GSI) with EventId as the partition key and BookingTimestamp as the sort key, and use the Query API on the GSI. Also use the TransactWriteItems API to execute the bulk registrations as a single transaction.
Creating a Global Secondary Index with EventId as the partition key and BookingTimestamp as the sort key allows the application to perform efficient queries and receive sorted results. Utilizing the TransactWriteItems API ensures that the bulk updates are performed atomically, preventing partial updates where some registrations succeed and others fail.

Adım Adım Çözüm

1
Evaluate query and sorting needs for non-key attributes.
Identified that retrieving sorted bookings by event requires a secondary index because the base table partition key is BookingId.
DynamoDB does not support direct sorting on non-key attributes without a sort key, and query operations are restricted to key attributes.
2
Select index type and key attributes.
Determined that a Global Secondary Index (GSI) with EventId as the partition key and BookingTimestamp as the sort key is required.
A GSI allows querying on EventId and returns results sorted by BookingTimestamp.
3
Evaluate requirements for bulk atomic writes.
Identified the need for all-or-nothing transactional guarantees for up to 20 writes.
Standard batch writes (BatchWriteItem) do not support transactions or conditional failures, whereas TransactWriteItems guarantees ACID transactions.

Anahtar Kavram

Using Global Secondary Indexes (GSIs) for alternative query patterns and sorting, and utilizing TransactWriteItems for atomic multi-item operations.
Bu soruyu puanla