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 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?
- 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
- Use the `TransactWriteItems` API to execute the bulk registrations as a single transaction.Cevap
- CUse the `Scan` API with a `FilterExpression` on the base table to retrieve bookings for a specific `EventId` and sort them in application code.
- DIncrease the provisioned Write Capacity Units (WCUs) on the base table to automatically resolve failures caused by transactional validation checks.
- EInitialize 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
Anahtar Kavram
Using Global Secondary Indexes (GSIs) for alternative query patterns and sorting, and utilizing TransactWriteItems for atomic multi-item operations.