PROFESSIONAL-CLOUD-DEVELOPER · Question #23
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?
The correct answer is B. Get and put the entity in a transaction. 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…
Question
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?
Exhibit
Options
- AGet the entity with an ancestor query.
- BGet and put the entity in a transaction.
- CUse a strongly consistent transactional database.
- DDon't return the account entity from the function.
How the community answered
(36 responses)- A3% (1)
- B78% (28)
- C8% (3)
- D11% (4)
Explanation
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
Topics
Community Discussion
No community discussion yet for this question.
