Skip to main content

Architecture Overview

LayerG is a monolithic stateful server that exposes real-time and non-real-time APIs from multiple subsystems. LayerG’s subsystems cover a variety of tasks, with the major subsystems discussed below.

Authorization

LayerG authorization is based on Universal Account (UA), which leverage on the concept of Account Abstraction (AA). UA plays a role in mapping a Web3 wallet with a traditional social account and helping the user to submit transaction to L1 in a seamless behavior

LayerG masternode

LayerG masternode acts as the Asset and Game hub management. Plays a vital role in managing User Asset that lies under LayerG.

It is also a place for Game developer to kickstart their Game developing process by creating game on game hub, creating collection and deploy their Asset smart contract to L1.

This Masternode will be managed by us, running in a Trusted Execution Environment (TEE) to make sure the validation of the server itself, so user can rest assure there's no malicious behavior is injected to the server. Database will also be cryptographically encrypted so neither do we can manipulate the data.

Cluster management

info

Cluster management is a feature of LayerG Enterprise.

By relying on conflict-free replicated data types and gossip-based peer-to-peer connections, LayerG’s cluster management system provides built-in service discovery.

With this system, a LayerG cluster can gracefully respond to the loss of individual nodes or distributing load to new nodes brought online to handle surges in traffic. The system reacts to changes in the cluster’s topology and records changes in client connections to each node, to support flexible and efficient scaling.

Console and metrics

LayerG’s built-in console and metrics system provides essential tools for DevOps professionals. The console provides a standalone interface to inspect a node’s status and data, while metrics exports data via Prometheus to your team’s preferred external monitoring and analytics tools.

Database

LayerG’s database system manages long-term persistence. While LayerG’s in-memory system provides fast read and write access to a variety of data, LayerG’s database component is a methodical bookkeeper, ensuring that long-lived data is stored efficiently and reliably.

When it comes to persistence, LayerG is ready for many deployment scenarios, supporting any PostgreSQL wire-compatible database. In a canonical configuration, LayerG runs alongside CockroachDB for scalable, geographically distributed, and durable data storage.

External interfaces

LayerG’s external interface system exposes socket and request interfaces. Games built with LayerG can use both interfaces, but may only need one or the other, depending on the game design and other details specific to your game’s experience.

The socket interface is the primary entry point for real-time activity such as chat and real-time multiplayer. The socket interface runs on WebSockets and rUDP, with a choice of binary (protocol buffers) or text (JSON) payloads.

The request interface, which runs on gRPC and HTTP, is the primary entry point for non-real-time activity, such as user account management.

In-memory data

LayerG’s in-memory data system takes the place of an external in-memory data store, such as Redis. Under the hood, LayerG uses Bluge to unlock full-text search on arbitrary JSON fields, providing a range of lightning-fast searches.

The LayerG in-memory data system can be used for sophisticated and efficient matchmaking searches for matches with suitable labels (e.g. open-to-join) or players with common attributes (e.g. magic skill level X).

Management

LayerG’s management system handles match lifecycle activities, scheduling for leaderboards and tournaments, matchmaking, and hosting server-authoritative multiplayer resources.

Most critically, this system manages the resources consumed by client activities and your game’s custom server-side logic.

Message routing

LayerG’s message routing system makes sure that real-time client messages reach the correct nodes across the cluster, transparently. The message routing system tracks the whole cluster’s set of socket connections to clients and routes incoming messages to the right nodes, regardless of the cluster’s topology. The message routing system supports all of LayerG’s real-time features, such as chat and status.

Presence

The presence tracking system builds on authorization to represent a player’s live activity in the game. The player’s presence is recorded uniquely as a combination of the user, the session, and the node to which they’re connected.

By way of presence, developers can help players set generic statuses (such as available or busy), free-form status messages to friends (e.g. “Looking for a party to join!”), or compose more complex interactions (e.g. inviting friends to spectate the player’s current match).

Streams

LayerG uses the streams system to efficiently share data between clients. Streams are LayerG’s core representation of any real-time activity, such as chat, notifications, and matches.

If data needs to be distributed to clients live, streams are the way it gets there. Individual player sessions join and leave streams, like subscribing and unsubscribing to a continuous flow of messages.