Cloud Code Best Practices

Before you start to build out the Cloud Code for your game, we strongly recommend that you read these guidelines. They are designed to help you avoid creating Cloud Code structures that might compromise your game's performance. Suggestions are also given on ways in which you can check and review your Cloud Code's performance and efficiency.

Using Modules

Code Iteration and Loops

Data Access

API Requests

If you embed API requests into your Cloud Code scripts, those API requests will count towards the limit imposed on your game for API request rate, which will depend on your game's Pricing Tier - please see our Usage Limits and Fair Usage Policy webpage for details.

For an explanation of what counts towards the limit imposed on the API Requests rate for your game and how to tell if you have reached your limits, please see our Self-Service Pricing FAQs page.

Bulk Jobs and Schedulers

Custom Logic

Querying

Here are some best practices for embedding database queries in your Cloud Code.

Indexed Fields for Data Types

When using the Game Data Service, you must define indexed fields first and these Game Data Indexes are the fields you can use to query and retrieve data from the custom Data Types you've created for your game. For more details, see the Game Data page.

Indexing Fields for Mongo Runtime Collections

When creating your own custom Mongo Runtime Collections, ensure that often-queried fields are indexed. This can be done via Cloud Code. Indexing will speed up Querying speeds. For more details see the Creating Game Collection Indexes page.

Spark Cache, Redis, and Mongo Collections

How do I determine where the data should be saved?

Here’s a few things to keep in mind for answering this question.

First ask: what type of data do you want to save: game meta data, Player data, or Team, Match, or Leaderboard specific data?

Legacy Games with Mongo? If you are working with a game that was created before the launch of the Game Data Service in January 2018, you can you still use Mongo Runtime collections to store custom data, such as extra player or team data. Note that Runtime collections for Mongo are now deprecated and are not available for new games - those created after January 2018.

More on Data Persistence? For more details on how to manage data persistence on the platform, see the Managing Date Persistence page.

Querying Large Entry Numbers

Using Game Data Service

Using Mongo Runtime Collections

Using Performance Metrics

There are several useful tools built right into the GameSparks platform that you can exploit for checking on how well your Cloud Code is performing:

Next

Please review the Cloud Code API Functions Guide guide, which will help you find the Cloud Code functions suited to your game development requirements.

Did this page help you? Please enter your feedback below.