question

brendan avatar image
brendan asked

Writing Title Data in Cloud Script

Question from a developer:   Can I use Title Data to track on a global counter/value that I'm writing to from the client via Cloud Script?  
10 |1200

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

brendan avatar image
brendan answered
No, that's really not going to work. What's going to happen if you do this is that anytime you have more than one person trying to write to it at the same time, only one of those is going to actually "win" the write race, causing your value to be inaccurate for at least one player. Also, since the data has to be replicated across multiple endpoints (as Title Data must be sharded to be readable by all users), a player reading a value after another player writes a new value isn't necessarily going to get the value just written. Both of these become increasingly important (and common) as you scale up the number of users.   We will be providing a way to have global counters later on, but at the moment, you would need to use an external data table to enable a global counter of this sort. Azure Table Storage, Amazon DynamoDB, and MongoDB via mLabs would all be options as they have Web API interfaces you could use from Cloud Script or directly from the client.
2 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.

mattilange avatar image mattilange commented ·

Is there any news on the "global counters"? Would be neat to have for generating custom diplay names. Kind regards, Matthias

1 Like 1 ·
brendan avatar image brendan mattilange commented ·

While I realize this sounds trivial, but to make this work in a situation where you have millions of players (which is always a requirement in our designs), it actually requires that the data in question be stored in-memory and that it be updated as an atomic operation via request from a queue, with all player actions that can change it feeding into that queue. Next, there's a decision to be made on whether that data should be consistent or not across all requests. So, if a user updates the value, should the next request - regardless of where it's from or how soon after - see the value as updated with that? That informs whether or not you can use caching (and potentially sharding) for the value. In this case, that is a requirement, so what you actually need is a 'query and increment' atomic operation, in this case.

We do have a backlog item to provide a feature like this at a future date, but for now you may want to look into using an external data table, Redis, etc.

0 Likes 0 ·
Miquel avatar image
Miquel answered

hello, do we have global counters already?

10 |1200

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

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.