Game Backend Experience

A few years ago, I was a full-time game developer. Nowadays I do it as a spare-time activity.

In a recent project I worked on, I chose Parse as the backend for our game. About halfway through a 16 month development process, Parse announced that it would close down, and that we would have until January 2017 to switch off of their platform. The hunt for a new solution begun.

Looking for Alternative Solutions

After understanding I would not have time to build my own backend system, I found a few pre-built game-centric SAS solutions. Amongst them, PlayFab. Evaluation lead me to find out that PlayFab had the best combination of features, customization and, most importantly, support.

Needless to say, I chose PlayFab and started working on a plan to migrate our data and our game code.

The first order of business was to map the data we had on Parse to PlayFab. Parse stored data using relational tables, whereas PlayFab has more game-centric data management. PlayFab also has a catalog that stores items that can be bought (either with real money or in-game currency), and storage with flat strings, that can be used to store data as JSON.

With the data downloaded from Parse into JSON blobs, I built a migration script using Swift Playgrounds in Xcode. PlayFab let me upload catalog entries as JSON objects, so the migration script would transform data by accumulating the values from the relationships in the Parse relational data tables, and creating whole objects that would make sense in PlayFab.

Afterwards, it was just a matter of building classes on the client-side to take in the new data. This turned out to be easier than I thought. Parse provided an API that lets us download data from its server and access object values using methods that return the proper type. Taking that into account, I just made my own base classes that let me do the same, with a constructor that took in PlayFab-based objects and let me access the object's properties.
 

public T GetProperty<T>(string key)
{
    return GetProperty<T>(default(T), key);
}

public T GetProperty<T>(T defaultValue, string key)
{
    if (parsedData != null)
    {
        object value = null;
        if (parsedData.TryGetValue(key, out value))
        {
            if (value is T)
            {
                return (T)value;
            }
            else
            {
                try
                {
                    return (T)Convert.ChangeType(value, typeof(T));
                }
                catch (InvalidCastException)
                {
                    Utils.DebugLog.Error("[{0}] error converting object {1} to type {2}", GetType().Name, value, typeof(T));
                }
            }
        }
    }

    return defaultValue;
}

public List<T> GetList<T>(string key)
{
    JsonArray array = GetProperty<JsonArray>(key);
    if (array != null)
    {
        return array.ConvertAll<T>(t => (T)Convert.ChangeType(t, typeof(T)));
    }
    
    return new List<T>();
}

This whole process took about a month, and I believe now more than ever, that it was the right decision for the game. Even if Parse did not close down, PlayFab provides us with features for user and data management that would not have been possible with Parse, even with months of extensive custom development.

Looking back, the most important things I learned throughout this process were:

  • Choosing a backend specific for your application is key
  • With pre-built solutions, long-term support and backing are essential
  • Spending a few weeks researching options is best done at the beginning of the project. Researching options at the beginning of the project can, in the end save you time and extra work.
  • Using a solution (for pretty much anything, not just backend), must NOT be solely based on past experience and comfort with the technology.
  • Learn from your experiences and understand how to move on fast if something is not working

I'm happy to say the PlayFab team has been very supportive through the whole endeavor, providing coding support, adding features for us, and fixing bugs at insane hours of the night.

 

Author: Ricardo Chavarria
https://www.linkedin.com/in/ricardochavarria/