Mischa Winkler
Mischa Winkler2mo ago

How are concurrent updates to a model property handled?

If two clients update a model property at the exact same time (lets say an array of bool values encoded in single byte[] property), one client switching index 0, and the other switching index 10, can I be sure that the property will contain both changes after the updates are completed? Or will one win over the other? Will one get lost?
7 Replies
kapa.ai
kapa.ai2mo ago
Hi @Mischa Winkler. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Normcore handles concurrent updates to a model property in a very efficient way. When multiple clients make changes to the same property, Normcore is able to detect these simultaneous updates and respond appropriately. If Client A makes a change and then receives an update from Client B that occurred before Client A made the change locally, Normcore will continue to reflect Client A's value locally as it knows that the value is more recent. If Client A's value is rejected by the server, the datastore will roll back to Client B's value and will fire a change event to notify that the value was updated. In the case of your byte array, if two clients are updating different indices of the array, these changes should be handled independently and both changes should be reflected in the final state of the array. However, if two clients are updating the same index of the array, the update from the client that the server deems to be more recent will be the one that is reflected in the final state of the array. It's also worth noting that Normcore provides several collections that can be used to synchronize data in real-time. These collections are designed to be atomic even with multiple clients making simultaneous changes to them. For example, the RealtimeArray is a special model type that holds a sequential list of models that can be modified at runtime. Modifying the array sends the minimal amount of information necessary for other clients to replicate the change. The whole collection is not sent every time. For more information, you can refer to the following documentation: - Instant updates (https://normcore.io/documentation/room/datastore#instant-updates) - RealtimeArray (https://normcore.io/documentation/reference/classes/Normal.Realtime.Serialization.RealtimeArray%601) - Collections (https://normcore.io/documentation/room/collections) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@847936237003604048> kapa.ai is still learning and improving, please let us know how it did by reacting below
maxweisel
maxweisel2mo ago
if they’re both editing the same byte array it definitely will not contain a merged buffer of the changes from both clients normcore’s server treats each property as an opaque value you could have both clients edit separate properties and those will merge together, but it’s not going to analyze the contents of your byte[] buffer and merge them if we did that, if you stored a PNG in a byte[] buffer and one client replaced it with a jpeg and one replaced it with a different png at the same time, it’s possible you’d get the png header added to a jpeg image because the header wasn’t touched by the second client we don’t know enough about the contents of the buffer to do merges correctly
Mischa Winkler
Mischa Winkler2mo ago
Makes sense. How would you recommend syncing a large array of bools reliably between clients? I don't want to create 5000 properties :/ I just want to account for concurrent edits. Maybe just use ownership locks?
maxweisel
maxweisel2mo ago
I’d use a lock system then or have one client own it and the others send delta update messages for it to update it
Mischa Winkler
Mischa Winkler2mo ago
Thank you for the quick response!
maxweisel
maxweisel2mo ago
sure thing!