Firebase database:
{
"balance" : 10
}
Application 1 (pseudocode):
if (balance-10 >= 0)
{
// Application freezes for a few seconds. (Connection/hardware issue or whatever reason)
balance -= 10;
}
Application 2 (pseudocode):
if (balance-10 >= 0)
{
// Application is executed without any problems.
balance -= 10;
}
If both applications start at the same time, the final "balance" value will be "-10" instead of "0".
In MySQL this problem is easy fixed by:
UPDATE `table` SET balance=IF(balance-10>=0, balance-10, balance);
What are the possible solutions for Firebase?