Sharing a backend across multiple games


Motivation

It's common for studios to have multiple games and want to share backend data across them. For example, a studio might want to share user accounts & friends across games, but keep game-specific data like leaderboards & achievements separate.


Multiple module instances

If we have a leaderboard module and we want to run multiple instances of it for the games foo and bar, we can use module aliases to create multiple instances of the module.

{
	"modules": {
    	// Users module is shared across all games
		"users": {},
    	// Leaderboard for game `food`
		"foo_leaderboard": {
			"module": "leaderboard"
		},
    	// Leaderboard for game `bar`
		"bar_leaderboard": {
			"module": "leaderboard"
		}
	}
}
rivet.json

This will create an isolated database for each game's leaderboard.

To get the scores from the foo leaderboard, we can use the foo_leaderboard module:

const fooScores = await ctx.modules.fooLeaderboard.getScores();
TypeScript