Skip to main content
Multiplayer Backend

Serverless Game Servers

Launch an authoritative game server for every match instantly. Scale to millions of concurrent players without managing fleets or Kubernetes.

match_handler.ts
1import { actor } from "rivetkit";
2
3export const deathmatch = actor({
4 state: { players: {}, scores: {}, map: 'arena_1' },
5
6 actions: {
7 join: (c, { name }) => {
8 c.state.players[c.connectionId] = { name, hp: 100, pos: {x:0, y:0} };
9 c.broadcast("player_join", c.state.players);
10 },
11
12 move: (c, { x, y }) => {
13 // Authoritative movement validation
14 if (isValidMove(c.state.map, x, y)) {
15 c.state.players[c.connectionId].pos = { x, y };
16 c.broadcast("update", { id: c.connectionId, x, y });
17 }
18 }
19 }
20});

The Game Loop

Traditional serverless functions die after a request. Rivet Actors stay alive, maintaining the game state in memory and ticking the simulation as long as players are connected.

TICK: 0
Player 1
Player 2
server.tick(-1)
server.tick(0) > Broadcasting State Snapshot
< P2 Input: Attack(target: P1)

Authoritative Logic

Run your game logic (movement, hit detection, inventory) on the server to prevent cheating. The Actor is the single source of truth.

Instant Connectivity

Clients connect directly to the specific Actor instance hosting their match via WebSockets. No database polling latency.

Persistence on Exit

When the match ends, the final state (scores, loot, XP) is automatically saved to disk.

Built for Multiplayer

Infrastructure primitives that understand the needs of modern games.

Lobby Management

Create persistent lobby actors that hold players before a match starts. Handle chat, loadouts, and ready states.

Matchmaking

Use a singleton 'Matchmaker' actor to queue players and spawn new Match actors when groups are formed.

Turn-Based Games

Perfect for card games or board games. Actors can sleep for days between turns without incurring compute costs.

Leaderboards

High-throughput counters and sorting in memory. Update scores instantly without hammering a database.

Economy & Inventory

Transactional state for trading items or currency. Ensure no item duplication glitches with serialized execution.

Spectator Mode

Allow thousands of users to subscribe to a match actor to watch real-time updates without affecting player latency.

Case Study

Real-Time Strategy (RTS)

A persistent world 4X strategy game where thousands of players move armies on a shared map.

  • Sharding: Map divided into hex grids, each controlled by an Actor
  • Fog of War: Calculated on server, only visible units sent to client
  • Persistence: Game state survives server updates seamlessly
Sector: Alpha-9
Units: 4,291 Active
Live
Tick Rate20Hz
Combat resolved in Grid[44,12]. 12 units lost. Updating clients...

Integrates with your engine

Unity
Unreal Engine
Godot
Phaser
Three.js
PlayCanvas

Launch day ready.

Focus on the gameplay. Let Rivet handle the state, scaling, and persistence.