We are making a multiplayer game and there is some data that is shared between clients.
The clients are running concurrently.
Even if our data sync was somehow instant we’d still have race conditions.
But our data sync is not instant. At internet scale, we can expect it to take 50 to 150 milliseconds for data to travel from one client to another. As quick as that might be for sending data around the world, its still pretty long. Certainly noticeable to humans, and computers can make millions of decisions in that amount of time! It’s also a good idea to think “it might take minutes”, as this helps you think clearly and code defensively.
So, we have multiple clients that share data and need to coordinate despite delays.
start: x = 10
client A: x = 9
client B: x = 11
start: x = 10
client A: x = 11
client B: x = 11
start: a = 1, b = 1
client A: a = 2, b = 1
client B: a = 1, b = 2
boss 1 email: paint the wall red
boss 2 email: paint the wall blue
When two clients try to change the data, even different parts of the data, at the same time we don’t know what to do.
What does “at the same time” really mean?
(If we had a magic system that could instantly notify about incoming data, well, we’d use it to send the data!)
The data sharing system that powers p5.party is called deepstream.io.