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 (Universal Account)
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 gamehub
The LayerG Gamehub serves as the central hub for asset and game management, playing a crucial role in overseeing user assets within the LayerG ecosystem and providing a dedicated platform for game developers to initiate their development process by creating games within the Game Hub, uploading assets, list your game on our Portal, and deploying asset smart contracts to Layer 1 (L1).
Seamlessly integrated into our Game Engine Admin Console, it eliminates the need for third-party services for asset uploads, ensuring a streamlined and efficient development experience.
LayerG Decentralized Crawler system
The Layerg-Crawler is a blockchain event monitoring and data indexing system designed for the U2U blockchain. It allows users to:
- Define data schemas using GraphQL, specifying what blockchain events to track and how to store them
- Monitor smart contract events (like Token Transfers and Approvals) in real-time
- Expose data in GraphQL for easy querying
- Generate type-safe Go code for handling blockchain events
- Developer can then join the crawler to the LayerG network to help us index the blockchain data and serve as a validator for the network, Creating redundant data publish the logic to the LayerG network.
Cluster management
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.