If You’d Had To Pick One: Datalevin

Sure, it’s typical for a company to use many different databases. At BigCo scale the right tool for the job trumps developer convenience. But what if we’re talking about a small startup or even a personal knowledge management tool? There you’d want a super-DB that brings many of the features of other databases together in one.

Let’s have a look at what these features are:

  • relationships (incl. graphs)
  • document storage
  • blob storage
  • a powerful query engine (supporting graph traversal)
  • runs locally and remotely
  • great performance
  • simplicity

You’d think a short list like that would get checked off by at least a few databases. Wrong. Many check about 5/7 but until now I’ve found none that checks all.

Enter Datalevin

I’ve been using Datalevin for over a year now. It’s very fast, can run locally (even on your phone) and remotely. It uses a Datalog-inspired query engine that allows for incredibly powerful queries. Its Entity API enables graph traversal. It stores gigabyte-sized blobs without a peep and it’s very easy to set up. In short, it does everything I need. If I’d had to pick one, as is often the case early on in projects, this would be the one.
📣 Shout out to Huahai Yang for single-handedly helming a project of this breadth!

Datalevin just shipped a server mode for remote use. A remote instance allows you to use one database across many projects over the wire. Don’t worry you can still have separate stores for each project inside that database. Here’s how you set it up.

  1. get a droplet running a recent LTS version of ubuntu (I use digital ocean)
  2. ssh into it ssh root@my.ip.address
  3. (if you want to mount a separate hard drive (to physically decouple data from the processing machine) follow the instructions of your hosting provider)
  4. make a user adduser myusername sudo
  5. switch to that user su — myusername
  6. install homebrew sudo apt-get update and paste the install script from brew.sh
  7. install datalevin brew install huahaiy/brew/datalevin
  8. pick a data-directory for the DB and make sure your user has read/write permissions sudu chmod a+rw /path/to/your/mounted-drive
  9. run dtlv serv -r /path/to/your/mounted-drive

And there you have a remote Datalevin database. Now any client can connect to it with a few lines of Clojure code:

(require '[datalevin.core :as d])(def conn


That was easy, right? Okay a few more steps:

At this point for security reasons, you should change the main password of the DB as outlined here.

If your process quits or server restarts for some reason, you should make sure the DB restarts. You can achieve this with systemd. First sudo nano /etc/systemd/system/datalevin.service

Then paste

Description=Datalevin service
ExecStart=/home/linuxbrew/.linuxbrew/bin/dtlv serv -r /path/to/your/mounted-drive

That’s it. Now when your machine restarts it will always start the DB as well.

Please leave suggestions to improve this blog post. I’ll happily incorporate them. For questions and thoughts DM/follow on twitter and as always a big thanks to the Clojure community!