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.
Review-first install path
This asset needs a review step. The copied prompt tells the agent to dry-run, show the writes, then proceed only after confirmation.
npx -y tokrepo@latest install 9033274f-3649-11f1-9bc6-00163e2b0d79 --target codexDry-run first, confirm the writes, then run this command.
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
ArangoDB — Native Multi-Model Database (Documents, Graphs, Key-Value)
ArangoDB is a scalable multi-model database that handles documents, graphs, and key-value data with one engine and one query language (AQL). It replaces three databases with one — without giving up performance.
Elixir — Dynamic Functional Language for Scalable Apps
Elixir is a dynamic, functional language for building scalable and maintainable applications. Runs on the battle-tested Erlang virtual machine (BEAM) with the same fault-tolerant, distributed, soft real-time properties. The language behind Phoenix framework and LiveView.
NVIDIA Triton Inference Server — Multi-Framework Model Serving at Scale
Triton Inference Server is NVIDIA's production model serving platform. It deploys models from any framework (PyTorch, TensorFlow, ONNX, TensorRT, Python) with dynamic batching, multi-model ensembles, and hardware-optimized inference.
Locust — Scalable Load Testing in Pure Python
Locust is an open-source load testing tool where you define user behavior in plain Python code. Distributed, scalable, and with a real-time web UI for monitoring. No DSL to learn — just write Python.