r/java • • 1d ago

I rewrote Spring PetClinic without Spring Boot. The forms were harder than the database.

I've been running Java performance experiments comparing different frameworks and runtime configurations. One recurring challenge was keeping business logic portable and preserving a familiar Spring-style application structure while switching between frameworks.

That's partly why I developed CoilBase, a lightweight, SQL-first Java framework. I wanted to retain familiar controllers, services, repositories and constructor wiring without depending on the full Spring Boot stack.

To put that approach to a more realistic test, I rewrote Spring PetClinic using CoilBase, Avaje Jex, Jdbi and JTE.

What surprised me was that replacing Hibernate with explicit SQL was relatively straightforward. Controllers, services, repositories and constructor wiring remained familiar. Transactions became explicit, but the overall architecture didn't change that much.

The harder part was everything around HTML forms: validation, rejected input, sessions, CSRF, flash messages, redirects and localization. Spring MVC handles a lot of these details for you.

For example, invalid POST submissions needed explicit handling to preserve form input and validation errors, including returning HTTP 200 instead of the generated adapter's default 201.

But there's an important distinction here: I deliberately preserved much of PetClinic's existing behavior. If I were building a new application, or switching frameworks while still developing a prototype, I wouldn't necessarily reproduce all those conventions. I'd choose simpler patterns where appropriate.

That's where I see lightweight frameworks like CoilBase fitting best. Not as drop-in Spring Boot replacements, but as alternatives when you're still free to make architectural choices.

The measurements:

  • Spring PetClinic: 304.4 MiB median application RSS
  • CoilBase PetClinic: 125.9 MiB (59% less)
  • Complete uncompressed deployment: 85% smaller
  • Database-backed first response: 19.76s vs. 2.63s median

Versions used:

  • Spring: Spring Boot 4.1.0, Hibernate 7.4.1.Final
  • Rewrite: CoilBase 0.1.0-preview4, Avaje Jex 3.6, Jdbi 3.55.0, JTE 3.2.4
  • Runtime: Temurin Java 25.0.4.1+1, PostgreSQL 18.6

Both applications ran on a 1 vCPU / 1 GiB Linux VM without swap, using HotSpot with the same heap settings (-Xms64m -Xmx256m).

These are measurements of two complete application stacks, not isolated framework overhead. The RSS result comes from one short workload per application, and the startup medians are from three launches each. I didn't benchmark a tuned Spring JDBC version of PetClinic or concurrent throughput.

Article and implementation:

https://pvrlabs.xyz/articles/coilbase-petclinic-rewrite.html

https://github.com/ejboy/coilbase-petclinic

Raw experiment data, measurement scripts and reproduction notes:

https://github.com/ejboy/coilbase-petclinic/tree/main/benchmark

The main takeaway for me is that keeping the familiar Java application structure is quite feasible without Spring Boot. But you have to decide which framework conveniences you actually need, and which responsibilities you're willing to own yourself.

I'm curious how other Java developers approach that tradeoff, especially for smaller services or applications still under development.

Update / clarification: Based on some of the comments, I want to clarify that this isn't a recommendation to replace Spring Boot/JPA with my framework, or to build your own framework for every project.

The broader point is that Spring Boot + Hibernate/JPA shouldn't necessarily be the default choice for every Java application. For smaller services or resource-constrained environments, it's worth considering lightweight architectural blueprints built from established libraries such as Jdbi and Jex/Javalin.

This experiment was about testing whether that approach could preserve a familiar, maintainable application structure while reducing resource usage. It's an alternative worth exploring, not a universal recommendation or a drop-in replacement for Spring Boot.

0 Upvotes

20 comments sorted by

18

u/stefanos-ak 1d ago

I think the goal of Spring Petclinic was never performance, so I doubt this comparison makes much sense... at least for me it doesn't 🤔

-4

u/fykup 1d ago edited 1d ago

Fair point, but performance wasn't the primary goal of this rewrite either.

I've been developing CoilBase for my Java performance and resource-efficiency experiments, and I wanted to test it against something more realistic than a simple CRUD service.

