SurrealDB is a modern, open-source database that blurs the line between document stores, graph databases, and relational systems. Built entirely in Rust, it lets you store, query, and manage data using a single unified query language — SurrealQL — while supporting real-time subscriptions, row-level permissions, and distributed clustering out of the box.
With over 31,000 stars on GitHub and weekly releases from an active development team, SurrealDB has matured into a viable production database for applications that need flexible data modeling without juggling multiple database systems.
This guide covers everything you need to self-host SurrealDB: installation methods, docker deployment, SurrealQL fundamentals, authentication setup, and production clustering configuration.
Why Self-Host SurrealDB
Running your own SurrealDB instance gives you capabilities that hosted database services cannot match:
Full data control. Your application data — including user records, session tokens, and business logic — stays on infrastructure you own. No third-party database operator can access, monetize, or restrict your data.
Unified data model. Traditional architectures require a document database for flexible JSON storage, a graph database for relationship queries, and a relational database for transactions. SurrealDB handles all three patterns in a single engine, reducing operational complexity and eliminating inter-database synchronization.
Cost predictability. Managed database services charge per read, per write, per gigabyte stored, and per compute hour. A self-hosted SurrealDB instance on a $15/month VPS handles millions of records with predictable resource usage.
Real-time subscriptions. SurrealDB supports live queries that push changes to connected clients over WebSockets. Self-hosting means you control the WebSocket endpoint, connection limits, and authentication — no middleware proxy required.
Edge deployment. Because SurrealDB runs as a single binary with no external dependencies, you can deploy it on edge servers, Raspberry Pi devices, or containers in remote locations where managed database connectivity is unreliable.
Architecture Overview
SurrealDB’s architecture differs fundamentally from traditional databases:
| Feature | Traditional RDBMS | Document DB + Graph DB | SurrealDB |
|---|---|---|---|
| Data model | Tables with fixed schemas | Separate JSON docs + graph nodes | Unified records with flexible schemas |
| Query language | SQL | Multiple (MongoDB query, Cypher, Gremlin) | SurrealQL (single language) |
| Relationships | JOINs with foreign keys | Manual graph traversal | First-class record links with RELATE |
| Real-time | Polling or separate message queue | Separate WebSocket layer | Built-in LIVE SELECT subscriptions |
| Permissions | Row/column-level grants | Application-level enforcement | Built-in DEFINE ACCESS rules |
| Deployment | Single-primary or primary-replica | Separate clusters per engine | Single binary, embeddable or distributed |
| Storage engines | Limited choices | Engine-specific | RocksDB, TiKV, FoundationDB, SurrealKV, memory |
SurrealDB stores data as records — each record has a unique table-and-ID identifier (e.g., person:john), can contain nested JSON-like fields, and can reference other records directly. This unified model means a single query can traverse relationships, filter on nested fields, and aggregate results without joining across separate systems.
Installation Methods
Binary Installation
SurrealDB ships as a single static binary. Install it directly on your server:
| |
Or use your system package manager:
| |
Docker Deployment
The official Docker image supports multiple storage backends. Here is a production-ready Docker Compose configuration:
| |
Deploy with:
| |
This configuration mounts a named volume for persistence, sets a health check, and includes the optional SurrealDB Studio web interface for database management.
Embedded Mode
For applications that need a database without a separate server process, SurrealDB embeds directly into your application:
| |
SurrealQL Fundamentals
SurrealQL is the unified query language that powers all data operations. It combines familiar SQL syntax with graph traversal and document manipulation capabilities.
Creating Records
Records in SurrealDB have explicit identifiers. You can let the database generate IDs or specify your own:
| |
Querying with Relations
The RELATE statement creates graph-style connections between records:
| |
Schema Definition
SurrealDB supports both schemaless and schema-defined tables:
| |
Live Subscriptions
Real-time data push without separate WebSocket infrastructure:
| |
Authentication and Permissions
SurrealDB has a built-in, multi-layered permission system that eliminates the need for application-level authorization middleware.
Root and Namespace Access
| |
Scope-Based Authentication
Scopes define authentication flows for different user types:
| |
Table-Level Permissions
Fine-grained access control at the record level:
| |
Production Deployment
Clustering with TiKV
For high-availability production deployments, use TiKV as the distributed storage engine:
| |
Reverse Proxy Configuration
Place SurrealDB behind a reversnginxxy for TLS termination and rate limiting:
| |
Backup and Restore
SurrealDB supports native export and import:
| |
For automated backups, combine with a cron job:
| |
When to Use SurrealDB vs Other Databases
SurrealDB excels in specific scenarios and is less suited for others:
| Scenario | Recommended | Reason |
|---|---|---|
| Rapid prototyping with flexible schemas | SurrealDB | Schemaless mode, no migrations needed |
| Social network with complex relationships | SurrealDB | First-class graph traversal in SurrealQL |
| Real-time collaborative applications | SurrealDB | Built-in live subscriptions over WebSockets |
| High-throughput OLTP (100K+ writes/sec) | PostgreSQL / CockroachDB | SurrealDB is still optimizing write throughput |
| Existing PostgreSQL ecosystem investment | PostgreSQL | SurrealDB uses its own query language |
| Time-series data ingestion | TimescaleDB / InfluxDB | Not SurrealDB’s primary optimization target |
| Multi-model with single database | SurrealDB | Eliminates need for separate document + graph stores |
If you are already running a distributed SQL cluster like CockroachDB, YugabyteDB, or TiDB, SurrealDB can serve as a complementary real-time layer for user-facing features while your primary cluster handles transactional workloads. For applications that need graph queries alongside document storage, SurrealDB replaces the need to run separate graph and document databases.
FAQ
Is SurrealDB production-ready in 2026?
SurrealDB reached version 2.0 and has been used in production by companies handling millions of records. The core engine is stable, and the team maintains a regular release cadence with weekly updates. For distributed clustering, TiKV and FoundationDB storage engines are production-tested. The newer SurrealKV engine is maturing but recommended for evaluation before large-scale production use.
What is the difference between SurrealDB and a traditional SQL database?
Traditional SQL databases use fixed table schemas, require explicit JOIN syntax for relationships, and store data in rows and columns. SurrealDB uses a flexible record model where each record has a unique ID, can contain nested JSON data, and can link to other records natively. SurrealQL supports both SQL-like queries and graph traversal, eliminating the need for separate query languages for different data patterns.
Can I migrate from MongoDB or PostgreSQL to SurrealDB?
Yes. SurrealDB provides import tools for JSON, CSV, and SurrealQL formats. For MongoDB, you can export collections as JSON and import them directly — SurrealDB’s document model maps naturally to MongoDB’s structure. For PostgreSQL, you can export as CSV or use migration scripts. However, complex stored procedures and triggers will need to be rewritten as SurrealDB event definitions.
Does SurrealDB support ACID transactions?
Yes. SurrealDB supports full ACID transactions at the record and table level. When using distributed storage engines like TiKV or FoundationDB, transactions span across multiple nodes with strong consistency guarantees. Single-node deployments with SurrealKV or file storage also provide ACID semantics within a single instance.
How does SurrealDB handle horizontal scaling?
SurrealDB scales horizontally through its distributed storage engine layer. With TiKV, data is automatically sharded and replicated across nodes. With FoundationDB, it leverages that database’s proven multi-node transactional layer. The SurrealDB compute layer is stateless — you can add or remove compute nodes without data migration. For smaller deployments, the embedded mode runs as a single process with no clustering overhead.
What programming languages have official SurrealDB drivers?
Official drivers exist for JavaScript/TypeScript (npm), Python (pip), Rust (crates.io), Go (go get), Java (Maven), .NET (NuGet), and PHP (Composer). Community-maintained drivers are available for Kotlin, Swift, Dart, and Elixir. All official drivers support the full SurrealQL feature set including live queries, authentication scopes, and parameterized queries.