Databases are vital in web development for storing data in different forms and shapes (both structured and unstructured) in an organized format. Their end goal is for the stored data to be easily retrievable, updated, queried, and generally easily administered via a GUI application, dashboard, or even via the command line interface.
Due to these use cases, database management systems and platforms have evolved a lot over the years. Today, we have various database-as-a-service (DBaaS) platforms, also known as managed database services. They basically provide ways of administering databases and offload the work of configuring, maintaining, and managing these databases to various cloud database services and storage providers.
All of this has coincided with the evolution of the cloud era. Using a DBaaS software means that there is no need for a user to deploy a database management system (DBMS) on-premises, since they can now be offered as managed services. DBaaS leverages all the benefits of cloud computing to ensure that the user has a small or nonexistent initial spend on infrastructure.
In this post, we’ll discuss database management systems, and how SurrealDB fits into the larger ecosystem.
Jump ahead:
One way of grouping or classifying DBMS is by their data model, i.e., the kinds of data structures supported and the manner in which the database schema is built.
As we may already know, relational databases store their data in either rows and columns or in a table-like format. Usually, these kinds of databases use SQL to interact with the data stored in them. Non-relational databases, on the other hand, are usually document-based and offer a different approach to querying the data.
Another way of classifying database systems is based on where and how the data is stored. Small databases can be stored on a file system, just like what the operating system uses, while large databases are usually hosted on computer clusters or in the cloud.
With DBaaS platforms, we can access a cloud database system without having to purchase hardware, install additional software, or even having to manage the database. All of these activities are done by the DBaaS provider, including regular upgrades, ensuring database availability at all times, and ensuring downtime is reduced to the barest levels. DBaaS, therefore, allows customers to focus on the core business operations and decisions.
Other important factors to consider when categorizing databases include:
SurrealDB is a DBaaS platform that offers a relational model for storing data. In this post we are going to take a look at its features, importance, ideal use cases, how to set it up, and the CLI. Finally, we will get to explore how the features of SurrealDB compare to other DBaaS platforms in the same category, like PostgreSQL, ScyllaDB, and CockroachDB.
According to the documentation, SurrealDB claims to be he ultimate cloud database for all different kinds of applications. It is an end-to-end, cloud-native database that works for most traditional applications, including web and mobile. It can also be used for Serverless, Jamstack, and other backend-based applications.
One of the benefits of SurrealDB is its ability to act as both a database and real-time collaborative API backend layer. What this means is that it can run as a single, plug-and-play database server. It is highly available, highly scalable, and distributed, with support for:
SurrealDB comes with an out-of-the-box, SQL-style query language known as SurrealQL. SurrealQL is rich in terms of support for real-time queries, faster and performant query processing, advanced permissions, and access control for mulit-tenant applications. SurrealDB also claims to be the next-generation database for serverless applications.
SurrealDB is NoSQL in nature, which removes the need for most server-side components and the layers that are usually required when using other kinds of database systems. It is versatile and can fit in easily into any kind of tech stack. Also, you can easily spin it up with a simple command, or even via a direct connection to a client-side application.
It also works in cases where there are a number of queries or analytics to be made on a server. In the next section, we’ll explore some more distinct features of this awesome cloud database.
Your engineering team can get up to speed with SurrealDB in no time because it is very easy to set up and use. There’s no need to spend time learning a new query language or syntax, as the manner of querying your data in previous databases works right away. It is a fast and highly performant database that scales to your desired demands. Its features include:
SELECT
, UPDATE
, CREATE
, and DELETE
methods or statements, similar to regular SQLNote: For more information regarding the different types of statements, syntax definitions, and example queries available in SurrealDB, take a look at the statements page in the documentation.
In terms of installation, there are two ways to run SurrealDB: either from Docker, or by installing the binary image, which is available for the popular operating systems.
To install and run with Docker, make sure Docker Hub is running on your machine and go ahead to pull the latest SurrealDB images from Docker Hub. To do so, run this command below:
docker run --rm -p 8000:8000 surrealdb/surrealdb:latest start
The SurrealDB image can be found here, and it contains all of the command-line tools needed to import and export data from a running server, or for running a SurrealDB server itself.
To install SurrealDB on macOS, since are making use of this operating system in this post, we can make use of the home brew package manager. See the command below:
brew install surrealdb/tap/surreal
For other operating systems, like Windows and Linux Mints, we can check out the installation page in the documentation. Once we are done with the installation, is it easy to backup, interact, and run SurrealDB instances.
Integrating to SurrealDB to perform queries is available via different methods. Many users connect via one of the supported and actively maintained client libraries, which exist for many popular programming languages. Currently, on the server side, SurrealDB supports:
On the client side, it supports WASM, JavaScript, and Ember.js. For further details on using this library, check out the documentation.
To perform SurrealDB queries, REST or HTTP methods are supported. By default, all queries are performed over HTTP API calls with support for SQL. It is easy to modify single-table records or even all table records, if need be, with the use of its HTTP endpoint. Also, we can make use of the usual HTTP endpoints to query table records with the help of SurrealQL. More details on this can be found here in the docs.
Finally, as we highlighted earlier, the WebSockets API supports JSON-RPC querying with support for persistent connection, session auth, realtime queries, and notifications.
The SurrealDB CLI can be used to import or export data from a local or remote SurrealDB instance. It can be used to manage either a single SurrealDB node or a distributed node cluster.
The start
command starts a SurrealDB server in-memory, on a disk, or in a distributed environment. Make sure to install SurrealDB before proceeding.
The import
command imports a SurrealQL script file into a local or remote SurrealDB database server. The version
command, as usual, shows the current version of the installed CLI and the machine architecture. Other available commands can be found in the documentation.
SurrealDB has support for both structured and unstructured data with an improved approach to data modeling, compared to other kinds of databases with support for only a single type of data model. It supports simple documents, documents with embedded fields, and graph connections between records. Also, it doesn’t force a specific kind of data model, and allows for both schemaful or schemaless tables, allowing you flexibility to store whatever you need.
When it comes to data querying, SurrealDB comes with a powerful set of querying capabilities. As previously mentioned, it offers a unique querying language, SurrealQL, which is a similar but modified version of traditional SQL. With SurrealQL, documents are traversed and queried efficiently, while still using a language that remains understandable by all. We can write simple SQL-like queries.
SurrealDB supports multi-column indexes that can be easily modified as your application evolves, allowing for consistent and performant read and write operations. Pre-computed table views allow for highly efficient data aggregation for known queries.
It also offers a faster app development time, with its inbuilt permissions and access control. For example, specifying permissions and making sure only those who have the appropriate rights or access are granted these permissions. Permissions for selecting, and performing all CRUD operations are supported, ensuring fine-grained control.
SurrealDB supports SSL/TLS, single-sign-on, external third party auth, JWT token-based authentication, and custom business authentication logic. It offers strong security, with the flexibility of custom authentication methods that can suit any application or business domain.
With SurrealDB, all connections are made via WebSockets, aiding bi-directional data exchange and transfer. Dependent on data access permissions, client-based document subscriptions are triggered in realtime whenever changes are made to the data.
PostgreSQL and SurrealDB are quite similar in nature, yet they provide unique feature sets that are worth looking into. While both PostgreSQL and SurrealDB are free and open source relational database management systems, PostgreSQL can be used for commercial and non-commercial projects alike.
PostgreSQL is also available for all major operating systems, including macOS, Linux, Windows, BSD, and Solaris, and has been in active development for over 30 years. It powers many of the applications we use on a daily basis. It is also more stable and has been battle tested over the years, so it is resilient and highly available with support for all kinds of mission-critical workloads.
Although PostgreSQL has issues relating to table and index bloating, it integrates with many other tools and platforms. It also supports distributed ACID transactions — i.e., ones that modify multiple rows in more than one shard — structured and unstructured data, and online/offline data synchronization.
Unlike other database platforms, SurrealDB combines the database layer, querying layer, API, and authentication layer into one platform. With SurrealDB, one very niche advantage is that there’s no need for complex database and backend setup.
SurrealDB also takes care of most security rules on your behalf. It offers an advanced table- and row-based, customizable access permissions allowing granular data access patterns for different types of users.
Other benefits include:
With SurrealDB, we can also easily extend our database with JavaScript and Wasm functions. This allows for an advanced, custom functionality with computation logic being moved to the data layer. This removes the need to move data to client devices, so as to carry out regular computational workloads. Therefore, only the necessary data is transferred upstream.
With database management systems, we can perform all actions required of databases via a GUI. With these GUIs, we can have a bird’s-eye view of all the data in our database for easy analysis of either the schema or data types, and generally an easy way of administering these databases.
SurrealDB reduces the development time for modern applications because it helps to simplify the entire database and API stack, removing the need for most server-side components. This way, you can easily build secure and performant apps quickly and cheaply. With its design, it can also run in all types of environments, designed to be embedded or run in a distributed manner in the cloud.
With SurrealDB, common traditional database issues like provisioning, scaling, sharding, replication, and correctness are all taken care of. Additionally, because it is a cloud-hosted database, when it comes to hosting or deploying, it becomes an easy job because SurrealDB can be deployed anywhere, even on the SurrealDB Cloud itself. In general, it can be hosted in the cloud, on-premises, embedded, and in edge computing environments.
When it comes to database administration, including general admin and user management, enforcing data security and control, performance monitoring, maintaining data integrity, dealing with concurrency transactions, and recovering information in the case of events such as an unexpected system failure, SurrealDB is the solution.
Install LogRocket via npm or script tag. LogRocket.init()
must be called client-side, not
server-side
$ npm i --save logrocket // Code: import LogRocket from 'logrocket'; LogRocket.init('app/id');
// Add to your HTML: <script src="https://cdn.lr-ingest.com/LogRocket.min.js"></script> <script>window.LogRocket && window.LogRocket.init('app/id');</script>
Hey there, want to help make our blog better?
Join LogRocket’s Content Advisory Board. You’ll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag.
Sign up nowBuild scalable admin dashboards with Filament and Laravel using Form Builder, Notifications, and Actions for clean, interactive panels.
Break down the parts of a URL and explore APIs for working with them in JavaScript, parsing them, building query strings, checking their validity, etc.
In this guide, explore lazy loading and error loading as two techniques for fetching data in React apps.
Deno is a popular JavaScript runtime, and it recently launched version 2.0 with several new features, bug fixes, and improvements […]