Skip to content

Overview

Embedding SurrealDB

Instead of connecting to a remote server, you can run SurrealDB directly inside your application process. Embedded mode gives you the full query engine with no network overhead, which is useful for local-first applications, edge deployments, and testing.

The following languages are supported:

The Swift and Kotlin SDKs, which cover iOS and Android apps, connect to a SurrealDB server over HTTP or WebSocket, and do not run a database inside the app.

When embedding SurrealDB in web browsers, you have two options:

  • SurrealKV over OPFS: SurrealDB can store and persist data within the web browser with SurrealKV, which keeps its files in the browser's Origin Private File System (OPFS). The database has to run in a dedicated web worker, and one database can be open in one tab at a time.

  • SDK: Alternatively, you can use the SurrealDB SDK to connect to a remote SurrealDB instance instead of storing data in the browser.

Embedding in a browser uses the JavaScript SDK's WebAssembly engine (@surrealdb/wasm). It connects with mem:// for an in-memory database or surrealkv:// for persistent storage, and can run inside a Web Worker so that queries do not block the page. A surrealkv:// database only opens inside a dedicated worker. IndexedDB (indxdb://) was removed in SurrealDB 4.0, and a surrealkv:// database copies the data of an IndexedDB database with the same name when it is first opened. Embedded engines shows both setups.

  • Storage engines - which engine an embedded database can use, and what each gives up

Was this page helpful?