Stateful v. Stateless design piece cover image displaying two engineers working on a complex server architecture

Stateful v. Stateless Design: Key Considerations for Game Developers

In the dynamic realm of mobile game development, backend infrastructure serves as the backbone of seamless gameplay experiences. At Metaplay, we've taken a distinctive approach by embracing stateful design principles, setting us apart from the prevalent trend of stateless backends that have dominated the industry in recent years. In this article, we'll delve into the essential factors that game developers should weigh when deciding between stateful and stateless designs for their backend infrastructure.


The Power of Stateful Design

Our stateful design philosophy introduces the concept of maintaining a persistent state within game servers. In contrast to stateless systems where each request is treated in isolation, our approach adopts an actor-based model, which is better suited for handling games at large scale.

Here's a closer look at how it operates:

Authoritative Game Servers

Within the framework of stateful design, individual game servers function as the authoritative source of state. When an actor—a player, guild, or any other in-game entity—awakens from the database, the game server assumes responsibility for managing its state.

Periodic Data Persistence

To safeguard against data loss, we implement periodic data persistence, ensuring that interactions among all actors within the clustered game server backend proceed seamlessly. 

While critics contend that this approach can add complexity to scaling, its benefits far outweigh the challenges it presents. 

Game server visualization-1

Key Benefits of Stateful Design

1. Efficiency Gains and Reduced Database Load

One of the primary strengths of stateful design lies in the efficiency gains it delivers. By transforming the database into a simplified key-value store, we eliminate the need for every game operation to query the database, resulting in a substantial reduction in the database workload. 

Consider the typical 9-to-1 ratio of read to write operations in many systems. With our stateful design, we often achieve a 1:1 ratio, alleviating the need to maintain eight additional read replicas. This not only enhances efficiency but also leads to significant cost savings.

2. Scalability and Streamlined Architecture

In the realm of game development, addressing scalability is paramount. Our stateful design supports database layer expansion through sharding into multiple database clusters. This ensures that we can scale database clusters without encountering capacity limitations. 

Moreover, this design simplifies our overall architecture. When concerns arise about database performance, many developers opt for in-memory caching systems such as Redis or Memcached. In our architecture, we can circumvent these components entirely. Our game server application layer guarantees that actors continuously reflect the latest, up-to-date state of the game world, eliminating the need for additional caching layers. 

Stateful v. Stateless Design Blog

Stateless Design: A Different Perspective

Now, let's briefly consider stateless design—a methodology that has gained significant traction over the past decade. Stateless backends are known for their simplicity and ease of operation. 

Each request is processed independently, making them suitable for various applications. However, when applied to the unique demands of mobile game development, stateless design may present certain limitations.

Games often involve numerous actors and complex interactions, requiring frequent access to shared states. In such scenarios, stateless designs may lead to increased database load and latency, potentially impacting gameplay experiences. 

Choosing the Right Approach

In summary, the choice between stateful and stateless designs for your game's backend infrastructure hinges on the specific requirements of your project. 

Stateless designs offer simplicity and are suitable for various applications, but they may fall short in the context of mobile game development, where efficient state management and reduced database load are paramount. 

Stateful design, as exemplified by Metaplay, introduces efficiency gains, reduces database load, ensures scalability, and simplifies architecture. These advantages make it an appealing choice, especially in mobile game development, where performance and cost-effectiveness are of utmost importance as a game scales.

When deciding between stateful and stateless designs, carefully assess your game's unique demands and player experience objectives. The choice you make will significantly influence the gameplay experience and operational efficiency of your mobile game.