nerdexam
Google

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 transact

Implementing Data Storage Solutions

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

PROFESSIONAL-CLOUD-DEVELOPER question #23 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)
  • A
    3% (1)
  • B
    78% (28)
  • C
    8% (3)
  • D
    11% (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

#Cloud Datastore#Transactions#Data Consistency#Concurrency Control

Community Discussion

No community discussion yet for this question.

Full PROFESSIONAL-CLOUD-DEVELOPER Practice