DEV Community

Sebastian Wessel
Sebastian Wessel

Posted on

SurrealDB  - The Magic Database to Keep on Your Radar

As a TypeScript backend developer, I've been juggling various projects, and one particular challenge kept resurfacing: implementing a robust permission system for users across multiple tenants.
I initially attempted to tackle this using TypeORM and a relational database, but it was a frustrating endeavor that didn't quite feel like the right fit.

In search of a better solution, I embarked on a journey through the vast landscape of web development tools and databases.
That's when I stumbled upon SurrealDB, and let me tell you, it was nothing short of mind-blowing.
Beyond resolving my immediate problem, it sparked a cascade of ideas for addressing numerous challenges across my other projects.

Without hesitation, I dove headfirst into SurrealDB, and the experience proved to be a game-changer.

Multi-model database

SurrealDB is a versatile multi-model database that offers you a world of possibilities. You can utilize it in various ways: as a traditional relational database, a straightforward key-value store, a NoSQL database akin to MongoDB, or even as a robust graph database. What sets it apart is the incredible flexibility it offers—you can seamlessly blend these approaches to meet your specific needs.

In this tutorial, we'll start by storing fundamental data, such as user entities with attributes like first name, last name, and email, much like you would in a NoSQL database, such as MongoDB. Then, in the next step, we'll enhance data integrity by incorporating table schemas, similar to what you'd find in a traditional relational database.
But that's not all.
We'll take it a step further by enriching this base data with relationship information, harnessing the power of graph database features to achieve a comprehensive solution.


A truly remarkable and potent core feature of SurrealDB revolves around its record-IDs.
These IDs are divided into two distinct parts.
The first part signifies the table or entity domain, while the second part denotes the unique identifier for a specific entity within that domain.
What sets SurrealDB apart is its remarkable flexibility – the identifier can take on a wide range of forms, be it numbers, strings, UUIDs, ULIDs, or even complex objects.
This versatility empowers SurrealDB, turning it into something of a rarity in the database world – a true unicorn.

I wholeheartedly encourage you to explore the official documentation to unlock the full potential of this extraordinary feature.

In this tutorial, we'll just skim the surface of the potential of record-IDs. We'll stick to basic identifiers to help you grasp the fundamental concepts of how we store, connect, and retrieve data.

Features of SurrealDB

Rather than overwhelming you with an exhaustive list of SurrealDB's fantastic features and possibilities, I'd like to highlight a few scenarios where SurrealDB could be an excellent solution for you:

  • Time series data
  • Geo data
  • Subscribe to database changes
  • IoT, edge and embedded devices.
  • Social networking data

Setup for our tutorial

To follow along with this tutorial, you'll need to have a functioning SurrealDB instance.
I recommend starting a Docker container in an in-memory mode. This allows you to conveniently reset or restart the database in a clean state as you experiment and explore.

Offical SurrealDB website:

For directly interacting with the database, you can use

Now, let's continue with the next part of this series.
In this section, we'll begin by taking a broad look at the problem and discussing how we plan to solve it using SurrealDB.

Top comments (0)