r/java • u/Snoo82400 • Sep 23 '26
I decided to go down the DOP rabbit hole
So a year ago I started my work at a local clinical data start up and decided to fully embrace Data Oriented Programing and modern Java features for the back end.
The result, as I see it, is a more clear-less magic back end, easier to reason for both humans and LLMs with records as first class citizens (I even decided to forego JPA and use jOOQ so that I could say goodbye to Entities and make the record a pure domain object.
The testing has some Bloch sprinkled of top.
As I go forward, and as long as I can have a say in the matter I will keep pushing modern Java, as much as I can.
Here some key features:
Sealed Interfaces & Pattern Matching: The possible states of each operation are explicit and closed. Every operation returns a strict contract, reducing ambiguity and avoiding entire classes of NullPointerException
SQL-First with jOOQ: Instead of managing entity states and persistence sessions, we wanted database interactions to be as stateless and explicit as the rest of our architecture.
jOOQ gave us the ability to work close to SQL while retaining compile-time type safety, mapping database results directly into our immutable data structures.
Pragmatic Architecture with Spring Modulith: For the early stages of development, we opted for a modular monolith to avoid the inherent complexities of distributed systems when they aren't strictly necessary.
Spring Modulith gives us explicit module boundaries and allows us to verify the application's modular structure. Our domains communicate through decoupled, asynchronous events using ApplicationModuleListener.
This gives us the structural isolation of an event-driven architecture without introducing external message brokers prematurely, while keeping the modules easier to extract into standalone services if the platform eventually requires it.
No Exceptions for Control Flow: For this project, we consider business exceptions an unnecessarily indirect form of control flow.
Java records are treated as first-class citizens. By combining them with sealed interfaces, errors are modeled as algebraic data types — for example, returning a Success or an InvalidData record.
The compiler then forces us to handle every possible scenario through exhaustive pattern-matching switches, leaving less room for unhandled states or hidden execution paths.
Testcontainers & The Bloch Enum Singleton: Testing against real infrastructure is non-negotiable, but spinning up containers for every test class can make CI unnecessarily expensive.
We implemented the Bloch Enum Singleton pattern to guarantee a strict Singleton lifecycle for our PostgreSQL and S3 test containers. They boot exactly once per test suite execution, significantly reducing infrastructure startup overhead while keeping our database and network tests reliable and isolated at the test-data level.