Reader small image

You're reading from  Microservices with Clojure

Product typeBook
Published inJan 2018
Reading LevelIntermediate
PublisherPackt
ISBN-139781788622240
Edition1st Edition
Languages
Right arrow
Author (1)
Anuj Kumar
Anuj Kumar
author image
Anuj Kumar

Anuj Kumar is the co-founder and chief architect of FORMCEPT, a data analytics startup based in Bangalore, India. He has more than 10 years of experience in designing large-scale distributed systems for storage, retrieval, and analytics. He has been in industry hacking, mainly in the area of data integration, data quality, and data analytics using NLP and machine learning techniques. He has published research papers at ACM conferences, got a few patents granted, and has spoken at TEDx. Prior to FORMCEPT, he has worked with the Oracle Server Technologies division in Bangalore, India.
Read more about Anuj Kumar

Right arrow

Chapter 7. Achieving Immutability with Datomic

"Most of the biggest problems in software are problems of misconception."

- Rich Hickey

Microservices depend on the underlying database to reliably store and retrieve data. Often applications like Helping Hands need to store user transactions consistently along with user locations that may change over time. Instead of updating the user location permanently and losing the history of the changes, a good application must maintain the change in data so that it can be queried over time. Such requirements expect the data stored in the database to be immutable. Datomic (http://www.datomic.com/) is one such database that not only provides durable transactions but also has the concept of immutability built into its core so that users can query the state of the database over a period of time. Datomic is also written in Clojure, which is the technology stack of choice for the Helping Hands application. In this chapter, you will learn about the following...

Datomic architecture


Datomic is a distributed database that supports ACID (http://docs.datomic.com/acid.html) transactions and stores data as immutable facts. Datomic is focused on providing a robust transaction manager to keep the underlying data consistent, a data model to store immutable facts, and a query engine to help retrieve data as facts over time. Instead of having its own storage, it relies on an external storage service (http://docs.datomic.com/storage.html) to store the data on disk.

Datomic versus traditional database

A typical database is implemented as a monolithic application that contains the storage engine, query engine, and the transaction manager all packaged as a single application to which clients connect to store and retrieve data. Datomic, on the other hand, takes a radical approach of separating out the Transaction Manager (Transactor) as a separate process to handle all the transactions and commit the data to an underlying Storage Service that acts as a persistence...

Using Datomic


Datomic can be downloaded freely from its Get Datomic (http://www.datomic.com/get-datomic.html) website. To start with Datomic, download the Datomic free edition that includes a memory database and embedded Datalog query engine. The free edition is also limited to two simultaneous peers and embedded storage that should be good enough to try out Datomic features and work with its data model.

Getting started with Datomic

To set up Datomic, download and extract the free edition's datomic-free-x.x.xxxx.xx.zip file. The free version of Datomic does not require any license key. For other versions, registration is mandatory to obtain a license key which must be added to transactor properties for Datomic to work. Datomic distribution contains two JARs, datomic-free-x.x.xxxx.xx.jar and datomic-transactor-free-x.x.xxxx.xx.jar. The datomic-free JAR file contains a peer library and datomic-transactor contains the implementation of the transactor. The distribution also contains a bin folder...

Summary


In this chapter, we learned about Datomic architecture and how it is radically different from traditional databases. We learned about its data model and how it stores datoms. We also learned how to retrieve facts with Datomic APIs and its Datalog-based query engine. We also looked at its immutability constructs and how to query databases in current as well as historical states.

In the next part of this book, we will focus on the implementation of microservices for the Helping Hands application, which will use Pedestal as the base framework to design APIs and Datomic for persistence.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Microservices with Clojure
Published in: Jan 2018Publisher: PacktISBN-13: 9781788622240
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Anuj Kumar

Anuj Kumar is the co-founder and chief architect of FORMCEPT, a data analytics startup based in Bangalore, India. He has more than 10 years of experience in designing large-scale distributed systems for storage, retrieval, and analytics. He has been in industry hacking, mainly in the area of data integration, data quality, and data analytics using NLP and machine learning techniques. He has published research papers at ACM conferences, got a few patents granted, and has spoken at TEDx. Prior to FORMCEPT, he has worked with the Oracle Server Technologies division in Bangalore, India.
Read more about Anuj Kumar