DEV Community

Alex Spinov
Alex Spinov

Posted on

SurrealDB Has a Free Multi-Model Database for Modern Apps

SurrealDB is a free, open-source multi-model database that combines SQL, document, graph, and time-series capabilities in one platform.

What Is SurrealDB?

SurrealDB is a next-generation database that eliminates the need for multiple specialized databases. One database for SQL queries, document storage, graph traversal, and real-time subscriptions.

Key features:

  • Multi-model: SQL + document + graph + time-series
  • SurrealQL (SQL-like query language)
  • Real-time subscriptions
  • Built-in authentication and permissions
  • Single binary deployment
  • Embedded or server mode
  • HTTP, WebSocket, and native SDK APIs
  • ACID transactions
  • Full-text search

Quick Start

Install

# macOS/Linux
curl -sSf https://install.surrealdb.com | sh

# Docker
docker run --rm -p 8000:8000 surrealdb/surrealdb:latest start
Enter fullscreen mode Exit fullscreen mode

Start Server

surreal start --user root --pass root --bind 0.0.0.0:8000 file:mydata.db
Enter fullscreen mode Exit fullscreen mode

First Queries

-- Create records (no schema needed)
CREATE person:john SET
  name = "John Doe",
  age = 30,
  email = "john@email.com",
  skills = ["Python", "Rust", "Go"];

-- Relations (graph)
RELATE person:john->knows->person:jane SET
  since = "2024-01-15",
  context = "conference";

-- Query with graph traversal
SELECT name, ->knows->person.name AS friends FROM person:john;

-- Full-text search
SELECT * FROM person WHERE name @@ "john";
Enter fullscreen mode Exit fullscreen mode

JavaScript SDK

import Surreal from "surrealdb";

const db = new Surreal();
await db.connect("ws://localhost:8000");
await db.signin({ username: "root", password: "root" });
await db.use({ namespace: "app", database: "main" });

// Create
const person = await db.create("person", {
  name: "Alice",
  age: 28,
  interests: ["AI", "web scraping"]
});

// Query
const results = await db.query(
  "SELECT * FROM person WHERE age > $min_age",
  { min_age: 25 }
);

// Real-time subscription
await db.live("person", (action, result) => {
  console.log(action, result); // CREATE, UPDATE, DELETE
});
Enter fullscreen mode Exit fullscreen mode

Multi-Model Power

Document (like MongoDB)

CREATE product SET
  name = "Laptop",
  specs = { cpu: "M3", ram: "16GB", storage: "512GB" },
  tags = ["electronics", "portable"];
Enter fullscreen mode Exit fullscreen mode

Graph (like Neo4j)

RELATE user:1->purchased->product:1 SET quantity = 1, date = time::now();
SELECT ->purchased->product.name FROM user:1;
Enter fullscreen mode Exit fullscreen mode

SQL (like PostgreSQL)

SELECT category, count(), math::mean(price) AS avg_price
FROM product
GROUP BY category
ORDER BY avg_price DESC;
Enter fullscreen mode Exit fullscreen mode

Permissions

-- Define who can read/write what
DEFINE TABLE post SCHEMAFUL
  PERMISSIONS
    FOR select WHERE published = true OR author = $auth.id
    FOR create WHERE $auth.id != NONE
    FOR update WHERE author = $auth.id
    FOR delete WHERE author = $auth.id;
Enter fullscreen mode Exit fullscreen mode

SurrealDB vs Traditional Stack

Need Traditional SurrealDB
SQL queries PostgreSQL Built-in
Documents MongoDB Built-in
Graph queries Neo4j Built-in
Real-time Redis/WebSocket Built-in
Auth External service Built-in
Search Elasticsearch Built-in
Total DBs needed 3-6 1

Who Uses SurrealDB?

With 28K+ GitHub stars:

  • Startups simplifying their tech stack
  • Developers building real-time apps
  • Companies with graph + document needs
  • Teams wanting fewer moving parts

Get Started

  1. Install with one command
  2. Start server
  3. Query with SQL-like syntax
  4. Use document, graph, and SQL — all in one

One database to rule them all.


Need to store scraped web data? Check out my web scraping tools on Apify — extract data and store directly in SurrealDB. Custom solutions: spinov001@gmail.com

Top comments (0)