Using Datahike's Java API To Build a Web Application

The goal of this article is to introduce Datahike's Java API. To do so we will create a small web application together. The figure below illustrates the application architecture and lists some of the core advantages of using Datahike. Datahike is an open source, light-weight Datalog runtime with durable and auditable storage. It has an efficient query engine and is written in Clojure. On the left we can see the Spring Boot based application interacting with Datahike's Java API through its Controllers. Since Clojure is also hosted on the JVM, objects such as lists or functions can be transparently passed into Datahike's runtime.
Application structure


There are good reasons for using a Datalog database like Datahike. First, it is simple. It is a very small, well-factored core codebase (< 5000 lines of code) of a few core concepts. This allows it to be flexibly recomposed and integrated with existing data sources in novel ways. Furthermore, it is more declarative than SQL by its roots in logic programming languages like Prolog, which provide first-class support for implicit binding by logic variables. Because of its support for recursion, it is also strictly more expressive than pure relational algebras such as those described by SQL. Compared to non-functional databases, Datahike provides coordination-free read scaling by automatically snapshotting all write operations. These snapshots can be read in parallel in each JVM runtime context of an arbitrary number of reading processes. It can also be audited at any point in time like git. Datahike requires only Java dependencies and can be used in-memory, with a simple file-based backend, with Redis for high throughput, with auto-scaling cloud infrastructure like AWS S3 and DynamoDB, or with all of these backends combined in one query context.