question

max avatar image
max asked

Creating a player referral system

We are planning to create a referral system that incentivizes our players to tell their friends and bring new players into the game. This questions is about how to ideally track the data in PlayFab and how to reward both the new player and the referrer.

Let's imagine that the referrer generates a referral link, then sends it to a friend, who then downloads our game. Upon the first startup the new player's client knows that a player with the PlayFabID A invited them.

Now the new player has to tell PlayFab that they want to use their one-time I-was-referred-by option and therefore the new player is getting rewards. So far it's easy. But we also need to have the referrer get their rewards and have them know that they did refer somebody. The initial idea would be that the new player writes their PlayFabID somewhere into the referrer's player data.

So far we could avoid that any player has to write into another player's data since we know that this might lead to race conditions / multiple players writing into the same data and something getting lost.

Is there some way of locking while writing data to a certain player data key? I've read quite a while ago that it was planned. Alternatively is there a better way to do it that maybe does not even raise this issue?

Looking forward to what you think! ;)

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

Actually, we posted an example of a recommended way to do a referral system in our "recipes" sample repo in GitHub - https://github.com/PlayFab/PlayFab-Samples/tree/master/Recipes/ReferralCodes. Can you have a look at that and see if you have any questions on how to make use of it?

3 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.

max avatar image max commented ·

Thank you that makes quite some sense!

Some questions directly about this recipe:

1) Is there any specific reason you use an item to track that the referral was already triggered? I would have saved a flag into player data from my gut feeling.

2) As far as I see it, this system might also trigger a race condition, as the referee is writing to the referrers player data. If two (or more) referrees are writing at the same time, the data might not be correct in the end.

A reads
A modified read data in local memory
B reads
B modifies read data in local memory
A writes
B writes

In the end everything that A did never happened in the database.

0 Likes 0 ·
brendan avatar image brendan max commented ·

In the sample, we use a referral item to indicate that the player has already stated when another player referred them - that could be done with user data as well, it's just what we chose to do. The player who provided the referral has the referred player added to a single key/value pair that tracks on all referrals.

To your original point, yes, it's possible that you could have multiple players call the referral code simultaneously, stating that player as their referrer. In the case where their calls are literally simultaneous, you'd only track on one of the two in the referrer's data, but if you're logging an event for it, you'd still be able to do analytics on the referral.

0 Likes 0 ·
brendan avatar image brendan brendan commented ·

Oh, but clarification - the person referred would still have the record showing that they were referred, so they couldn't cause an issue where they claim referral from multiple other players.

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.