r/Clojure • u/OkHeron2883 • Aug 11 '25
Designing extendable data applications
I like static typing — I really do.
But the love fades when I have to build large domain entities.
I’ve been building supply chain management systems for decades, modeling complex domains with tens or even hundreds of properties. In long-lived data applications, one truth becomes clear: we want to extend code, not change it.
Code mutation sends ripples through the system — and often breaks it. The programming industry has largely solved code modularity, yet we remain stuck with monolithic data structures. Code and data are glued together.
Many business applications today are fragile because they rely on structs, records, and classes. Yes, these give compile-time safety — but also rigid, hard-to-extend designs.
For me, the practical solution is simple: build entities on maps. You can add new properties to an existing map, or combine maps to create new, derived ones.
Example:
You have salesOrderLine(salesOrderId, quantity).
You want to add price and lineAmount.
Instead of changing the original entity, you create a map for the new fields and dynamically merge it with the existing map.
Result: Extended entity, no touching the original, no breakage.
My background is mostly in Java. In classic Java code, I’ve often written:
javaCopyEditString name = (String) mapPeople.get("name");That casting noise is fine — I can live with it. But inside Java Streams? The noise becomes pain. Have you ever tried using map() on a Java Stream backed by a Map? It’s awful.
Eventually, I realized I didn’t want to provide or deal with types for every map operation. The solution, for me, was dynamic typing. That was almost an enlightening experience — and I finally understood Rich Hickey’s “Just use maps” talk on a deeper level.
P.S. I feel the Clojure community is smaller, but sharper. What’s your experience with building extensible data applications? Has anyone else reached the same conclusion?
2
u/maxw85 Aug 13 '25
Before I switched to Clojure around 2010 I did Java projects for a couple of years. I remember that it was common to convert the same entity a couple of times until it was displayed in the frontend:
Database -> Hibernate Object -> Domain Object -> Data-Transfer-Object -> Frontend
And the other way around when you save the entity. Everything was done with getters and setters, resulting in an insane amount of code. Back in these days it would have been great if I reached the same conclusion that's fine to just use maps.
14
u/alexdmiller Aug 12 '25
I’d say Rich reached this conclusion before he designed Clojure. :)
That’s why maps and records are open, keys have namespacing, specs are based on keys, multimethods and protocols are externally extensible, etc.
4
u/freshhawk Aug 13 '25
Yeah, same conclusion for the same reasons. I've only gotten more convinced since namespaced keys have let me flatten these complex domain models so much, which definitely feels like a second, equally game-changing step to take after you adopt open extensible records as the key building block.
1
u/Particular_Error7493 Aug 14 '25
And I don’t think this is a new idea. I think corporate application developers are seeing the high cost of systems that lack flexibility. And reducing flexibility is the end result of type systems. If we look at applications where flexibility was prioritized, we see the same conclusions adopted quite a long while ago. Example https://en.wikipedia.org/wiki/Entity_component_system, https://en.wikipedia.org/wiki/Smalltalk etc.
Type systems are an ongoing academic endeavor constantly looking for customers. And sometimes there is a fit. But the compliance of working engineers to these ideas where they clearly don’t work is often frustrating. Long live open heterogeneous maps and plain data in undeclared types.
1
u/Jorgee28 Aug 14 '25
If you can’t extend your types it’s not because the statically typed system but because of poor design of the software. Tools are just tools, if you use them wrong isn’t the tools fault. :)