Save and load from Storage

Hi,
I’m working on reading and writing storage objects.
My game has a lot of things to save (coins, gems, player profiles that have a lot of variables by themselves, and many more).
I have some questions and some scenarios about it.

Senario 1:
Q1. Is it better to have a unique collection and key for every single player that saves all variables on it?
For example, I have cl_1 collection key_1 key for player 1,cl_2 key_2 for player 2, and … those whole variables should be in general.

public class general{
public int coin;
public int gem;
public Profile Profile;
and many more ....
}
public class Profile{
.....
}
the general class use for parse json from server (for read and wirte)

Senario 2:
Q2.Is it better to have a lot of collections and keys for every variable that should be saved on the server?
For example, I have coin collection = C_COL with key = C_KEY that every single player coin should be saved in this collection.
For every single variable, I make a collection and a key. In this scenario, I should use a lot of separate classes.

public class Coin{
public int coin;
}
public class Gem{
public int gem;
}

public class Profile{
public int profile;
}

and many more classes that should be make seprate (for parse json from server)

I have 10 million active players (for example), so

Senario 1: have 10M database rows with very large json response save and load from every single player. I think it should be easier to search between 10 million users and find whole user data. However, it may take a long time to save and load data on the server (a lot of server resources are used for saving and loading data).
(I’m not sure about this.)

Scenario 2: has 1000 database rows (for example, whole variables are 1000) and each database row has 10M database rows.
I believe that searching between 10 million users and 1000 variables to find every single user’s data should be more difficult, but the json response time for save and load is very short (using a lot of server resources for searching and finding data).
(I’m not sure about this either.)

My goal is to use very low server resources because I have a lot of players (for example, 10 million) and want a fast server response.

FinalQ: Which one of the above scenarios is better?

MoreQ:Have you got a better scenario for a game that has a lot of variables that should be saved and loaded on the server?

About my game: Racing, 3D, developed by Unity Engine, no battle royal mode yet, but will be added in the future, and a maximum of ten players per match.

I’d appreciate any help.
Thanks in advance.

Hello,

The recommended approach is to have multiple values under the same key, as discussed here: Storage engine structure.

Instead of having a huge object per key, I’d spread the values by some logical grouping per collection, using your example above, coins and gems could be part of the economy collection under a currencies key, but please refer to the above thread for more fleshed out examples.

Hope this helps.

Hi @sesposito ,
It was helpful and your brief explanation here was much more helpful and excellent
Thank you.

If it is possible, I will ask a question. I hope you answer

Can it be said that a collection is like a database and the key works like a database table?
Therefore, we must be careful in using the collection, but we can use more keys.
Is this conclusion correct?

Thank you very much again. have a nice day.

I think that abstraction creates a few misleading assumptions. Under the hood the collection is just part of the composite primary key of each storage object, which maps to a database row.

We provide the collection as a flexible and abstract way of grouping keys, so that you can also list them (see: Nakama: Collections | Heroic Labs Documentation), shall you need it.

Hopefully this gives more clarity.

Have a nice day yourself :slight_smile:

1 Like