question

Matthew avatar image
Matthew asked

Azure Functions with 2 phase commit

When the Azure functions call multiple PlayFab API internaly,
Are there any good design for 2-phase commit like application?

And Are there any good design for a application like with role-back system?

When the Azure functions call multiple PlayFab API internaly, Are there any role-back best practise for Azure Functions?

I'm thinking of the following logic

What I want to do: Give the player an item and equip it as the initial data of the game. Details of what you want to do.

1. PlayFab grants items to players Enhanced consumable items Points (virtual currency)

2. Consume points to increase item enhancement (item level)

3. Keep the item level of this enhancement in JSON in Item Inventry Custom Data

I'm trying to use Azure Function for this process, is that the right approach?

At that time, the process becomes complicated. What kind of design should I do?

I asume the logic on Azure Functions like:

API requests for these items

* Instance ID A of the item to be strengthened (example: sword)

* Instance ID B of the item with the enhancement effect (Example: Item Enchanter +5)

* Virtual currency

1. GetUserInventoryAsync: Get the item list that the user has

2. Obtain the level of equipment to be strengthened from among them Sword: 100

3. In Instance A, add level 5 to the custom value (UpdateUserInventoryItemCustomDataAsync)

4. ConsumeItemAsync consumes enhancement item B

5. Consume points (virtual currency) with SubtractUserVirtualCurrencyAsync.

Question: Step 4 and Step 5 call different APIs. If 4 succeeds and 5 fails, the player's data will be inconsistent. How can I prevent this inconsistency?

(Example 2) Case of new character generation

1. For the first time the player plays the game

2. New character generation

3. I want to install the default equipment

4. Save equipment information in the character's Title Data

Make an API request to the following information in Azure Functions

* Character name

* Character class

1. Grant CharacterToUserAsync ()

2. Rewrite equipment information with UpdateCharacterReadOnlyDataAsync

Question"

In step 2, data inconsistencies can occur if the API returns an error. How to prevent it,,,How can I prevent this inconsistency?

CloudScript
10 |1200

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

Sarah Zhang avatar image
Sarah Zhang answered

>> Step 4 and Step 5 call different APIs. If 4 succeeds and 5 fails, the player's data will be inconsistent. How can I prevent this inconsistency?

Since we only provide REST API for you to update data. There is no built-in roll-back method can used to revoke the request. We suggest you add the judgement before the step 1 to determine if the player has both enough items and currency to upgrade the weapon. Since the executing time of a function is very short, if you have made the enough judgements to ensure that the code has no logical problems, basically the data inconsistencies won't happen.

>> In step 2, data inconsistencies can occur if the API returns an error. How to prevent it,,,How can I prevent this inconsistency?

You can add the retry mechanism for the step 2. If it returns an error, you can the API UpdateCharacterReadOnlyData again until it is updated successfully. For clarification, if the API UpdateCharacterReadOnlyData returns an error, it means this update fails and the data version won’t be incremented. When you use the API GetCharacterReadOnlyData to retrieve K/V pairs, you can set a version number in the field – IfChangedFromDataVersion to determine if this data have been updated from the previous version successfully.

10 |1200

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

Matthew avatar image
Matthew answered

Perfect! Thank you for your great answer.

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.