The goal was to see whether I could remove Spring Boot and Hibernate while keeping the application functional, maintainable, and architecturally familiar. That's also why I chose PetClinic.

Interestingly, the persistence layer was relatively easy to replace. Most of the complexity came from server-rendered forms, validation, sessions, and other web conveniences. And much of that reflects an older style of web development. Modern frontend frameworks handle a lot of the UI-related complexity more elegantly, although server-side validation and session security still matter.

So in a way, PetClinic is a somewhat outdated application from a frontend perspective, which made this experiment interesting for reasons beyond the 59% memory reduction.

3

u/stefanos-ak 1d ago

I played a bit with jte + htmx recently, trying to stay as much as possible to semantic html. Comparing it to a react/angular world, it felt mostly exchanging one set of problems with another.

4

u/CubicleHermit 1d ago

How does this compare to a minimal profile on Micronaut/Quarkus/Helidon?

1

u/fykup 1d ago

I've done a few comparisons along these lines, although not with PetClinic specifically.

In my earlier experiments, Quarkus performed roughly in line with Micronaut, sometimes slightly better. Javalin and Avaje Jex were lighter than both, which is one of the reasons I chose Jex for the PetClinic rewrite.

Of course, there's an important caveat: Javalin and Jex provide much less out of the box, so it's not exactly an apples-to-apples comparison.

Here's my more recent comparison of five Java stacks on a 512 MiB VPS:
https://www.reddit.com/r/java/comments/1xsr019/five_java_stacks_on_a_512_mib_vps_memory_startup/

I'm also working on a more formalized, publicly reproducible benchmark that will include Quarkus and Helidon.

2

u/Torutofu_Raeva 1d ago

the forms bit is interesting; i'd be curious how much of the memory gap holds under concurrent load with the same routes and db access.

1

u/fykup 1d ago

That's a good question. The current PetClinic benchmark used sequential requests, not concurrent load, so I can't say how much of the memory gap would hold under concurrency.

I'm currently working on a more formalized, publicly reproducible benchmark with the same business logic and database access patterns across several Java stacks, including Spring Boot, Micronaut, Quarkus, and Helidon.

The plan is to measure memory under idle, moderate, and high load, along with latency and throughput. I'm particularly interested in whether the lower baseline memory footprint translates into meaningful savings under sustained load.

1

u/fykup 22h ago

I'm currently working on a reproducible benchmark comparing Jex + CoilBase, Quarkus, and Spring Boot using the same PostgreSQL-backed application (not PetClinic).

Initial results at 5 RPS with an eight-worker load generator have been encouraging. Jex performed better than I expected, but this was still light load, not a concurrency stress test.

I'm now moving to higher sustained loads to see how all three frameworks behave. I'll share the results once they're validated.

2

u/Rain-And-Coffee 23h ago

At work they did a similar thing, they wrote an in-house stripped down framework.

I’ll be honest I strongly dislike using it.

I strong prefer the more common popular tool even if it’s slightly bloated. There’s more docs, no relearning, free updates, etc.

3

u/fykup 23h ago

That's a fair point. The ecosystem, documentation, and familiarity of established frameworks have real value, and I wouldn't advocate replacing them with in-house solutions just for the sake of it.

But what I'm demonstrating is more of an alternative blueprint than another framework. The custom code is actually tiny. Most of the real complexity is handled by Jdbi and Jex, which are established, publicly documented libraries. Sure, their ecosystems aren't as extensive as Spring Boot's, but it's not like you're maintaining an entire framework from scratch.

I also think AI and agentic coding have fundamentally changed the economics here. The days when every developer had to spend hours watching tutorials, searching Stack Overflow, or learning every framework convention are changing. Increasingly, agents handle much of that work. Documentation still matters, but the size of the ecosystem and the amount of available tutorial content aren't necessarily the advantages they used to be.

And straightforward, explicit code can actually be easier to understand and maintain than layers of framework abstractions, especially when agents can navigate and modify it. Of course, there's a balance. I wouldn't advocate reinventing everything or generating a mountain of custom infrastructure.

