Soru

Zorluk: ZorData Store Operations with Amazon DynamoDB

A developer is designing a peer-to-peer mobile payment application. When a user initiates a funds transfer to another user, the application must perform three operations: deduct the transfer amount from the sender's account balance, add the transfer amount to the recipient's account balance, and record the transaction history in a log table. These operations must execute atomically so that either all of them succeed or all of them fail. Under high traffic, the system must maintain strict consistency and prevent throttling issues. Which implementation strategy should the developer use to meet these requirements?

  1. A
    Initialize the DynamoDB client by passing hardcoded IAM access keys with administrative access directly in the application code, and use the BatchWriteItem API to execute the updates and transaction logging in a single batch request.
  2. B
    Perform a Scan operation on the Accounts table to retrieve both the sender and recipient records, verify the sender's balance within the application logic, and then apply the updates using individual UpdateItem calls.
  3. Use the TransactWriteItems API to perform conditional Update operations on the sender and recipient records in the Accounts table, checking that the sender's balance is sufficient, while simultaneously performing a Put operation in the Transactions table.Cevap
  4. D
    Use a partition key of AccountStatus to query active accounts, and increase the table's provisioned write capacity units (WCUs) to resolve ProvisionedThroughputExceededException errors caused by highly concurrent balance updates.

Cevap

Use the TransactWriteItems API to perform conditional Update operations on the sender and recipient records in the Accounts table, checking that the sender's balance is sufficient, while simultaneously performing a Put operation in the Transactions table.
Using the TransactWriteItems API provides atomicity and consistency guarantees, ensuring that all operations (the balance updates and the transaction log) either succeed together or fail together. The conditional check verifies that the sender has sufficient funds prior to completing the write.

Adım Adım Çözüm

1
Analyze the requirements for atomicity and consistency across multiple operations.
The requirements demand that deducting the sender's balance, adding the recipient's balance, and writing the transaction log must succeed or fail as a single atomic unit.
This guarantees that no money is lost or created in the system if a failure occurs mid-operation.
2
Evaluate the capabilities of different DynamoDB write APIs.
BatchWriteItem does not support atomic transactions or conditional checks. TransactWriteItems supports up to 100 actions (or 4 MB of data) and provides ACID transactions.
Choosing the correct API ensures both transactional integrity and data consistency.
3
Incorporate conditional checks for balance verification.
The balance check must be performed atomically at write time using a ConditionExpression on the sender's record (e.g., balance >= transfer amount).
This prevents overdrafts and race conditions in a concurrent high-throughput environment.

Anahtar Kavram

Using DynamoDB Transactions (TransactWriteItems) for atomic, multi-table write operations with conditional checks.
Bu soruyu puanla