The core feature of p5.party is the shared object: a data object that is kept in sync between all instances of the sketch. When one client sets a value on a shared object, the change is immediately updated on the local object. The value change is also sent to the server and then broadcast to all the other clients. It takes some time—usually 50 to 500 milliseconds, depending on network quality—for each client to be updated. This delay introduced the possibility that a client will write to a shared object and then receive a change from another shared object that conflicts and overwrites the local change.
A write conflict occurs when two clients try to write to the same shared object at nearly the same time.
Here, “nearly the same time” means that a client writes while another client’s write is still in transit.
It makes sense that if two clients set the same property—like shared.fruit
—at once, only one of the values prevail. Unfortunately, the problem is more broad than that. A data conflict occurs even if the clients are setting different properties if they are on the same shared object. If client A sets shared.fruit
to "apple"
at the same time that client B sets shared.animal
to "bear"
one of those changes will be thrown out.
The short answer:
One value is thrown out.
The medium answer:
When two clients write to the same object at the same time, their changes race. The winning change is sync’d. The losing change is thrown out.
The long story:
Imagine two clients—A and B—set shared.fruit
at nearly the same time.
"apple"
and client B sets it to "banana"
.fruit
property of their local shared
object.shared.fruit = "apple"
to all of the clients.fruit
should be "apple"
and overwrites the local value accordingly.fruit
to "banana"
.fruit
is briefly "banana"
before settling on "apple"
.Losing one of the changes is the worst that should happen, but sometimes data conflicts can lead to broken client-server connections. This usually only occurs when there are lots conflicts happening at once.
A conflict happens when multiple clients write to the same shared object at nearly the same time. All of those things need to happen together, so there are many ways you might avoid conflicts.
You won’t have a conflict if: