The Best Database for SpatialOS
We’ve gotten some inquiries from customers about using Fauna with SpatialOS. Fauna’s global distribution, transactions, and temporal data model make it a great fit; I would like to explain why in detail.
What is SpatialOS?
SpatialOS is a cloud platform for building multi-agent systems: primarily online games, VR worlds, and physical simulations.
The game Worlds Adrift
Data elements called entities are sharded and replicated in memory across machines that can host co-located workers. Workers are stateless logic processors that can be written in a variety of programming languages. They subscribe to change events on entities, or respond to user input, and react by executing logic, querying external resources, and updating other entities.
In academia, they call this a tuple space. In game development they call it a big problem, so it makes sense that SpatialOS has attracted so much attention.
The Spatial Sauce
The SpatialOS name comes from the fact that entities are sharded by their location in three-dimensional virtual space. This is nice for games because you get the benefits of batch processing nearby entities together, while letting the platform manage replication and partitioning at the boundaries.
However, as Duco van Amstel, a SpatialOS engineer, explains:
[In SpatialOS], as soon as you have an element of data you care deeply about, you want something that is: written on disk…in multiple locations for redundancy; has access mechanisms that implement transactions correctly; [and] allows for rollback to a specific point in history. In other words, you want an on-disk, cloud-based transactional database.
Fauna is the only database that meets these requirements.
What is Fauna?
Fauna is a multi-cloud, globally distributed, temporal database. You get all your friendly database feature like transactions, indexes, constraints, and user-defined functions, you get a comprehensive cloud security model, and you never have to worry about provisioning or scaling your backend.
Like SpatialOS, Fauna works hard to hide the infrastructure behind the system. If you don’t want to care about the underlying cloud providers, you don’t have to. Also like SpatialOS, Fauna Cloud is pay-as-you-go. As your system scales up and down in usage and complexity, you pay for only what you actually use.
Snapshots and Rollbacks
Fauna is also designed to store not just the state of your data, but its history. This solves a critical issue with SpatialOS. SpatialOS allows you to snapshot your entire world state, in order to duplicate it or survive catastrophes. But if you take a snapshot, you also need to have a snapshot of your database at the same point in time, or the two will be badly out of sync.
Since Fauna is temporal, the entire database can be read at any point in the past for any query. In effect, it is “always snapshotted.” Any SpatialOS snapshot, entity state, or worker computation can be trivially correlated to the correct database state at any time. This also solves a related problem, partial rollback:
Snapshots are a costly operation and should not be counted on, for example, to roll back specific player transactions with respect to maintenance or similar incidents.
A temporal database is the right way to provide this discrete rollback capability.
Fun With History
If you can query any group of entities in your simulation from any point in time, what else can you accomplish? You could:
- Render instant replays of anything, from any time and any perspective, by interpolating event data
- Let entities use their “memory” to automatically create narratives about themselves
- Use machine learning to detect unusual, fraudulent, or game-breaking behavior
- Create activity feeds of world and player activity for second-screen apps
With Fauna, the virtual sky is the limit.
Latency and Locality
To top it all off, although you might not know where your SpatialOS nodes and application users are physically located, queries to Fauna from both workers and clients will automatically get routed to the closest physical datacenter, guaranteeing the lowest possible latency.
Let us know if you build something with Fauna and SpatialOS!
If you enjoyed our blog, and want to work on systems and challenges related to globally distributed systems, serverless databases, GraphQL, and Jamstack, Fauna is hiring!
Subscribe to Fauna blogs & newsletter
Get latest blog posts, development tips & tricks, and latest learning material delivered right to your inbox.