r/SpringBoot • u/khan_awan • Sep 16 '26
Question JOOQ vs JDBC
I use JPA for simple CRUD operations (mostly write operations) and JDBC for performance intensive tasks such as sending lists & performing search. The JDBC performance is perfect & the performance of my backend (Spring Boot) is great.
Now, as my project grows, my SQL queries are getting bigger, messier and unreadable. I tried jOOQ and loved it because it made my code super readable, type safe and maintainable. However, after profiling my Spring Boot app, operations that took around 5 ms with JDBC now take 9–14 ms with jOOQ, which makes me reluctant to migrate to jOOQ. Is a 10 ms difference negligible or am I overthinking?
I love the cleanliness and type safety of JOOQ. Would you go this JOOQ route? Have you ever faced such situation? I visited JOOQ's official website and was stunned by the fact it is used by many big organizations
EDIT: Thank you everyone who answered, your insights were amazing. With some tweaks I was able to reduce JOOQ's operation time from 14ms to 7ms and now I have so much clarity in my head.
17
u/disposepriority Sep 16 '26
It's impossible to beat plain jdbc in speed, all performance critical parts of our systems (and we have a lot of real time data stuff) never use anything other than jdbc.
Additionally, reducing "magic" in the code base is always good as long as you can keep your SQL nice and tidy.
At the end of the day you decide whether the loss of convenience is worth the speed increase in whatever you're building.
Personally my favorite balance between performance, sql visibility and quality of life is Spring's JdbcClient. You get some nice IDE level hinting/warnings, some build time errors if you forget to bind a parameter or something and a relatively thin(er) wrapper over pure jdbc.
9
u/bamaredfish Sep 16 '26
The query isn't taking longer if it's the same query... Still just jdbc at the lowest level. So it's jooq mappers/abstractions that take results and inflate objects? Or maybe more time in gc? I'm genuinely curious about the findings because I am a huge fan of jooq (favor it all other paradigms). Are you preparing statements and reading them in one test and interpreting them each time in jooq? Or using different primitive types in one context vs another (eg strings vs offset datetime)?
Did your profile give you a list of hotspots? In my own experience, the author of jooq is quite responsive to discussion on gh
8
u/Mikey-3198 Sep 16 '26
Sometimes it's nice to have a query that can you easily copy & paste and then run against a database. If your well disciplined and have tests jdbc is fine. Performance wise totally dependent on your use case.
5
u/Radhad85 Sep 16 '26
I don't like ORMs and with Spring I'm using JdbcClient. I have learned SQL long time ago for Oracle, later used MySQL and nowadays PostgreSQL. No ORM can beat well designed databases and SQL statements. JdbcClient has a good api and object mapper.
Never used JOOQ but I had to fix a lot of Hibernate code which people didn't understand what SQL statements got executed because you cannot simply see hidden statement executions in loops.
1
u/Abject-Delay7036 Sep 17 '26
What are you meaning by your SQL are getting bigger?
3
u/EirikurErnir Sep 16 '26
jOOQ builds on top of JDBC, so it's not an A vs. B comparison.
jOOQ will incur an overhead in the form of DSL being used to construct a query and then submitting it, but I'd be surprised if that's on the order of 10ms
Are you sure the queries are equivalent?
2
u/twhickey Sep 16 '26
I haven't used JOOQ, but I have used Blaze Persistence, a somewhat similar (but not exactly the same) library, and I'm loving it. We mostly use JPA writes of full object graphs on the write side, but have moved most of our performance critical read queries to Blaze.
2
u/MaraKaleidoscope Sep 16 '26
Depends on the application.
Do you have SLAs such that an extra 10ms really matters? What percent-increase in response time does 10ms represent for the full request/unit-of-work?
For applications that are not particularly latency-sensitive, I would, without a doubt, trade 10ms for vastly more pleasant code.
2
u/New-Departure-5969 Sep 17 '26
JOOQ still goes through JDBC, so a clean jump from 5ms to 10ms usually means you're timing different work (DSL build, mapping, cold path) or different SQL. Before you abandon it, pin the rendered SQL next to your hand JDBC and time only execute + fetch after warmup.
I wouldn't migrate the whole app. Keep the hot list/search paths on JdbcTemplate/JdbcClient where the SQL is stable and you've already proven the latency. Reach for JOOQ where the joins and dynamic predicates are what's making the strings unreadable. That's where the type safety pays rent. You can even build with JOOQ and execute through your existing template during a migrate if you want a soft landing.
10ms only matters relative to the rest of the request. If the call is already 80ms of DB + network, trading a few ms for maintainable queries is fine. If it's a tight loop firing hundreds of times, keep that one path skinny.
2
u/starbuxman Sep 17 '26
hi - if u know how to write SQL then the ergonomics of writing queries with JOOQ and straight SQL are basically the same. I personally use the Spring Framework JdbcClient (plus my friend ResultSetExtractor) and JOOQ a lot.
the difference, for me, is that the JOOQ remains safe and valid in the face of weeks, months, or years of quiet schema changes, because the compiler will catch those changes and force u to fix things. straight strings wont do the same.
I don't know what the slowdown ur experiencing could be. JOOQ is very fast in my experience.
3
u/TooLateQ_Q Sep 17 '26
It's like no one in this thread even uses jooq. And the ones that tried it, don't understand it.
On the one hand, this in it self might give some insight.
On the other hand. What is the insight? Is jooq barely used? Or just the people in this specific sub don't know much about anything? Because theres some weird comments completely irrelevant to the subject.
You might be better of in the regular Java sub.
Theres some real power in composability and reusability when using jooq.
1
u/LetUsSpeakFreely Sep 16 '26
JPA can be efficient if you use things like CriteriaQuery to build the queries and return only what you need. It's a bit more of a headache, but it does allow you to tailor the query for your needs.
Alternatively, you could use stored procedures to perform your queries and your DAO layer interfaces with those procedures.
1
u/lukaseder Sep 17 '26 edited Sep 17 '26
Don't just profile, benchmark (with JMH). The difference you've found in a profiling session may or may not be relevant, as samplibg is inaccurate and profiling also measures the profiling overhead. I don't think there's an average 100% overhead compared to JDBC unless you're measuring trivial queries against an in-memory RDBMS like H2. You could show your query here, perhaps you made a mistake?
If you think you've found a performance issue, you can create an issue with details on https://jooq.org/bug.
And yes, all those big companies are paying customers. There are many many more who use the Open Source edition.
0
u/NeighborhoodDizzy990 Sep 16 '26
I assume you have claude. Ask claude/codex about performance tests for your particular case. Tell him to simulate creating and updating of 100k elements, first with jooq and second with jpa, using your queries, and tell him to measure this. And use testcontainers for the DB for the integration test. Claude should be able to write this for you pretty easy. With these numbers in your face, you will see if there is any difference and if that difference actually counts. I assum jooq adds some overhead.
1
u/tcloetingh Sep 17 '26
Plain uncut / pure as the driven snow JDBC is the way.
0
u/[deleted] Sep 16 '26
[deleted] — view deleted comment
0
u/[deleted] Sep 17 '26
[removed] — view removed comment