question

dominiquecanzeri avatar image
dominiquecanzeri asked

Is UpdatePlayerStatistics aggregation method "Sum" atomic?

if multiple client/server add a player statistic at the same, will the result be as we expect?

ex: 4 clients attacks a 5th player base, and increment some statistic (village_damage) by 1,2,3,4 points, will the resulting village_damage always be increment by 10 points?

thanks

10 |1200

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

Citrus Yan avatar image
Citrus Yan answered

Hi @dominiquecanzeri,

PlayFab cannot guarantee that these operations are atomic, therefore, in your case, we cannot make sure that the resulting village_damage will always be increment by 10 points. Moreover, enabling clients to update statistics is not best practice, as this data will no longer be safely controlled by the server. Using the Server/UpdatePlayerStatistics API in the server-side logic to deal with this concurrency issue might be a good idea, for instance, using Queue to handle multiple requests.

10 |1200

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

dominiquecanzeri avatar image
dominiquecanzeri answered

hi,

the real use-case was to implement a "like" feature.

I know that the upcoming UGC feature will probably take care of that.

in the meantime, I was using a playerStatistic to track the number of likes.

in this example, N server sessions would increment (by 1) the playerstatistics Y of player X

so if I understand what you're saying, the player statistic Y might not be incremented by N if those events happen at the same time.

Is that it?

1 comment
10 |1200

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

Citrus Yan avatar image Citrus Yan commented ·

Hi @dominiquecanzeri, sorry for this late reply,

Yes, indeed, in your aforementioned scenario, PlayFab cannot guarantee that statistic Y will increment by N using the UpdatePlayerStatistics API.

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.