question

andrearossini avatar image
andrearossini asked

Concurrency Read/Write on Title Data

Hi,

We have a piece of code in cloud script that read a title data entry, modify the data and then re-write it.

If two different sources run this cloud script function at the same time, it can be that both of them read the same thing and process the same data resulting in two equal write operations. Is this right, no?

So, if this scenario is possible, what about the next one:

(In the following example we'll consider a simple title data entry with just a string) - Is it possible that:

- First client execution read a string like "AAA"

- First client execution modify it to "ABC"

- First client execution start to write "ABC"

- Second client execution read the temporary string "AB"

- First client exeuction end to write "ABC"

.

.

.

?

So the question is: is it possible that a client script execution read an incomplete temporary data cause another instance is writing the same data?

Thank you.

Best regards,

Andrea

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

Because Title Data has to be queryable by all players in the game, it must be a sharded and cached resource. That means that it is only meant to be used for scenarios where it is occasionally updated. There is always going to be some delay until all caches have been updated with the latest value.

So while Title Data may be read by all clients (that's the point of it), Title Data must never be updated as a result of a client action. Trying to do so would violate our fair use policy, as it is not designed to be used that way, and could result in your title being throttled or blocked.

If you can describe from a top-down perspective the actual feature you're trying to enable, we can help to advise you on the best solution.

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

andrearossini avatar image andrearossini commented ·

We're implementing a premium tournament system, where player can join an event paying a buy-in.

All event data are stored in title data. This title data entry is updated every X time by a cloud script call done by an external service.

We have the problem when this call fails (ex. for an Internal Server Error or something like that). Just to be sure that the data change correctly and they are ready for the client, when the client refresh this title data, we check if this title data entry should be updated:

- If entry is already updated, it's ok.

- If entry need to be updated, we'll update it during the client cloud script call (This possibly results in multiple updates but since we don't need to process cumulative data this is not a problem for us... Every client will just write the same data).

Our question is about if is it possible that, when a client perform a GetTitleData while another client execution is writing that entry, the first client receive an incomplete version of the entry (like using Multithread). Or if the first client just read the previous value of the entry and only when the write operation it's completely done, next clients will read the new value.

Thanks

0 Likes 0 ·
brendan avatar image brendan andrearossini commented ·

First, what is X in the time period for the Cloud Script call from the external service?

Second, no, do not make the "backup" call from a client-triggered Cloud Script. If your title takes off, that could result in a large number of clients making that call, which would be a problem (and again, could get your title blocked). What you should do is check for errors on the response when making the call from the external service, and re-try the call with an exponential backoff on any error (so, retry after a couple of seconds, then after about 8, then 30, then 120).

For your question, If it's one Title Data key/value pair, the client will either get the old value or the new value. If it's multiple key/value pairs, the client could get old or new values for each, so I would recommend having a version number in the data.

0 Likes 0 ·
andrearossini avatar image andrearossini brendan commented ·

X should be a medium-large period such as 12/24 hour.

I'm also considering the solution using PlayFab Scheduled Task (but in this case I won't have the retry option on fail, right?)

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.