https://github.com/clockworklabs/SpacetimeDB
Multiplayer at the speed of light
https://github.com/clockworklabs/SpacetimeDB
database dataoriented game-development relational relational-database smart-contracts
Last synced: about 1 year ago
JSON representation
Multiplayer at the speed of light
- Host: GitHub
- URL: https://github.com/clockworklabs/SpacetimeDB
- Owner: clockworklabs
- License: other
- Created: 2023-06-17T07:28:29.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-10-29T15:36:31.000Z (over 1 year ago)
- Last Synced: 2024-10-29T15:41:27.729Z (over 1 year ago)
- Topics: database, dataoriented, game-development, relational, relational-database, smart-contracts
- Language: Rust
- Homepage: https://spacetimedb.com
- Size: 15.3 MB
- Stars: 4,382
- Watchers: 27
- Forks: 110
- Open Issues: 299
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome - clockworklabs/SpacetimeDB - Development at the speed of light (Rust)
- awesome-github-projects - SpacetimeDB - Development at the speed of light ⭐24,615 `Rust` 🔥 (🌐 Web Development - Full-Stack)
- StarryDivineSky - clockworklabs/SpacetimeDB - 推送"模式自动将数据变更广播给客户端,相比传统轮询或长连接方案,资源消耗降低超 90%;最后,**去中心化的时间戳系统**利用逻辑时钟而非全局时钟达成一致性,使得全球分布的游戏节点能保持毫秒级同步,这一设计甚至优于许多商业游戏引擎的解决方案。 其技术原理可通过一个类比理解:想象数据库是一个高速运转的"时空引擎",每当玩家操作触发事件(如移动角色),引擎会像物理定律一样立即确定该事件对所有关联客户端的影响,并通过"因果链"(类似区块链的哈希链接但无加密开销)确保所有节点按相同顺序处理事件。这种架构本质上将数据库转化为一个可预测状态的确定性状态机,而客户端如同观测者,始终接收到经过引擎计算后的合法状态快照。 SpacetimeDB 通过 Rust 实现的高性能存储层支持每秒数十万次事务,其模块化设计允许扩展存储后端(当前支持本地存储和内存模式)。与 Firebase 等实时数据库相比,它通过牺牲部分灵活性换取了游戏开发中最关键的确定性;相较传统 SQL/NoSQL 方案,它又将业务逻辑从应用层下沉到数据层,使开发者能像编写单机程序一样处理分布式状态。这种"数据库即服务端"的范式,可能成为下一代实时应用基础设施的重要拼图。 (数据库管理系统 / 资源传输下载)
- AiTreasureBox - clockworklabs/SpacetimeDB - 11-03_18519_1](https://img.shields.io/github/stars/clockworklabs/SpacetimeDB.svg)|Multiplayer at the speed of light| (Repos)
- awesome-ccamel - clockworklabs/SpacetimeDB - Development at the speed of light (Rust)
- stars - SpacetimeDB
- my-awesome - clockworklabs/SpacetimeDB - development,mmorpg-server,relational,relational-database,web-development,web-framework pushed_at:2026-04 star:24.5k fork:1.0k Development at the speed of light (Rust)
README
Multiplayer at the speed of light.
## What is [SpacetimeDB](https://spacetimedb.com)?
You can think of SpacetimeDB as both a database and server combined into one.
It is a relational database system that lets you upload your application logic directly into the database by way of fancy stored procedures called "modules."
Instead of deploying a web or game server that sits in between your clients and your database, your clients connect directly to the database and execute your application logic inside the database itself. You can write all of your permission and authorization logic right inside your module just as you would in a normal server.
This means that you can write your entire application in a single language, Rust, and deploy it as a single binary. No more microservices, no more containers, no more Kubernetes, no more Docker, no more VMs, no more DevOps, no more infrastructure, no more ops, no more servers.
SpacetimeDB application architecture
(elements in white are provided by SpacetimeDB)
It's actually similar to the idea of smart contracts, except that SpacetimeDB is a database, has nothing to do with blockchain, and is orders of magnitude faster than any smart contract system.
So fast, in fact, that the entire backend of our MMORPG [BitCraft Online](https://bitcraftonline.com) is just a SpacetimeDB module. We don't have any other servers or services running, which means that everything in the game, all of the chat messages, items, resources, terrain, and even the locations of the players are stored and processed by the database before being synchronized out to all of the clients in real-time.
SpacetimeDB is optimized for maximum speed and minimum latency rather than batch processing or OLAP workloads. It is designed to be used for real-time applications like games, chat, and collaboration tools.
This speed and latency is achieved by holding all of application state in memory, while persisting the data in a write-ahead-log (WAL) which is used to recover application state.
## Installation
You can run SpacetimeDB as a standalone database server via the `spacetime` CLI tool.
Install instructions for supported platforms are outlined below.
The same install instructions can be found on our website at https://spacetimedb.com/install.
#### Install on macOS
Installing on macOS is as simple as running our install script. After that you can use the spacetime command to manage versions.
```bash
curl -sSf https://install.spacetimedb.com | sh
```
#### Install on Linux
Installing on Linux is as simple as running our install script. After that you can use the spacetime command to manage versions.
```bash
curl -sSf https://install.spacetimedb.com | sh
```
#### Install on Windows
Installing on Windows is as simple as pasting the above snippet into PowerShell. If you would like to use WSL instead, please follow the Linux install instructions.
```ps1
iwr https://windows.spacetimedb.com -useb | iex
```
#### Installing from Source
A quick note on installing from source: we recommend that you don't install from source unless there is a feature that is available in `master` that hasn't been released yet, otherwise follow the official installation instructions.
##### MacOS + Linux
Installing on macOS + Linux is pretty straightforward. First we are going to build all of the binaries that we need:
```bash
# Install rustup, you can skip this step if you have cargo and the wasm32-unknown-unknown target already installed.
curl https://sh.rustup.rs -sSf | sh
# Clone SpacetimeDB
git clone https://github.com/clockworklabs/SpacetimeDB
# Build and install the CLI
cd SpacetimeDB
cargo build --locked --release -p spacetimedb-standalone -p spacetimedb-update -p spacetimedb-cli
# Create directories
mkdir -p ~/.local/bin
export STDB_VERSION="$(./target/release/spacetimedb-cli --version | sed -n 's/.*spacetimedb tool version \([0-9.]*\);.*/\1/p')"
mkdir -p ~/.local/share/spacetime/bin/$STDB_VERSION
# Install the update binary
cp target/release/spacetimedb-update ~/.local/bin/spacetime
cp target/release/spacetimedb-cli ~/.local/share/spacetime/bin/$STDB_VERSION
cp target/release/spacetimedb-standalone ~/.local/share/spacetime/bin/$STDB_VERSION
```
At this stage you'll need to add ~/.local/bin to your path if you haven't already.
```
# Please add the following line to your shell configuration and open a new shell session:
export PATH="$HOME/.local/bin:$PATH"
```
Then finally set your SpacetimeDB version:
```
# Then, in a new shell, set the current version:
spacetime version use $STDB_VERSION
# If STDB_VERSION is not set anymore then you can use the following command to list your versions:
spacetime version list
```
You can verify that the correct version has been installed via `spacetime --version`.
##### Windows
Building on windows is a bit more complicated. You'll need a slightly different version of perl compared to what comes pre-bundled in most Windows terminals. We recommend [Strawberry Perl](https://strawberryperl.com/). You may also need access to an `openssl` binary which actually comes pre-installed with [Git for Windows](https://git-scm.com/downloads/win). Also, you'll need to install [rustup](https://rustup.rs/) for Windows.
In a Git for Windows shell you should have something that looks like this:
```
$ which perl
/c/Strawberry/perl/bin/perl
$ which openssl
/mingw64/bin/openssl
$ which cargo
/c/Users//.cargo/bin/cargo
```
If that looks correct then you're ready to proceed!
```powershell
# Clone SpacetimeDB
git clone https://github.com/clockworklabs/SpacetimeDB
# Build and install the CLI
cd SpacetimeDB
cargo build --locked --release -p spacetimedb-standalone -p spacetimedb-update -p spacetimedb-cli
# Create directories
$stdbDir = "$HOME\AppData\Local\SpacetimeDB"
$stdbVersion = & ".\target\release\spacetimedb-cli" --version | Select-String -Pattern 'spacetimedb tool version ([0-9.]+);' | ForEach-Object { $_.Matches.Groups[1].Value }
New-Item -ItemType Directory -Path "$stdbDir\bin\$stdbVersion" -Force | Out-Null
# Install the update binary
Copy-Item "target\release\spacetimedb-update.exe" "$stdbDir\spacetime.exe"
Copy-Item "target\release\spacetimedb-cli.exe" "$stdbDir\bin\$stdbVersion\"
Copy-Item "target\release\spacetimedb-standalone.exe" "$stdbDir\bin\$stdbVersion\"
```
Now add the directory we just created to your path. We recommend adding it to the system path because then it will be available to all of your applications (including Unity3D). After you do this, restart your shell!
```
%USERPROFILE%\AppData\Local\SpacetimeDB
```
Then finally, open a new shell and use the installed SpacetimeDB version:
```
spacetime version use $stdbVersion
# If stdbVersion is no longer set, list versions using the following command:
spacetime version list
```
You can verify that the correct version has been installed via `spacetime --version`.
If you're using Git for Windows you can follow these instructions instead:
```bash
# Clone SpacetimeDB
git clone https://github.com/clockworklabs/SpacetimeDB
# Build and install the CLI
cd SpacetimeDB
# Build the CLI binaries - this takes a while on windows so go grab a coffee :)
cargo build --locked --release -p spacetimedb-standalone -p spacetimedb-update -p spacetimedb-cli
# Create directories
export STDB_VERSION="$(./target/release/spacetimedb-cli --version | sed -n 's/.*spacetimedb tool version \([0-9.]*\);.*/\1/p')"
mkdir -p ~/AppData/Local/SpacetimeDB/bin/$STDB_VERSION
# Install the update binary
cp target/release/spacetimedb-update ~/AppData/Local/SpacetimeDB/spacetime
cp target/release/spacetimedb-cli ~/AppData/Local/SpacetimeDB/bin/$STDB_VERSION
cp target/release/spacetimedb-standalone ~/AppData/Local/SpacetimeDB/bin/$STDB_VERSION
# Now add the directory we just created to your path. We recommend adding it to the system path because then it will be available to all of your applications (including Unity3D). After you do this, restart your shell!
# %USERPROFILE%\AppData\Local\SpacetimeDB
# Set the current version
spacetime version use $STDB_VERSION
```
You can verify that the correct version has been installed via `spacetime --version`.
#### Running with Docker
If you prefer to run Spacetime in a container, you can use the following command to start a new instance.
```bash
docker run --rm --pull always -p 3000:3000 clockworklabs/spacetime start
```
## Documentation
For more information about SpacetimeDB, getting started guides, game development guides, and reference material please see our [documentation](https://spacetimedb.com/docs).
## Getting Started
We've prepared several getting started guides in each of our supported languages to help you get up and running with SpacetimeDB as quickly as possible. You can find them on our [docs page](https://spacetimedb.com/docs).
In summary there are only 4 steps to getting started with SpacetimeDB.
1. Install the `spacetime` CLI tool.
2. Start a SpacetimeDB standalone node with `spacetime start`.
3. Write and upload a module in one of our supported module languages.
4. Connect to the database with one of our client libraries.
You can see a summary of the supported languages below with a link to the getting started guide for each.
## Language Support
You can write SpacetimeDB modules in several popular languages, with more to come in the future!
#### Serverside Libraries
- [Rust](https://spacetimedb.com/docs/modules/rust/quickstart)
- [C#](https://spacetimedb.com/docs/modules/c-sharp/quickstart)
#### Client Libraries
- [Rust](https://spacetimedb.com/docs/sdks/rust/quickstart)
- [C#](https://spacetimedb.com/docs/sdks/c-sharp/quickstart)
- [Typescript](https://spacetimedb.com/docs/sdks/typescript/quickstart)
## License
SpacetimeDB is licensed under the BSL 1.1 license. This is not an open source or free software license, however, it converts to the AGPL v3.0 license with a linking exception after a few years.
Note that the AGPL v3.0 does not typically include a linking exception. We have added a custom linking exception to the AGPL license for SpacetimeDB. Our motivation for choosing a free software license is to ensure that contributions made to SpacetimeDB are propagated back to the community. We are expressly not interested in forcing users of SpacetimeDB to open source their own code if they link with SpacetimeDB, so we needed to include a linking exception.