Architecture

Architecture

uGameDB is a Riak client which is designed especially for the Unity game engine. The system is made up of several parts that is normally spread over several different machines.
  • The game servers interact with the database as part of their game logic. The uGameDB client runs in the background as part of the Unity instance on the game server.
  • Riak, being a distributed database, consists of a cluster of Riak nodes that run on one machine each. A Riak cluster can have any number of nodes, and nodes can be added or removed while the cluster is online.
  • The game clients do not perform any database operations themselves, and are not aware of the Riak back-end. However, their interactions with the game server may indirectly trigger database requests to be created.
You can see the architecture of uGameDB in the figure below. Every game server communicates with a number of Riak nodes through the uGameDB client. In order for a game server to be able to have many simultaneous requests in transit, it has a pool of TCP connections to each node that it talks to. Each game server can configure both which Riak nodes it will connect to, and how many connections to pool up to each separate node. uLobby can connect to the same Riak cluster to share important game data with the game servers, and it is possible to add other external systems that interacts with the cluster, like a web site displaying game statistics.
images/architecture.png

Riak provides three protocols by which a user can communicate with it: Protocol Buffers Client (PBC), HTTP and Erlang. uGameDB uses the PBC protocol, which is faster than HTTP. The PBC connection to Riak is made over TCP and the default Riak PBC port is 8087, but this is configurable both in the client and on each database node. Erlang is not a protocol in the conventional sense, but since Riak is using the Erlang runtime it is possible to hook an erlang node directly into the Riak cluster and make requests from within the cluster. One can see this as a protocol because it can be done remotely and the commands are sent over the network as Erlang function calls.

External Database Access

When you have a multiplayer game it is common to have additional services that view and manipulate game data. For example, you might want to have a website where players of an MMO game can browse and trade items that are used in-game, or a website that displays recent match statistics of an FPS game. Riak has many client libraries that can be used in PHP, Ruby, Java and other languages common for building websites. Some of these have been developed by Basho themselves and some have been provided by the community. Check out the Client Libraries page at the Basho website.
If you intend to make a specific set of your game data available to external clients, it is important that you encode your data as JSON, which is the native encoding of many of these client libraries. Otherwise you will not be able to decode the data once it has been read.