Global data store setting and retrieving problem

I am currently working on a custom clan system for my game and this is the approach i am trying to take.

To create a clan my client sends a name to the server which then the server will retrieve a table filled with all the existing clans using GetAsync() to create a reserved place in the table for the new clan.

It would look like this,

retrieved_data = data:GetAsync(1)

retrieved_data.current_clans[“WARRIORS”] =
{
name = info.name,
owner_id = tostring(plr.UserId),
}

data:SetAsync(1, retrieved_data)

This table would then be saved using SetAsync().
My reason for this approach is to have people able to join clans without being on the same server.
And the updates on clans will be live throughout different servers which is what i want.

My question is if i retrieve data at one point in time and different servers change the data before i even set the new data then will some data be lost? And how would i approach it differently?

I will illustrate this for you.

If you need any more elaboration let me know.
Thanks.

do not have several servers read from datastores if the information is meant to be used during runtime. use another service such as memorystoreservice or messaging service to reflect the changes synthetically and have just one server actually update the datastore

edit: also, use updateasync, not setasync if you’re just altering data

I’ve just read about messaging service, it seems like i will have to have one server update to the datastore and have different servers request their changes towards that one server.

That seems a bit unsafe because what if that chosen server loses all it’s players and shuts down, the time it takes to hand over the role to a different server will surely cause loss of data.

im confused why you’re doing it backwards?

server 1 initializes, reads datastore
server 1 subscribes to messagingservice topic “clan server updates” (think of this as a chat channel)

server 2 initializes, reads datastore
server 2 subscribes to messagingservice topic “clan server updates”

server 1 updates datastore
server 1 pings messagingservice topic “clan server updates” with new information it updated

server 2 gets ping, checks to make sure the clan names align and verifies what data its supposed to reflect and ifi ts even relevant, then reflects the changes this creates in runtime, but does NOT update any datastores

… later
server 3 initializes, reads datastore, which is the updated one that server 1 updated
server 3 subscribes to messagingservice topic “clan server updates”
server 3 updates the datastore due to input on its new server, pings messagingservice topic again with new data

server 1 and server 2 now verify, reflect the changes, and do not update their datastores but simply present the environment as if they did

… continues forever, all servers on the same page

there, data is reflected across your game

1 Like

This makes so much sense now thanks

Can you elaborate on which server actually updates the datastore and why?

The server who gets the user’s input to update something updates the datastore, as that’ll make sure any other servers that are created after are up to date. We want only this server updating because:

  • There is no way for others to tell if it’s updated in real-time using only DataStores. That is partially why MessagingService was created.
  • Updating and reading a datastore several times with the same data is redundant and may cause timeouts (rejections). We want to reduce as many SetAsync’s and GetAsync’s as we can.
  • Other servers that are created later and read the data from the datastore will be updated and on the same page.

So if server 1 were to have somebody create a clan, server 1 would update the datastore.
Other servers will recieve a signal via messaging service.
Those other servers will read the updated datastore and then what will they do?
You said reduce GetAsyncs and SetAsyncs so will there be a copy of clan data on each server which is updated every messagingservice event?

Other servers will recieve a signal via messaging service.
Those other servers will read the updated datastore and then what will they do?

Don’t have the other servers read the updated datastore, give them the data directly through MessagingService to avoid GetAsync()'s. Then, have them update the game state, aka their local server (I don’t know what this does in your game’s context, it just means updating whatever they need to update in their specific servers to reflect the change.)

You said reduce GetAsyncs and SetAsyncs so will there be a copy of clan data on each server which is updated every messagingservice event?

Yes, assuming the above.

1 Like

I’ve managed to implement your method and it is working perfectly thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.