Topic 1 Question 75
Your teammate has asked you to review the code below, which is adding a credit to an account balance in Cloud Datastore. Which improvement should you suggest your teammate make?

Get the entity with an ancestor query.
Get and put the entity in a transaction.
Use a strongly consistent transactional database.
Don't return the account entity from the function.
ユーザの投票
コメント(5)
https://cloud.google.com/datastore/docs/concepts/transactions#uses_for_transactions: "This requires a transaction because the value of balance in an entity may be updated by another user after this code fetches the object, but before it saves the modified object. Without a transaction, the user's request uses the value of balance prior to the other user's update, and the save overwrites the new value. With a transaction, the application is told about the other user's update."
B is the answer
👍 3syu31svc2021/07/10- 正解だと思う選択肢: B
B is correct
👍 2tomato1232022/08/19 B. Get and put the entity in a transaction.
It is a good practice to perform a get and put within a transaction to ensure that the update to the balance is atomic. This prevents other processes from reading the balance and making updates to it simultaneously, which could lead to incorrect or inconsistent results. By using a transaction, your teammate can ensure that the balance is updated correctly and consistently.
👍 2omermahgoub2023/01/08
シャッフルモード