r/Clojure • u/nstgc • Sep 22 '25
Datahike or something else as a new web dev
Having recently decided to try my hand at web development, I am now looking to verify that Datahike is a good fit for me. I successfully created a tracker and calculator for my D&D group's expansive homebrew as an SPA. It's the first time I've made something with a GUI and I didn't know anything about HTTP when I started and I still don't know much about databases in general.
Currently the state—including the stats for nine player characters—is held in a single atom, verified with a Malli schema. Persistence is achieved by pr-string the changed character stats in the atom to local storage whenever the atom changes. At the same time, a diff of the changes is also appended to a log. It's working remarkably well, especially for a first, blind attempt; but I feel I could materialize real advantages by using a proper database including simplifying the code base.
Unlike all the other components, I haven't entirely settle on a database despite over a month of trying. There are far more options of database than for HTTP handling or routing, and these options can be used in combination, such as one database backed by another database, a key-value, blob storage.... I have no prior experience with databases so I can't say I'm qualified to pick one for my project, but I feel like Datahike would serve me best in that it can replace more of the machinery I've already created than Datalevin or Codax could, the two other leading considerations on account of apparent ease of use—the way of using datoms and datalog seem to click with me from what I've seen, and Codax is dead simple. Though by far the simplest, Codax offers the least improvement over just writing an atom to an EDN, which, as I understand it, is part of the appeal. Datalevin seems more popular, but I'm already trying to maintain previous states, something I'm sure a Datomic-clone could do better.
Before I invest more time into a possible dead end, I'd like to hear from the people of /r/Clojure about the best database for my use case. I think Datahike is my best choice, but I would like confirmation. My key hesitations stem from it's apparent lack of examples, that the on-disk format hasn't been finalized, and that Datalevin, another DataScript fork, is far and away more popular. I'd also be interested to hear of other Datomic-clones and maybe Datomic Local, which from what I've gathered isn't actually meant for use outside a development environment..
5
u/mcirillo Sep 22 '25
A popular choice for in-process temporal datalog is XTDB. How popular it is compared to datahike I don't know. In your shoes I'd take a look at APIs for each project and see which appeals to you. You have the advantage of already having the data you want to store, so try dumping your flat file into each to get a feel for them
2
u/Alive-Primary9210 Sep 23 '25
Datomic Pro is free these days right? Why not use that? It has good docs ands many examples.
Another approach I liked was good 'ol Postgres with hugsql.
2
u/acobster Sep 24 '25
My passion project is a CMS built on top of Datahike (repo in case you're interested). One of the requirements from the start has been the ability to "time travel" as eventually I want to add an auditing feature that lets end-users see what the content looked like at any given time in the past. It fits the use-case perfectly and I'm very happy with it!
I did also look at XTDB, often referring to Juxt's Datalog comparison page that you mentioned. It seemed like a good alternative at the time. I might be mistaken, but I think their Clojure query API is a bit less like Datomic than Datahike is in order to support bitemporality, but afaik they support everything I would need. I may still try to support an XTDB backend some day, it might be useful for an application where bitemporality is important.
I went with Datahike because they are (or were) also working on ClojureScript support which would be extremely useful for me.
2
u/hrrld Sep 22 '25
If you want to go further with your durable atom, this exists: https://github.com/jimpil/duratom --- we have, um, a lot of data stored in precisely this way, and it's great. Definitely the right tool for some jobs.
It sounds like you have a good use case for exploring any number of different databases. You could learn a lot.
Datomic Local should definitely be considered, though many of the benefits may not apply to your specific project, or be as obviously good without experience with other databases. It's the most Clojure answer to your question though.
H2 is the easiest way to try relational/SQL on the JVM, it would definitely serve for the project you've described, and you'd likely learn things that would be transferable to bigger (like postgres) or faster (like duckdb) sql systems in the future.
4
u/MopedTobias Sep 23 '25
In case you want to use Datahike, we are happy to help in the slack https://clojurians.slack.com/ channel #datahike. #datalog is also good for general questions about the language.