Fork me on GitHub
#clojure
<
2022-04-03
>
Shuky Badeer05:04:26

Hii guys! We're writing a clojure backend these days. The only missing piece of the puzzle is the database. What database is commonly used with clojure? I know that Datomic goes hand in hand with clojure but I find it strange that big companies use clojure without Datomic. So I wonder, in practicaliy, which database should we use?

jumar05:04:34

Many people use traditional rdbms like MySQL, PostgreSQL, etc. There's next.jdbc library for that. Some (much fewer?) people use Datomic or XTDB (former Crux) if they have a need for the features they offer.

Shuky Badeer05:04:51

@U06BE1L6T thank you for the info. Datomic offers the immutable feature which is nice, but it proves to be slow in terms of querying large datasets. That's why we're skeptical about it

jumar05:04:40

I never used these in production but Datomic and/or XTDB are something I would like to try seriously at some point. However, I saw people migrated from Datomic to PostgreSQL because of performance and costs. If you think you need Datomic's features I guess you have to judge it depending on your own context

👍 2
jumar05:04:57

Maybe @U0KD0N5T5 can give you additional info - I know he talked about this stuff in #clojure-czech a long time ago.

👍 1
leifericf07:04:58

In their podcast, https://clojuredesign.club (#clojuredesign-podcast), @U5FV4MJHG and @U0510902N mention https://www.mongodb.com several times. But I suppose whether you need a “traditional” relational database or “NoSQL” or graph database depends on the particular problem and application. In addition to Datomic, you might want to check out https://github.com/threatgrid/asami (#asami) by our friend @U051N6TTC. What kind of data are you working on within your application, if I may ask? Perhaps that might help inform your choice.

👍 1
leifericf07:04:08

Another database I find particularly interesting because of its decentralization capabilities is https://couchdb.apache.org. If you have many distributed servers or clients, they can work on their own “local replica” of the database, even without an internet connection. When the internet connection comes back up, they will sync automatically. It’s like a non-ephemeral writable cache. This is made possible by the facilities of Erlang/OTP and the BEAM, upon which CouchDB is built. One use case that comes to mind is brick-and-mortar retail, where hundreds of distributed stores need to manage the same product master data even if the store has an unstable internet connection.

👍 1
jumar09:04:25

There was a good discussion in #off-topic recently about why people don't like mongo much https://clojurians.slack.com/archives/C03RZGPG3/p1648698585403029

leifericf12:04:36

Thanks for the link, @U06BE1L6T! I’m adding it to my to-read list!

borkdude12:04:25

PostgreSQL would be my favorite if you're not going for a datalog db.

💡 1
👍 1
leifericf12:04:01

@U04V15CAJ, are there any particular aspects of PostgreSQL which make it a better fit for Clojure projects than other SQL databases? Other than just being a “better” SQL database in general.

borkdude12:04:07

More reliable than MySQL, for one.

borkdude12:04:58

Unscientific answer, but it just feels more mature to me than any other OSS relational database.

leifericf13:04:41

Yeah, I get that! I would also opt for PostgreSQL (even if I wasn’t using Clojure). I was just curious if some aspects of PostgreSQL made it better for Clojure in particular.

borkdude13:04:39

Nothing specific to Clojure (until I get the dust off this thing: https://github.com/borkdude/plsci)

👀 1
😮 1
borkdude13:04:59

In my previous job we used PostgreSQL together with ZomboDB which worked pretty well: it's a plugin that syncs it with ElasticSearch

leifericf13:04:41

Never heard of ZomboDB! I’ll have a peek.

leifericf13:04:56

We use SAP HANA (yuk!), Oracle Database (operations), and Snowflake (analysis) for structured and semistructured data in my current job. And Azure Blob Storage for unstructured stuff, like binaries, etc. Oh, and Kafka, which functions as a database in some scenarios if you squint your eyes and look at it from a weird angle. Before learning about Clojure, I played around with Neo4j at work for data science stuff… But now I think I’ll try Datomic (if I can convince my employer to buy it) or Asami instead.

neumann23:04:48

@U01PE7630AC @U033V0AJFU4 I have used MongoDB quite a lot, but that is due to historical choices for myself and the projects I've worked on. For any new project that needs a relational database, I pick PostgreSQL these days. PostgreSQL also supports JSON for non-relational use. I'd love to use a datalog-style DB, but I haven't had occasion to use one yet.

👍 1
Joshua Suskalo23:04:42

I'll admit I'm really curious about the comparison of performance between datomic and datahike on postgres

didibus23:04:56

I'm surprised to hear about slow performance on queries on Datomic? Do you have source for that? As far as I know, writes is the bottleneck, due to single writer design, but reads can be scaled horizontally, so maybe you mean individual queries are still too slow? But at least in theory it should scale out easily.

didibus23:04:11

There's not really anything special about Clojure when it comes to DB choice. So choose your DB the same way you'd do for whatever the language you use. At my work we use AWS DynamoDB and S3 primarily for our operational use cases, with ElasticSearch for cross-record queries.

didibus23:04:11

In the open-source, for relational, you can't go wrong with MySQL or MariaDB or PostgressSQL. PostgressSQL also has nice support for document store, and it has some nice relational features too that at least used to be missing from MySQL, like proper constraint enforcement of foreign keys. I also know a lot of people using Cassandra and CouchDB quite successfully as well, so those are good candidate to consider.

devn00:04:07

while i think it’s fair to say there is nothing special about clojure w/r/t DB choice, the ergonomics of use certainly vary