John Peterson avatar image
John Peterson asked

Custom data for statistics?

Dear PlayFab community,

I am curious to learn if there's any ability to hang custom data off of a statistic? From everything I've reviewed, a statistic is basically composed of an integer value and a version number.

The reason I ask is that I'd like to provide some additional context for a statistic. That is, if I have an leaderboard with an aggregation of last/min/max, it'd be convenient to provide some additional information to the statistic in the event that it's the "winner" (e.g., what weapon was used to achieve this high score, etc.).

Presuming there's no native support for this, can anyone provide me with some suggestions as to how I might achieve this feature? I had thought that I could store this in the UserData, but I wasn't sure whether the submitted statistic would be "persisted" as a last/min/max.


apissdksLeaderboards and Statistics
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

No, sorry, but that won't work. The problem is that when players view the leaderboard, they're going to view the top folks quite often. If you have a whole bunch of players querying the leaderboard, and they're all trying to read user data from the same players, that's going to cause a serious problem with the data table - bear in mind that every request to read a single row in the table has to be serviced one at a time. So in the case where you have loads of players, that's going to cause a "logjam" effect when they're trying to read the same players' data too quickly.

In addition, if you wanted to show this as a rich leaderboard with that info, you'd be making a query per player on the leaderboard, generating excessive calls, which could get the title throttled or blocked.

What I would recommend is that you use the profile elements to build out that extra info for the rich data you need. You could use other statistics, for example, to have info on state of the player at the time of the score, for example (since you can get all the profile info on each leaderboard entry).

10 |1200

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

John Peterson avatar image John Peterson commented ·

Thanks, @Brendan! Yeah, I can appreciate that this would generated kind of a "hotspot" effect if we were to try and leverage UserData. I wondered, too, whether we might try and store/update this data as some TitleData element (by providing our own interfaces to update the statistic and determine whether to update TitleData), but maybe that would run into some of the same issues?

Can you elaborate on your recommendation? I'm not quite "grokking" it. It reads like you're suggesting that we use the user profile data to store the custom data, but I'm not sure how that's done, or how we'd correlate a specific statistic instance with the leaderboard instance (maybe through the version?).

I do see a Tags element on the Profile from Maybe we could do something clever with that?

I'm not quite sure how we'd use other statistics to track statistics. Any additional information to give more clarity into your suggestion would be much appreciated!

Also, is this worthy of a Feature Request for the statistics, in general?

0 Likes 0 ·
brendan avatar image brendan John Peterson commented ·

It really depends upon what you have in mind. If you're going to have your own server running, and it updates Title Data once every few minutes, that would probably be fine, but you need to bear in mind that since Title Data is sharded and cached, it's not immediately available with the updated value at all endpoints. So whenever you update it, you'll have a brief period where some players will get the old values (as well as any player who have already read the data, and so will be using it).

But you originally were asking about having extra per-player data, which definitely would not work in Title Data. Can you explain in more detail what it is you want to do?

What I was saying was that there are a lot of things in the profile, including the other player stats (so, you could use one as a bitfield to contain one or more enums) and Tags (you can set a few custom strings on players with this). The profile is returned with each leaderboard entry, allowing you to use it for rich leaderboard displays.

0 Likes 0 ·

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.