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

Bulk Jobs and Schedulers

Custom Logic


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:

Did this page help you? Please enter your feedback below. For questions about using this part of the platform, please contact support here