Gamasutra: The Art & Business of Making Gamesspacer
View All     RSS
September 23, 2017
arrowPress Releases






If you enjoy reading this site, you might also want to check out these UBM Tech sites:


 

Building a Scalable Online Game with Azure - Part 5

by Nick Pruehs on 03/28/17 09:37:00 am   Expert Blogs   Featured Blogs

The following blog post, unless otherwise noted, was written by a member of Gamasutraís community.
The thoughts and opinions expressed are those of the writer and not Gamasutra or its parent company.

 

Welcome to the final part of the series Building a Scalable Online Game with Azure! Now that we know about the general architectural design of online games in the cloud, adding a web service that acts as interface between the frontend and the actual backend services, how to persist state to a scalable database, and how to create a small Universal Windows Platform game that accesses our backend, there's only one last thing do to: Deploying the application to the cloud.

Then, adding more services such as the Game service in the diagram above, is straight-forward and works exactly the same as adding the Lobby service in the second part of this series, and communication between these services is implemented the same way as communication between the Web Service and the Lobby service.

As always, if you've missed any or all of the previous parts, you can catch up by grabbing the source code that we've written so far from GitHub.

Setting up the Database

First, we need to setup a few things in Azure:

  1. Create a free account at portal.azure.com.
  2. In the navigation pane to the left, click New > Databases > NoSQL (DocumentDB).
  3. Enter an ID for the new database resource.
  4. Ensure that the DocumentDB API is selected.
  5. Select the subscription you acquired when creating your Azure account.
  6. Create a new resource group for the database.
  7. Confirm all settings by pressing Create.

After a few minutes, our new database should be up and running.

In the navigation pane of the database, click on Keys to retrieve our new connection URI and primary key.

Now, in our LobbyActor, in OnActivateAsync, change the client parameters accordingly.

// Create the client.
this.client = new Microsoft.Azure.Documents.Client.DocumentClient(
    new Uri("https://npruehs-game-sample.documents.azure.com:443/"),
    "Cut0c46kzpS0hmx7zHqycrY20TU4rVmRcq7P3XmIQPgegZNRZkhrsWLr06yAs5x31JjBYZbYiGypynSwyNkzpg==");

We can verify that our new database is working as expected by hitting F5 in Visual Studio and visiting our local endpoint again (e.g. http://localhost:8557/api/login/npruehs). The login counter should be visible from the Document Explorer of our Azure portal afterwards.

Setting up Service Fabric

Time to create the actual service fabric cluster.

  1. In the navigation pane to the left, click New > Compute > Service Fabric Cluster.
  2. Enter cluster name, user name and password as desired.
  3. Select the subscription you acquired when creating your Azure account.
  4. Specify a name for a new resource group.
  5. Confirm all data by pressing OK.

Then, we specify the configuration of our new cluster. Set up a new node type by choosing durability and reliability tiers, as well as virtual machine size. Confirm all settings by pressing OK.

Finish the cluster creation by specifying security settings, reviewing the summary and pressing Create.

Azure will create the service fabric cluster and notify us as soon as it's ready. Make sure to wait until the Service Fabric Cluster is fully deployed.

Note that depending on the type of virtual machine you've selected, this can take up to several hours.

Done. Back to Visual Studio.

Deploying the Application

After opening our backend solution, we can right-click the service fabric project (i.e. GameBackend) and select Publish...

Our application has already several target profiles in place: These profiles allow to properly test the application locally, while not wasting any resources when deployed to the cloud.

  1. Select the cloud publish profile.
  2. Sign in to the Microsoft account that you used for accessing the Azure portal.
  3. Select the connection endpoint we've just set up in the Azure portal.
  4. Click Publish.

Wait for Visual Studio to publish our application to the cloud.

As soon as the publishing process has finished, we can see our application in the Service Fabric Explorer of the Azure portal!

Setting up the Load Balancer

(Un-)fortunately, our application isn't publicly available yet. Let's change that.

First, we need to add a health probe that will monitor the availability of our service.

  1. In the navigation pane to the left, click All Resources.
  2. Select the load balancer resource (e.g. LB-npruehs-game-sample-nodetype0).
  3. Select Health probes and press the + button (Add).
  4. Specify a name for the health probe, and the correct protocol and port for our application.
  5. Confirm all settings by pressing OK.

Next, we open the actual port for our game client.

  1. In the navigation pane of the load balancer resource, select Load balancing rules.
  2. Press the + button (Add).
  3. Specify a name for the rule, as well as the correct protocol and port for our application.
  4. Select the health probe we've just created.
  5. Confirm all settings by pressing OK.

Finally, our service running in the cloud is available to be consumed by clients - visit the application URL (e.g. http://npruehs-game-sample.westeurope.cloudapp.azure.com:8557/api/login/npruehs) in the browser and verify the results!

Adjusting the Client

One last tiny step remains: We need to change the connection settings in our client.

  1. Open the frontend solution in Visual Studio.
  2. In SampleFpsTextRenderer.cpp, update the connection settings.
// Send request.
httpClient =
	ref new Windows::Web::Http::HttpClient();
Windows::Foundation::Uri^ uri =
	ref new Windows::Foundation::Uri("http://npruehs-game-sample.westeurope.cloudapp.azure.com:8557/api/login/" + clientId);

Build and run the game. It should properly connect to our Azure backend.

Conclusion

We have learned about the general architectural design of online games in the cloud, adding a web service that acts as interface between the frontend and the actual backend services, how to persist state to a scalable database, how to create a small Universal Windows Platform game that accesses our backend, and how to finally deploy the whole application to the cloud.

Both our game logic services and our data storage are scalable to meet varying resource demands. The backend application is extensible, allowing to add more services at any time.

Congratulations! You've successfully created a scalable online game running in the cloud!

References

  1. Microsoft. NoSQL tutorial: Build a DocumentDB C# console application. March 2017. https://docs.microsoft.com/en-us/azure/documentdb/documentdb-get-started
  2. Xue. Developing and Deploying a Service Fabric Voting App to Azure. February 2017. https://blogs.msdn.microsoft.com/zxue/2017/02/25/developing-and-deploying-a-service-fabric-voting-app-to-azure/

 


Related Jobs

Naughty Dog
Naughty Dog — Santa Monica, California, United States
[09.22.17]

Graphics Programmer (Game Team)
Insomniac Games
Insomniac Games — Burbank, California, United States
[09.22.17]

Mid to Sr Gameplay Programmer
Insomniac Games
Insomniac Games — Durham, North Carolina, United States
[09.22.17]

Mid to Sr Gameplay Programmer
Monomi Park
Monomi Park — San Mateo, California, United States
[09.22.17]

Game Engineer





Loading Comments

loader image