I am designing the layout of my datastore, but am wondering whether my approach is correct due to the nature of transactions.
I have an Account entity:
Account
=======
(int) balance (in cents)
and a Transfer entity:
Transfer
========
(Key) fromAccount
(Key) toAccount
(int) amount (in cents)
Now the transfer is pretty easy:
In a transaction I insert a Transfer entity with the appropriate values (fromAccount, toAccount, amount), and I update the two Account entities with the correct balance.
So far so good. But the documentation reads:
When two or more transactions simultaneously attempt to modify entities in one or more common entity groups, only the first transaction to commit its changes can succeed; all the others will fail on commit.
Doesn't this create a big problem? If I have many transfers happening at the same time, they might all want to update the same Account so they would all fail.
What is the recommended approach for this?
EDIT: In the documentation, they talk about retrying the same transaction, but if I have too many write operations on one account, this will just result in endless retries won't it?