In my project only Cloud Functions can write to Firestore database, clients never.
Clients only call Cloud Functions like this one:
InflictDamageToEnemy()
{
1."Read Player attack from database"
2."Read Enemy health from database"
3."Enemy health -= Player attack"
4."Write new Enemy health to database"
}
I wonder what happens when multiple users call this cloud function at roughly same time? Will reads and writes conflict with each other? Specifically. Read and Write of Enemy health. Like this:
InflictDamageToEnemy()
{
1."Read Player attack from database"
2."Read Enemy health from database"
Enemy health changed here to a different value as this cloud function was called from different client and executed
3."Enemy health -= Player attack"
4."Write new Enemy health to database"
}
Can this happen? If so. How to fix this? Do I have to use transactions in cloud functions?
Thanks!