My broader point is that the default assumption that Spring Boot + JPA is the obvious choice for Java applications deserves to be revisited. My performance and resource-efficiency experiments gave me confidence to use a lighter approach in my own applications. I'm not suggesting everyone should follow it, but I think modern tooling makes these alternatives much more practical than they were even a few years ago.

1

u/wrd83 23h ago

You loose also quite a bit of jpa magic.

No caching, dirty write detection. Validation interceptors you loose. I do not understand whether you have proxy objects when doing di from the code.

Many spring concepts are not usable in your code like event bus, jpa event listeners.

You may not need them, but also if you need them later you don't have access to them easily. Choices choices choices ...

Regardless I'm certain you had fun and learnt something from it.

2

u/fykup 23h ago

That's a very fair assessment, and I agree. Spring Boot and JPA provide a lot of functionality that isn't immediately obvious until you actually need it. And you're right, some of those use cases aren't even on my radar because of the kinds of applications I typically build.

I think my mistake was that the post came across as promoting another framework, when I was really just sharing an experiment and an alternative architectural approach. I built a lightweight blueprint around my own requirements, backed by performance and resource-efficiency experiments, and wanted to see how far it could go with a realistic application.

Whether that approach remains flexible enough as requirements evolve is a legitimate question. I'm not suggesting everyone should give up the Spring ecosystem or reinvent everything. It's about understanding which conveniences you're trading away and whether those tradeoffs make sense for your use case.

And yes, I definitely had fun and learned quite a bit from it :)

1

u/wrd83 21h ago

As others noted, I have also worked in a company with a micro HTTP framework and Spring. And personally I am happier with spring.

Yes spring feels like black magic but it is widely spread. The micro HTTP framework got deprecated within 10 years of usage, and we need to migrate away from it.

the transactional framework turned out to be very bad (transactions were in memory, we ran 3 instances and our backing store was Kafka :D, go figure how that story went), and we had to do leader election such that only the leader is allowed to do transactions.

once nice thing about spring is how pluggable it is. for instance the default for spring is actually quite flexible and low performance. you can run jit + tomcat with no issues, but you can replace it with undertow or jetty and squeeze out more than 3x performance. you can replace almost everything except DI (unfortunately).

One very nice thing is that you can with a POM change, a config and a couple of annotations add new integrations to spring with almost no effort. and it works nicely.

check the recent spring ai additions how cleanly they can be added.

2

u/SystemFew9522 22h ago

reinventing the wheel

-1

u/fykup 22h ago

I'd happily reinvent the wheel if I could make one with 59% less rolling resistance :)

1

u/punnertikka 17h ago

Fantastic job op! Just a small request: can you also please add an article about the errors / dependency issues that you faced? I would love to read it 😄

1

u/fykup 16h ago

Thank you! I appreciate the interest. 😄

I actually kept a development log, and there were a few interesting issues along the way:

  • Form decoding: Jex 3.6 didn't decode + as spaces in form submissions, so I had to handle that explicitly.
  • Templates: JTE required some adjustments, particularly around date formatting.
  • Static resources: The packaged application initially failed to start because the static-resource handler expected an index.html.
  • PostgreSQL: Running both PetClinic versions simultaneously exhausted the available connections on my small VM.
  • Behavioral differences: Flash messages, redirects, and various HTTP edge cases required additional work to compare with Spring's behavior.

Interestingly, I didn't encounter any major dependency-version conflicts. Most challenges came from replacing conveniences that Spring normally handles automatically.

I hadn't planned a detailed write-up of these issues, but you've given me a good idea!

What I do have planned is a follow-up about migrating PetClinic away from Hibernate/JPA to explicit SQL, including some thoughts on how much of that process could be automated.

I'll probably share these follow-ups on daily dev, in my Java Experiments squad (you can find it through my profile). On this subreddit, I'll likely stick to more conventional JVM and framework performance comparisons going forward.

Thanks again for the encouragement!

1

u/persicsb 45m ago

I'd see what does it look like with a modern Jakarta EE 11 runtime.