Serverless Multiplayer Options
What Serverless Means for Games
Serverless computing traditionally means stateless functions that execute in response to events and shut down when idle. This model does not work for multiplayer games because game sessions are inherently stateful, maintaining game state in memory across many interactions over minutes or hours. However, a new generation of serverless platforms provides stateful compute, instances that maintain state in memory and accept persistent WebSocket connections, while still handling provisioning, scaling, and geographic distribution automatically.
The appeal is operational simplicity. You write your game logic as a class or module, deploy it to the platform, and the platform handles creating instances when players connect, distributing those instances across global infrastructure, scaling up during peak hours, scaling down to zero during quiet periods, and managing the underlying servers. You never SSH into a machine, configure nginx, set up process managers, or handle rolling deployments. For solo developers and small teams, this removes an entire category of work.
The tradeoff is control. You cannot customize the networking stack, tune OS-level parameters, choose specific hardware, or run arbitrary background processes. You are constrained by the platform's execution model, timeout limits, memory limits, and supported APIs. For complex game simulations that need raw performance, dedicated servers still win. For simpler real-time games and prototypes, serverless platforms can be the faster path to production.
Cloudflare Durable Objects
Cloudflare Durable Objects are the closest thing to a dedicated game server in the serverless world. A Durable Object is a JavaScript/TypeScript class instance that runs on Cloudflare's edge network with a unique ID, persistent in-memory state, and support for WebSocket connections. Each Durable Object instance is guaranteed to run in a single location (no distributed state), which means you can use ordinary in-memory data structures without worrying about consistency across replicas.
For game development, each Durable Object instance acts as a game room. The object holds the game state in memory, accepts WebSocket connections from players, runs a game loop using the alarm() API for periodic ticks, and processes messages from each connected client. The platform automatically creates the object when the first player connects and keeps it alive as long as connections are active. When all players disconnect and the object has no pending alarms, it hibernates, serializing its state to durable storage and consuming no compute resources until the next connection arrives.
The WebSocket Hibernation API is particularly useful for games. It allows a Durable Object to release its memory while keeping WebSocket connections open. When a message arrives on a hibernated connection, the platform wakes the object, restores its state, and delivers the message. This means you pay nothing for idle connections (players in menus, AFK players, slow-paced games between turns). The wake-up latency is typically under 50 milliseconds, which is acceptable for turn-based games but may be noticeable in fast-paced action games.
Durable Objects run on Cloudflare's global network, so the object instance is automatically placed near the first player who connects. Subsequent players connect to the same location regardless of their own geography. For regional games, this works well. For global games where players from different continents join the same session, some players will have higher latency than others, just as with any single-region dedicated server.
PartyKit
PartyKit is a serverless platform built specifically for real-time, multiplayer, and collaborative applications. It runs on Cloudflare's infrastructure under the hood but provides a higher-level API designed for the common patterns of multiplayer games and collaborative tools. You define a "party" server class with lifecycle methods (onConnect, onMessage, onClose, onAlarm) and deploy it with a single CLI command.
PartyKit handles room routing automatically. Each party instance is identified by a room ID in the connection URL. When a client connects to a specific room ID, PartyKit routes the connection to the party instance for that room, creating it if it does not exist. This eliminates the need to build room discovery, matchmaking routing, or instance management. For many casual multiplayer games, this built-in routing is sufficient.
The developer experience is PartyKit's strongest advantage. Local development uses a hot-reloading dev server. Deployment is a single command that pushes your code to the edge globally. The API surface is small and focused, so you spend time writing game logic rather than configuring infrastructure. PartyKit also provides a built-in storage API for persisting game state between sessions, useful for persistent world games or saving game results.
PartyKit's limitations mirror those of Durable Objects since it runs on the same underlying technology. CPU time per request is limited (though alarms can chain for continuous processing), memory is limited to the Durable Object limits, and you cannot run native code or heavy computation. It is well-suited for turn-based games, card games, simple real-time games, and collaborative experiences like shared whiteboards or document editors with game-like interaction.
Firebase Realtime Database and Firestore
Firebase Realtime Database was one of the original "serverless multiplayer" solutions, long before the term serverless was widely used. It provides a cloud-hosted JSON database with real-time synchronization. When any client writes to a path in the database, all other clients listening to that path receive the update within milliseconds. This makes it possible to build multiplayer games without writing any server code at all.
The pattern is straightforward. Each game room is a path in the database (e.g., /games/room-id/). Game state lives at that path. Players write their inputs to sub-paths (e.g., /games/room-id/players/player-id/input), and all clients listen for changes to the entire room path. When any player's input changes, every client receives the update and processes it locally.
The major limitation is that Firebase is a relay, not an authoritative server. There is no server-side game logic processing inputs and enforcing rules. Every client runs the game simulation and trusts the data in the database. Firebase Security Rules can validate data shapes and enforce basic constraints (a player can only write to their own path, values must be within certain ranges), but they cannot run arbitrary game logic like physics simulation or complex validation.
Firebase works well for turn-based games (chess, card games, board games) where the rules are simple enough to express as database security rules and where cheating is either detectable (impossible moves in chess) or acceptable (casual games among friends). It is not suitable for real-time action games that need authoritative servers, fast tick rates, or binary message protocols. The latency through Firebase (typically 100 to 300 milliseconds for writes to propagate) is also too high for fast-paced games.
Supabase Realtime and Alternatives
Supabase provides a Postgres-backed alternative to Firebase with real-time subscriptions via WebSockets. Changes to database rows are broadcast to subscribed clients through Postgres's built-in LISTEN/NOTIFY mechanism. This is more structured than Firebase's JSON tree but serves a similar purpose for game state synchronization.
Supabase's advantage is that it uses standard SQL for data storage and queries, making it familiar to developers who already know relational databases. Row-level security policies provide fine-grained access control that can enforce some game rules server-side. However, like Firebase, the real-time layer is a synchronization mechanism, not a game engine. Complex game logic still needs to run somewhere, either on the client (with cheating risks) or in a separate server process that writes to Supabase.
Other alternatives in this category include Ably (a pub/sub messaging platform with presence detection), PubNub (real-time messaging with channel-based routing), and Pusher (event-driven WebSocket service). These platforms provide real-time message delivery but no game-specific features. They can serve as the transport layer for turn-based or slow-paced multiplayer games where you implement game logic on the client.
When to Use Serverless vs. Dedicated Servers
Serverless multiplayer works well for turn-based games where latency tolerance is high and tick rates are low, casual real-time games with simple physics and small player counts (2 to 8 per session), collaborative experiences and shared-state applications, prototypes and MVPs where speed of development matters more than performance optimization, and games with highly variable traffic where scaling to zero during off-peak hours saves significant cost.
Dedicated servers are better for competitive real-time games where tick rates above 20 per second are needed, games with complex server-side physics or AI simulation, games requiring more than 128 MB of state per room, games where sub-10-millisecond processing latency matters, and large-session games with dozens or hundreds of players per room.
A hybrid approach is also viable. Use a serverless platform for matchmaking, lobbies, leaderboards, and social features while running game sessions on dedicated servers. The serverless components handle variable-traffic, stateless operations efficiently, while the dedicated servers handle the compute-intensive, latency-sensitive game simulation.
Serverless platforms like Cloudflare Durable Objects and PartyKit bring multiplayer game hosting within reach of solo developers by eliminating server management. They work best for turn-based and casual real-time games. For competitive, physics-heavy, or high-tick-rate games, dedicated servers remain the better choice, though a hybrid approach can combine the strengths of both.