Why should you use Datomic?
Tags: datomic, database, architecture, clojure
Published: 2023-10-09 00:25:17

A few months ago I got into a new project that was basically a challenge for me. Basically, to really work on new features, fix bugs and improve the code, I needed to learn Clojure and Datomic.

It was a challenge for me because I've never worked with the Functional way of programming since I started studying, in fact, I've never gone deeper to understand what was that and why people were using it.

And after studying Clojure for at least 2 months and getting a good amount of knowledge, the need of understanding Datomic and its queries came up, so I started studying and here are the most important points about it that I've chosen to bring, hope you enjoy it.


## Why Datomic?
Well, we can start with the fact that Datomic has the ACID guarantees which improves the reliability and integrity of the actions performed.

Differently from other common databases, datomic internal logic is based on facts(datoms), so every action(transaction) you perform on Datomic, you’re actually handling facts instead of handling a specific line of a table that only returns the latest state of it.

The information above implies another characteristic of Datomic, the data of older transactions doesn’t get lost. This guarantees the need to investigate the past of a specific entity in a given time, which is very helpful when debugging.

## As Datomic never erases the data of transactions, DOESN’T IT FILL THE MEMORY QUICKLY?
Yes, you’re right, datomic was designed to work with large datasets of memory, but you think about it,it’s worth it, because if in one year you have a certain amount of data stored, in the next year, it won't grow so much that that.

## How does Datomic manage to retrieve the data as it becomes BIGGER? 
Datomic was designed to support large data and because of that, the way that the data is stored in memory was designed to work with a high performance to retrieve the data. You can see more about it here: [Datomic Large Data Sets](https://docs.datomic.com/cloud/whatis/architecture.html#large-data-sets)

## What kind of projects is Datomic more useful for?
Analyzing the project that you are wondering, in order to choose if Datomic would be the one to choose, you might need to ask yourself some question: 
- If a database action that my project fails, is it a huge problem?
- Is it ok with using Clojure language on the server side of the project?

## Conclusion:
Seeing Datomic as a "Database as a value", I like the fact that when we perform transactions in Datomic, for example, updating an attribute of a entity, it actually creates at least new three facts, one is the updated fact, the second is the older fact that got updated and the third one is the transaction with the instant and some other attributes of the transaction. It really guarantees you the possibility to visit the older data and analyze things, and also allows you to choose if you want to include in the transaction fact who made that transaction, so that’s AMAZING.

Another good point is that when you need to make any decision related to your project, would you be able to decide it just knowing what has happened now? It will be really difficult to analyze the past and have really good decisions.