SurrealDB — Scalable Multi-Model Database for Modern Apps
SurrealDB is a scalable, distributed, collaborative, document-graph database for the real-time web. Combines relational, document, graph, and time-series models in one database with SurrealQL query language. Built in Rust for performance and reliability.
What it is
SurrealDB is a scalable, multi-model database designed for the real-time web. It combines relational, document, graph, and time-series data models in a single database with its own query language called SurrealQL. You can write SQL-like queries that traverse graphs, filter documents, and aggregate time-series data in one statement.
SurrealDB targets full-stack developers building real-time applications who want to avoid managing separate databases for different data models.
How it saves time or tokens
SurrealDB eliminates the need for a document store, a graph database, and a relational database. One connection string, one query language, one backup process. The built-in permissions system means you can expose SurrealDB directly to the frontend with row-level security, removing the need for a separate backend API for simple CRUD operations.
Real-time subscriptions via WebSocket push data changes to clients without polling.
How to use
- Install SurrealDB:
curl -sSf https://install.surrealdb.com | sh - Start the server:
surreal start --user root --pass root - Connect with the CLI:
surreal sql --conn http://localhost:8000 --user root --pass root - Create tables and query with SurrealQL
Example
-- Create a user document
CREATE user:alice SET name = 'Alice', age = 30, role = 'engineer';
-- Create a graph edge
RELATE user:alice->works_at->company:acme SET since = '2024-01-01';
-- Query with graph traversal
SELECT name, ->works_at->company.name AS company
FROM user
WHERE role = 'engineer';
-- Real-time subscription
LIVE SELECT * FROM user WHERE age > 25;
Related on TokRepo
- Database tools -- Database management and query tools
- Coding tools -- Full-stack development tools
Common pitfalls
- SurrealDB is younger than PostgreSQL or MongoDB; the ecosystem of drivers and ORM integrations is smaller
- The direct-to-frontend pattern requires careful permission configuration; misconfigured DEFINE TABLE PERMISSIONS can expose data
- SurrealQL looks like SQL but has significant differences in syntax for graph traversals and record IDs
Frequently Asked Questions
PostgreSQL is a mature relational database with extensions for JSON and limited graph queries. SurrealDB is purpose-built for multi-model data with native graph traversals, real-time subscriptions, and document storage. PostgreSQL has a far larger ecosystem; SurrealDB has a more integrated multi-model experience.
For document storage, SurrealDB is a capable alternative. It stores schemaless JSON documents and supports flexible querying. The advantage is that you also get graph and relational capabilities without adding another database. The tradeoff is a smaller ecosystem and fewer managed hosting options.
Yes. LIVE SELECT queries push changes to connected clients via WebSocket whenever matching data changes. This enables real-time features like chat, notifications, and collaborative editing without polling.
Official drivers exist for Rust, JavaScript/TypeScript, Python, Go, Java, and .NET. The JavaScript SDK works in both Node.js and browsers, enabling the direct-to-frontend pattern.
SurrealDB is in active development. It is used in production by some teams, but it is newer than established databases. Evaluate its stability against your requirements and have a fallback plan for critical workloads.
Citations (3)
- SurrealDB GitHub— SurrealDB is a multi-model database for the real-time web
- SurrealDB Docs— SurrealQL query language documentation
- SurrealDB Docs— Real-time LIVE SELECT queries via WebSocket
Related on TokRepo
Discussion
Related Assets
Hugging Face Tokenizers — Fast Text Tokenization for ML Pipelines
Hugging Face Tokenizers is a Rust-powered tokenization library with Python bindings that implements BPE, WordPiece, Unigram, and SentencePiece tokenizers with training and encoding speeds of gigabytes per second, used as the backbone for Transformers model tokenization.
Cleanlab — Find and Fix Label Errors in Any ML Dataset
Cleanlab is a data-centric AI Python library that automatically detects label errors, outliers, and data quality issues in classification and regression datasets, helping improve model accuracy by cleaning training data rather than tuning models.
Hugging Face Datasets — Access and Process ML Datasets at Scale
Hugging Face Datasets is a Python library for efficiently loading, processing, and sharing machine learning datasets with Apache Arrow-backed memory mapping, streaming support, and access to thousands of community datasets on the Hub.