News for hackers. Stuff that matters.
Re:Datomic Is Now Free by augustl on Thursday April 27, 2023 @09:54AM (#35728143)
Datomic's is perfect for probably 90% of small-ish backoffice systems that never has to be web scale (i.e. most of what I do at work).

Writing in a single thread removes a whole host of problems in understanding (and implementing) how data changes over time. (And a busy MVCC sql db spends 75% of its time doing coordination, not actual writes, so a single thread applying a queue of transactions in sequence can be faster than your gut feeling might tell you.)

Transactions as first-class entities of the system means you can easily add meta-data for every change in the system that explains who and why the change happened, so you'll never again have to wonder "hmm, why does that column have that value, and how did it happen". Once you get used to this, doing UPDATE in SQL feels pretty weird, as the default mode of operation of your _business data_ is to delete data, with no trace of who and why!

Having the value of the entire database at a point in time available to your business logic as a (lazy) immutable value you can run queries on opens up completely new ways of writing code, and lets your database follow "functional core, imperative shell". Someone needs to have the working set of your database in memory, why shouldn't it be your app server and business logic?

Looking forward to see what this does for the adoption of Datomic!

Re:Datomic Is Now Free by electroly on Thursday April 27, 2023 @10:36AM (#35728794)
> Someone needs to have the working set of your database in memory, why shouldn't it be your app server and business logic?

This one confused me. The obvious reason why you don't want the whole working set of your database in the app server's memory is because you have lots of app servers, whereas you only have one database[1]. This suggests that you put the working set of the database in the database, so that you still only need the one copy, not in the app servers where you'd need N copies of it.

The rest of your post makes sense to me but the thing about keeping the database's working set in your app server's memory does not. That's something we specifically work to avoid.

[1] Still talking about "non-webscale" office usage here, that's the world I live in as well. One big central database server, lots of apps and app servers strewn about.

Re:Datomic Is Now Free by NovemberWhiskey on Thursday April 27, 2023 @10:41AM (#35728875)
I think the point is that treating your database as an arms-length, RPC component that's independent from your "application" isn't necessarily the only pattern.
Re:Datomic Is Now Free by foobiekr on Thursday April 27, 2023 @11:03AM (#35729211)
Strong agree. there are vast, massive cost savings and performance advantages to be had if the model is that a shard of the dataset is in memory and the data persistence problem is the part that's made external. The only reason we are where we are today is that doing that well is hard.
Re:Datomic Is Now Free by bombolo on Friday April 28, 2023 @06:04AM (#35739394)
If it's in memory you must live with the fact that it might be gone at any moment though.
Re:Datomic Is Now Free by foobiekr on Friday April 28, 2023 @11:31AM (#35742478)
Hence "the data persistence part."
Re:Datomic Is Now Free by robertlagrant on Friday April 28, 2023 @12:09PM (#35743233)
This sounds like a write-back / write-through cache with extra terminology. What's the difference?
Re:Datomic Is Now Free by foobiekr on Friday April 28, 2023 @04:13PM (#35746501)
The difference is the 10,000x slower performance if you move the actual DB transaction leader for the shard to over-the-wire access.

Anything can be anywhere if we ignore latency and throughput.

Re:Datomic Is Now Free by robertlagrant on Tuesday May 02, 2023 @04:30AM (#35784791)
I'm not saying that. I'm asking if this is just new terminology for a previous technology idea, or whether it's a new concept.
Re:Datomic Is Now Free by robertlagrant on Friday April 28, 2023 @08:57AM (#35740715)
Is this not the case already? Database drivers (or just your application code) are allowed to cache results if they like. The problem is cache invalidation.
Re:Datomic Is Now Free by foobiekr on Friday April 28, 2023 @11:31AM (#35742492)
Caches aren't the same. In the shard-in-memory case, the shard is the thing serving the queries, meaning it's not a cache it _is_ the live data.
Re:Datomic Is Now Free by robertlagrant on Friday April 28, 2023 @12:08PM (#35743213)
Understood. For a single-node or read-only system it sounds fine, but then there are a variety of ways to solve that (e.g. a preloaded in-memory sqlite).
Re:Datomic Is Now Free by augustl on Thursday April 27, 2023 @11:01AM (#35729171)
It's definitely a trade-off! If you have 10s or 100s of app servers that has the exact same working set in memory, it's probably not worth it.

But if you have a handful of app servers, it's much more reasonable. The relatively low scale back-office systems I tend to work with typically has 2, max 3. Also, spinning up an extra instance that does some data crunching does not affect the performance of the app servers, as they don't have to coordinate.

There's also the performance and practicality benefits you get from not having to do round-trips in order to query. You can now actually do 100 queries in a loop, instead of having to formulate everything as a single query.

And if you have many different apps that operates on the same DB, it becomes a benefit as well. The app server will only have the _actual_ working set it queries on in memory, not the sum of the working set across all of the app servers.

If this becomes a problem, you can always architecture your way around it as well, by having two beefy API app servers that your 10s or 100s of other app servers talks to.

Re:Datomic Is Now Free by electroly on Thursday April 27, 2023 @11:28AM (#35729584)
SQLite provides a similar benefit with tremendous results using its in-process database engine, although the benefit there is more muted by default because of the very small default cache size. We do have one app where we do this. There's no database server, the app server uses SQLite to talk directly to S3 and the app server itself caches its working set in memory. I can definitely see the benefit of some situations, but for us it was a pretty unusual situation that we might not ever encounter again.

All that said... can't Datomic also do traditional query execution on the server? I thought it had support for scale-out compute for that. AIUI, you have the option to run as either a full peer or just an RPC client on a case-by-case basis? I thought you wouldn't need to resort to writing your own API intermediary, you could just connect to Datomic via RPC, right?

Re:Datomic Is Now Free by carry_bit on Thursday April 27, 2023 @01:22PM (#35731483)
AIUI, the full peer is Datomic; the RPC server is just a full peer that exposes the API over http and is mainly intended to be used with clients that don't run on the JVM (and so can't run Datomic itself in-process).
Re:Datomic Is Now Free by xmlblog on Thursday April 27, 2023 @01:22PM (#35731471)
> If you have 10s or 100s of app servers that has the exact same working set in memory, it's probably not worth it.

The introduction of intelligent application-level partitioning [1] and routing schemes can help one balance cost and performance.

[1] https://blog.datomic.com/2023/04/implicit-partitions.html

Re:Datomic Is Now Free by dimitar on Thursday April 27, 2023 @11:39AM (#35729730)
Consider this use case - in addition to your web app, you have a reporting service that makes heavy duty reports; if you run one at a bad time, bad things might happen like users not being able to log in or do any other important work, because the database is busy with the reports.

So in a traditional DB you might have a DBA set up a reporting database so the operational one is not affected. Using Datomic the reporting service gets a datomic peer that has a copy of the DB in database without any extra DBA work and without affecting any web services. This also works nicely with batch jobs or in any situation where you don't want to have different services affect each others performance.

Its true that a lot more memory gets used, but it is relatively cheap - usually the biggest cost when hosting in the cloud being the vCPUs. But usually in Clojure/Datomic web application you don't need to put various cache services like Redis in front of your DB.

Thea assumption here is that the usual bottleneck for most information systems and business applications is reading and querying data.

Re:Datomic Is Now Free by electroly on Thursday April 27, 2023 @12:28PM (#35730559)
I appreciated this insight into other people's use cases, thank you for that! This architecture brings RethinkDB to mind, which also had some ability to run your client as a cluster node that you alone get to query. (Although there it was more about receiving the live feed than about caching a local working set.)
Re:Datomic Is Now Free by thewataccount on Thursday April 27, 2023 @02:20PM (#35732412)
Is RethinkDB still around?

They actually have recent commits, and a release last year.

Re:Datomic Is Now Free by electroly on Thursday April 27, 2023 @02:30PM (#35732556)
The company is gone, but the open source project lives on. We still use it in production.
Re:Datomic Is Now Free by thewataccount on Thursday April 27, 2023 @02:48PM (#35732824)
How's it been for production?

Would you recommend using it, or would it be better to go with a safer option?

Re:Datomic Is Now Free by electroly on Thursday April 27, 2023 @03:00PM (#35732993)
We've never had any issue with it on a typical three-node install in Kubernetes. It requires essentially no ongoing management. That said, it can't be ignored that the company went under and now it's in community maintenance mode. If you don't have a specific good use for Rethink's changefeed functionality, which sets it apart from the alternatives, I'm not sure I could recommend it for new development. We've chosen not to rip it out, but we're not developing new things on it.
Re:Datomic Is Now Free by thewataccount on Thursday April 27, 2023 @03:35PM (#35733434)
Interesting thank you!

I remember back when it came out it was a big deal that it could easily scale master-master nodes and the object format was a big thing because of Mongo back then.

That was before k8's wasn't a thing back then, and most of the failover for other databases wasn't a thing just yet. I'm too scared to use it because they have a community but they're obviously nowhere as active as the Postgres and other communities.

Re:Datomic Is Now Free by jwr on Friday April 28, 2023 @06:56AM (#35739701)
RethinkDB user here. I've been running it in production for the last 8 years or so. It works. It doesn't lose data. It doesn't corrupt data (like most distributed databases do, read the Jepsen reports).

I am worried about it being unmaintained. I do have some issues that are more smells than anything else — like things becoming slower after an uptime of around three weeks (I now reboot my systems every 14 days). I could also do with improved performance.

I'm disappointed that the Winds of Internet Fashion haven't been kind to RethinkDB. It was always a much better proposition that, say, MongoDB, but got less publicity and sort of became marginalized. I guess correct and working are not that important.

I'm slowly rebuilding my application to use FoundationDB. This lets me implement changefeeds, is a correct distributed database with fantastic guarantees (you get strict serializability in a fully distributed db!), and lets me avoid the unneeded serialization to/from JSON as a transport format.

Re:Datomic Is Now Free by svieira on Thursday April 27, 2023 @02:36PM (#35732662)
> which also had some ability to run your client as a cluster node that you alone get to query

FoundationDB does this as well.

Re:Datomic Is Now Free by bsaul on Friday April 28, 2023 @05:17AM (#35739136)
Do you have a pointer to some doc explaining how to do that in foundationdb ?
Re:Datomic Is Now Free by svieira on Friday April 28, 2023 @10:08AM (#35741427)
https://blog.the-pans.com/notes-on-the-foundationdb-paper/ is one:

> Client (notice not Proxy) caches uncommitted writes to support read-uncommitted-writes in the same transaction. This type of read-repair is only feasible for a simple k/v data model. Anything slightly more complicated, e.g. a graph data model, would introduce a significant amount of complexity. Caching is done on the client, so read queries can bypass the entire transaction system. Reads can be served either locally from client cache or from storage nodes.

Re:Datomic Is Now Free by tyre on Thursday April 27, 2023 @03:35PM (#35733424)
With AWS you can create a replica with a few clicks. Latency is measured in milliseconds for the three-nines observed usage.

I don’t think this is a huge challenge (anymore) for Postgres or whatever traditional database.

Re:Datomic Is Now Free by augustl on Thursday April 27, 2023 @03:38PM (#35733469)
A few milliseconds per query adds up if you're doing one query per item in a list with 100s or 1000s of elements :)
Re:Datomic Is Now Free by tyre on Thursday April 27, 2023 @09:33PM (#35736572)
ah okay. in that case add in a couple hours to refactor those N+1 queries and you’re all good
Re:Datomic Is Now Free by bt1a on Thursday April 27, 2023 @11:36PM (#35737210)
when do you ever have to do one query per array of items? genuinely curious
Re:Datomic Is Now Free by augustl on Friday April 28, 2023 @01:26AM (#35737738)
I suppose I think of this the other way around. When the query engine is inside your app, it doesn't have to invent a way for the query engine to do loop-like things. So you can have a much simpler querying language and mix it with plain code, kind of similar to how you don't need a templating language in React (and in Clojure when you use hiccup to represent HTML)
Re:Datomic Is Now Free by robertlagrant on Friday April 28, 2023 @08:55AM (#35740701)
> A few milliseconds per query adds up if you're doing one query per item in a list with 100s or 1000s of elements :)

If you're doing this, then you need to stop :)

Re:Datomic Is Now Free by dimitar on Thursday April 27, 2023 @06:22PM (#35735291)
That is a read replica, datomic peers can do writes as well, which further expands the possible use cases.
Re:Datomic Is Now Free by xmlblog on Thursday April 27, 2023 @01:16PM (#35731393)
Having the working set present on app servers means they don't put load on a precious centralized resource which becomes a bottleneck for reads. The peer model allows app servers to service reads directly, avoiding the cost of contention and an additional network hop, allowing for massive read scale.
Re:Datomic Is Now Free by bruiseralmighty on Thursday April 27, 2023 @02:41PM (#35732718)
This is true, but the tradeoff is that now your central DB is a bottleneck that is difficult to scale.

Having the applications keep a cached version of the db means that when one of them runs a complex or resource intensive query, it's not affecting everyone else.

Re:Datomic Is Now Free by fulafel on Thursday April 27, 2023 @10:54AM (#35729063)
> Someone needs to have the working set of your database in memory, why shouldn't it be your app server and business logic?

This is Ions in the Cloud version, or for on-prem version the in-process peer library.

Re:Datomic Is Now Free by Scarbutt on Thursday April 27, 2023 @11:26AM (#35729553)
Datomic's is perfect for probably 90% of small-ish backoffice systems that never has to be web scale

How do they scale it for Nubank? (millions of users)

Re:Datomic Is Now Free by augustl on Thursday April 27, 2023 @11:32AM (#35729647)
Good question! I don't have any personal experience in that regard. I would probably have paid up for enterprise support (or bought the entire company ;))
Re:Datomic Is Now Free by ithrow on Thursday April 27, 2023 @04:47PM (#35734323)
I don't how they do it, but the obvious answer is probably sharding. Their cloud costs must be no joke. Peers require tons of memory and I can only guess they must have thousands of transactors to support that workload and who knows how many peers. Add to this that they probably need something like Kafka for integrating/pipelining all this data.
Re:Datomic Is Now Free by outworlder on Thursday April 27, 2023 @06:10PM (#35735195)
> Peers require tons of memory

As do most distributed databases. Even when you don't store your entire database (or working set) in memory, you'll likely still have to add quite a bit of memory to be used as I/O cache.

Re:Datomic Is Now Free by bhurlow on Saturday April 29, 2023 @01:10PM (#35754832)
sharding, microservices, they run many instances of Datomic to handle different functionality
Re:Datomic Is Now Free by xpe on Thursday April 27, 2023 @11:42AM (#35729769)
> Datomic's is perfect for probably 90% of small-ish backoffice systems that never has to be web scale (i.e. most of what I do at work).

I don’t think I agree with this as stated. It is too squishy and subjective to say “perfect”.

More broadly, the above is not and should not be a cognitive “anchor point” for reasonable use cases for Datomic. Making that kind of claim requires a lot more analysis and persuasion.

Re:Datomic Is Now Free by augustl on Thursday April 27, 2023 @12:04PM (#35730158)
I agree, I mostly phrased it that way for effect. My "analysis" is 100% subjective, opinionated and anecdotal :)
Re:Datomic Is Now Free by pachico on Thursday April 27, 2023 @12:31PM (#35730612)
You seem to describe the Event Source paradigm rather than a database :)
Re:Datomic Is Now Free by augustl on Thursday April 27, 2023 @12:39PM (#35730737)
The main difference between event sourcing and datomic are the indexes and the "schema", which provides full SQL-like relational query powers out of the box, as well as point-in-time snapshots for every "event" (transaction).
Re:Datomic Is Now Free by samuell on Thursday April 27, 2023 @12:35PM (#35730665)
Question to people having used Datomic:

Based on experience with Prolog, I always thought using Datalog in a database like Datomic would mean being able to model your data model using stored queries as a very expressive way of creating "classes". And that by modeling your data model using nested such queries, you alleviate the need for an ORM, and all the boilerplate and duplication of defining classes both in SQL and as objects in OO code ... since you already modelled your data model in the database.

Does Datomic live up to that vision?

Re:Datomic Is Now Free by gleenn on Thursday April 27, 2023 @01:49PM (#35731929)
Clojure in general is all about passing around little maps of data and in particular not using OO to model. So Datomic naturally continues that by returning maps of nested structures to represent your query results and does side-step the ORM completely.
Re:Datomic Is Now Free by PreachSoup on Thursday April 27, 2023 @02:36PM (#35732656)
Question: What's the difference between nested oop objects (composition over inheiritance) vs maps of nested structures?
Re:Datomic Is Now Free by gleenn on Thursday April 27, 2023 @02:49PM (#35732835)
Rich Hickey has a great talk about how Objects are data structures with unique interfaces that are unnecessary complexity. He showed and example of a web server with a web request object with request headers etc etc. Doing simple things like collecting information out of that nested object structure is bespoke and harder than it should be for no real gain. If everything is a map or list or set, it becomes completely trivial to extract and manipulate data from a structure. It's a subtle difference at first but when everything is like that it makes your system far simpler. Unfortunately I can't remember exactly where the part of this talk is.
Re:Datomic Is Now Free by tyre on Thursday April 27, 2023 @03:31PM (#35733383)
“No real gain”

I don’t agree with this. iirc Rack ultimately uses and array to represent HTTP responses. It has three members: the status code, the headers, and the response body.

If you’re shipping a new change, is it easier to mistake response[0] or response.headers?

This is a trivial example, but the general class (ha) of trade-off is amplified with more complex objects.

I love clojure and lisp but the blindness behind a statement like “no real gain” has always kneecapped adoption.

Re:Datomic Is Now Free by augustl on Thursday April 27, 2023 @04:00PM (#35733753)
In Clojure, response.headers is still data :) You just use the built-in ways of reading named keys, such as (:headers response) or (get headers :response).
Re:Datomic Is Now Free by augustl on Friday April 28, 2023 @03:43AM (#35738610)
Errata: (get response :headers)
Re:Datomic Is Now Free by outworlder on Thursday April 27, 2023 @06:07PM (#35735176)
> If you’re shipping a new change, is it easier to mistake response[0] or response.headers

False dichotomy. There are many options other than arrays. Clojure in particular is fond of hashmaps. You can have your response.headers without OOP.

Re:Datomic Is Now Free by bavell on Thursday April 27, 2023 @03:23PM (#35733279)
> Unfortunately I can't remember exactly where the part of this talk is.

If you or anyone else remembers, I'd love to watch

Re:Datomic Is Now Free by sharms on Thursday April 27, 2023 @03:34PM (#35733415)
Here is this specific part cut out from the larger talk "Clojure made simple": https://www.youtube.com/watch?v=aSEQfqNYNAc
Re:Datomic Is Now Free by 8ytecoder on Thursday April 27, 2023 @03:28PM (#35733350)
Me as well. I just tried searching for it in transcripts. There are many similar ones but not exactly as described. Such a talk would be great to point people to. As someone who has been in API development for 15+ years, that’s single most pointless busy work I did. I very much prefer Rails, Clojure and Elixir’s approach as opposed to Java or Go.
Re:Datomic Is Now Free by janosos on Thursday April 27, 2023 @03:52PM (#35733655)
Re:Datomic Is Now Free by greg7mdp on Thursday April 27, 2023 @03:43PM (#35733540)
Re:Datomic Is Now Free by gleenn on Thursday April 27, 2023 @07:16PM (#35735723)
Yes, this hit home so hard. All objects are bespoke mini languages that add little to no value and simultaneously make it hard to remember and hard to use. Just use maps!
Re:Datomic Is Now Free by oblio on Friday April 28, 2023 @02:08AM (#35738018)
An object is a schema, though.

A map is... Whatever you put in it.

Re:Datomic Is Now Free by simongray on Friday April 28, 2023 @03:30AM (#35738528)
This is the benefit. Languages like Clojure have excellent support for manipulating maps and I'd wager that something like 40-60% of Clojure code is similar-looking map manipulation stuff for this very reason.

If you need that validation, you just validate the map? You can use established methods like Malli or Clojure Spec for this. If you need to use a record with a fixed schema, just use a record instead of map. In Clojure, you can use most of the map functions for records too.

Re:Datomic Is Now Free by xpe on Friday April 28, 2023 @06:21PM (#35747848)
This comment is talking specifically in the context of Clojure.

In the Clojure culture (so to speak) maps may also have a schema, as used by various schema checking tools, which are richer than runtime type checks. (Not the same as database schema)

Nit: I would not say that a JVM object is a schema, because there’s more to it. Rich is well known for saying that the idea of an object complects two things: (1) a record-like (struct) data structure with the (2) code to manipulate it.

Sometimes it’s even more complected because in some languages classes can make assumptions about state across all objects and threading.

Re:Datomic Is Now Free by javajosh on Friday April 28, 2023 @09:37AM (#35741126)
Constraints always have value. Without constraints programmers are confronted with the naked complexity of mapping between the set of all possible states of N bits which is (2^N)!.
Re:Datomic Is Now Free by gsinclair on Friday April 28, 2023 @09:00PM (#35748951)
More constraints don’t necessarily have more value, though. Each constraint needs to be thought through, not just have its value assumed.
Re:Datomic Is Now Free by kaba0 on Thursday April 27, 2023 @03:55PM (#35733682)
I think there is a need for objects. An active connection, talking to the GPU, etc are not data -- identity is essential for their operation.

OOP is probably the best way to model such,.. well objects, allowing them a private, encapsulated state, and making it only modifiable, or even viewable through a well-defined public interface that enforces all its invariants.

Re:Datomic Is Now Free by gleenn on Thursday April 27, 2023 @04:08PM (#35733855)
Clojure uses objects for connections and things, but POJOs are harmful IMHO because it makes manipulation and collecting data a bespoke task every time. Every time you change the data, you have to change a class to represent the JSON and the ORM class and .... this is all just data
Re:Datomic Is Now Free by kaba0 on Thursday April 27, 2023 @04:28PM (#35734074)
Well, that’s what Java records are for. As for having to change the type description, that’s more of a static typing discussion, though it can be generated — having a single source of truth and generating others is imo the best approach.
Re:Datomic Is Now Free by ledauphin on Thursday April 27, 2023 @05:43PM (#35735010)
Java records weren't even a gleam in the eye of James Gosling when Clojure was solving these problems at its inception.
Re:Datomic Is Now Free by lmm on Thursday April 27, 2023 @08:13PM (#35736076)
Standard ML had records since the '70s. Both Clojure and Java would benefit from taking more from what came before, though Java at least had the excuse of being designed for low-powered set-top boxes.
Re:Datomic Is Now Free by filoeleven on Thursday April 27, 2023 @09:59PM (#35736726)
According to the link below, ML records are mostly handled by hash-maps in Clojure, except that there’s no canonical key/val order or strict typing by default.

ML record:

  {first = "John", last = "Doe", age = 150, balance = 0.12}
Clojure hash-map:

  {:first "John", :last "Doe", :age 150, :balance 0.12}
Destructuring a record in an ML function:

  fun full_name{first:string,last:string,age:int,balance:real}:string =
    first ^ " " ^ last
(It’s unclear from the example whether or not all of the destructured values are required in the function signature. I hope they are not, but I left them in since I don’t know. The caret positioning raises further questions.)

Destructuring a map in a Clojure function:

  (defn full-name [{:keys [first last]}]
    (str first “ “ last))
I don’t know if I’m missing something that ML offers with its records aside from more strict typing, which you can also have in Clojure when it’s useful. In both cases, it looks like it’s applied at the function declaration and not the record declaration.

https://www.cs.cornell.edu/courses/cs312/2008sp/recitations/...

Re:Datomic Is Now Free by simongray on Friday April 28, 2023 @03:32AM (#35738539)
Clojure has records too.
Re:Datomic Is Now Free by kaba0 on Friday April 28, 2023 @12:32AM (#35737497)
In his eyes? It definitely was a thing, records are just nominal product types, these are probably the single most used building block of programming languages.

I really like Clojure, but I really don’t know what some of its fans think (also true of other lisps), like there is a healthy pollination of ideas between languages, lisps are not God’s language.

Re:Datomic Is Now Free by waffletower on Thursday April 27, 2023 @04:42PM (#35734253)
I think OOP (object oriented programming) is abused and is not the optimal paradigm for most software services. It succeeds best at providing inter-operability structure for API design. "Objects", as mentioned here, are an abstraction. Stateful data can be organized and manipulated elegantly without use of the OOP paradigm. Many small systems that employ OOP hamper their maintenance and extendability by unnecessary dependence upon encapsulation and data ownership. Mutability is a villain here as well -- when data structures are immutable, there is little fear of panoptic architectures designed without ownership constraints. Here software is no longer corralled into walled gardens of "objects"; large complex types and their brittle method associations are avoided, greatly simplifying software architectures as a result.
Re:Datomic Is Now Free by filoeleven on Thursday April 27, 2023 @06:38PM (#35735409)
Connection pools exist precisely because the code outside of the connection management piece shouldn’t have to care much whether or not there is an active connection. It’s all boilerplate, except for handling the “unable to connect” case.

When you call a connection or connection pool object, you’re querying its current state. This is absolutely data.

Re:Datomic Is Now Free by PreachSoup on Thursday April 27, 2023 @05:26PM (#35734825)
Most of the time, the class name is used just as a nominal type identifier. That's what we do at least
Re:Datomic Is Now Free by blatant303 on Thursday April 27, 2023 @03:44PM (#35733542)
"It is better to have 100 functions operate on one data structure than to have 10 functions operate on 10 data structures."

Alan Perlis.

Re:Datomic Is Now Free by xmcqdpt2 on Friday April 28, 2023 @08:25AM (#35740449)
To paraphrase a well known saying, objects are the poor person's nested maps and vis versa.
Re:Datomic Is Now Free by samuell on Thursday April 27, 2023 @03:12PM (#35733133)
Thanks for the comment!

I was more thinking of the means to define your data "classes" (or whatever it is called on this context) though, rather than how it is passed around.

Re:Datomic Is Now Free by mtnygard on Thursday April 27, 2023 @04:07PM (#35733842)
You can definitely use Datomic in the way you describe, in at least a few different ways. I haven't often seen queries stored in the database itself. It's more common to have the queries as data in the application. Since queries are ordinary Clojure data structures, it's even more common to see functions that build queries from inputs or functions that transform queries (e.g., adding a tenant-id filter clause).

Datomic also support rules, including recursive rules. I wrote a library to do OWL-style inference about classes of entities using rules. You can see an example here (https://github.com/cognitect-labs/onto/blob/master/src/onto/...). This is a rule that infers all the classes that apply to an entity from an attribute that assigns it one class.

I would also say that building an "entity type definition" system as entities in Datomic is almost the first thing every dev tries after the tutorial. It works... but you almost never _need_ it later.

Re:Datomic Is Now Free by samuell on Friday April 28, 2023 @01:15AM (#35737679)
Great, many thanks for this elaboration!
Re:Datomic Is Now Free by abc_lisper on Thursday April 27, 2023 @08:29PM (#35736194)
It emphatically does. It has pull-syntax just for the nested entities obviating the need for ORM. I am surprised I had to scroll so far down to see this. This is its biggest selling point IMO.
Re:Datomic Is Now Free by epolanski on Thursday April 27, 2023 @12:54PM (#35731013)
> Datomic's is perfect for probably 90% of small-ish backoffice systems that never has to be web scale (i.e. most of what I do at work).

So is any cloud-managed db offering and at that scale we talking very small costs anyway.

Why datomic instead?

Re:Datomic Is Now Free by augustl on Thursday April 27, 2023 @12:58PM (#35731093)
Because of the reasons I list :) Anything in particular that wasn't clear/relevant?
Re:Datomic Is Now Free by brundolf on Thursday April 27, 2023 @01:38PM (#35731746)
Something I've been curious about: how well (or badly) would it scale to do something similar on a normal relational DB (say, Postgres)?

You could have one or more append-only tables that store events/transactions/whatever you want to call them, and then materialized-views (or whatever) which gather that history into a "current state" of "entities", as needed

If eventual-consistency is acceptable, it seems like you could aggressively cache and/or distribute reads. Maybe you could even do clever stuff like recomputing state only from the last event you had, instead of from scratch every time

How bad of an idea is this?

Re:Datomic Is Now Free by augustl on Thursday April 27, 2023 @01:47PM (#35731887)
Datomic already sort of does this :) You configure a storage backend (Datomic does not write to disk directly) which can be dynamodb, riak, or any JDBC database including postgres. You won't get readable data in PG though, as Datomic stores opaque compressed chunks in a key/value structure. The chunks are adressable via the small handful of built-in indexes that Datomic provides for querying, and the indexes are covering, i.e. data is duplicated for each index.
Re:Datomic Is Now Free by brundolf on Thursday April 27, 2023 @01:58PM (#35732087)
Interesting! I assumed Datomic was entirely custom

Now I'm even more curious if you could skip Datomic and just do something like this directly with a relational DB in production

Re:Datomic Is Now Free by kamma4434 on Thursday April 27, 2023 @03:21PM (#35733250)
Yes, but you end up rewriting Datomic!
Re:Datomic Is Now Free by brundolf on Thursday April 27, 2023 @04:09PM (#35733875)
Well, except it sounds like Datomic is closed-source :)
Re:Datomic Is Now Free by Moru on Friday April 28, 2023 @02:51AM (#35738281)
Nah, our (not very good) implementation existed 10 years before Datomic :-)
Re:Datomic Is Now Free by JBiserkov on Thursday April 27, 2023 @04:11PM (#35733901)
But why?! The whole point of Datomic is that it implements this entire immutable framework for you, on top of mutable storage.

So YOU can focus on building your own specific business logic, instead of re-implementing the immutable DB wheel.

Re:Datomic Is Now Free by xmcqdpt2 on Friday April 28, 2023 @08:19AM (#35740401)
Because, for example, your application is not tied to the JVM? You are uncomfortable using closed source software for such a critical piece of infra? As far as I can tell they don't even have a searchable bug report database! I'd hate to be the one debugging an issue involving datomic.
Re:Datomic Is Now Free by koreth1 on Thursday April 27, 2023 @06:00PM (#35735127)
That's a pretty common pattern in event-sourcing architectures. It is a completely viable way to do things as long as "eventual-consistency is acceptable" is actually true.
Re:Datomic Is Now Free by spariev on Thursday April 27, 2023 @03:31PM (#35733382)
One thing which is quite hard to do in Datomic is simple pagination on a large sorted dataset, as one can easily do with LIMIT/OFFSET in MySQL for example. There are solutions for some of the cases, but general case is not solved, as far as I remember (it’s been a while I used it extensively)
Re:Datomic Is Now Free by augustl on Thursday April 27, 2023 @04:04PM (#35733796)
It depends! If you want to lazily walk data, you can read directly from the index (keep in mind, the index = the data = lives in your app), or use the index-pull API which is a bit more convenient.

However, if you want to paginate data that you need to sort first, and the data isn't sorted the way you want in the index, you have to read all of the data first, and then sort it. But this is also what a database server would need to do :)

Re:Datomic Is Now Free by spariev on Friday April 28, 2023 @03:37AM (#35738574)
Yep, I am well aware of these specifics and workarounds, but in general case where is no general solution to the question asked here, for example [0]. And for big datasets with complex sorting it will take some effort to implement a seemingly simple feature.

Guess it is just one of the tradeoffs, as while some features Datomic has out of the box are hard to replicate in RDBMS-es, things like pagination which are often took for granted is a bit of work to do in Datomic. So it is something to keep in mind when considering the switch

[0] https://forum.datomic.com/t/idiomatic-pagination-using-lates...

Re:Datomic Is Now Free by augustl on Friday April 28, 2023 @09:28AM (#35741047)
Interesting link, thanks for posting!

Datomic's covering indexes are heavily based on their built-in ordering, and doesn't really have much flexibility in different ways to sort and walk data.

Personally, I'm a fan of hybrid database approaches. In the world of serverless, I really enjoy the combo of DynamoDB and Elasticsearch, for example, where Dynamo handles everything that's performance critical, and Elasticsearch handles everything where dynamic queries (and ordering, and aggregation, and ....) is required. I've never done this with Datomic, but I'd imagine mirroring the "current" value of entities without historical data is relatively easy to set up.

Re:Datomic Is Now Free by convolvatron on Thursday April 27, 2023 @04:10PM (#35733884)
there must be a relational sort? ah yes, there is, and the ability to feed a relational output into a Clojure sort
Re:Datomic Is Now Free by JimmyRuska on Thursday April 27, 2023 @04:57PM (#35734461)
> doing UPDATE in SQL feels pretty weird, as the default mode of operation of your _business data_ is to delete data, with no trace of who and why!

It's a good idea to version your schema changes using something like liquibase into git, that gets rid of at least some of those pains. Liquibase works on a wide variety of databases, even graphs like Neo4j

I got the same feeling in Erlang many times, once write operations start getting parallel you worry about atomic operations, and making an Erlang process centralize writes through its message queue always feels natural and easy to reason about.

Re:Datomic Is Now Free by Lutger on Monday May 01, 2023 @11:31AM (#35774235)
Datomic always seemed like a really cool thing to use. However, I'm not familiar with Clojure or any other JVM based language, nor do I have the time to learn it. And I can't find any supported way to use it with other languages (I'm not even talking about popular frameworks), or am I missing something?

It doesn't feel like the people behind Datomic actually want to have users outside of the Clojure world, which will be rather limiting to adoption.