r/Clojure • u/andersmurphy • 6d ago
Two apps one process
https://andersmurphy.com/2026/11/09/two-apps-one-process.html3
u/beders 6d ago
Does anyone remember JAR hell and it’s „solution“ OSGi?
We certainly don’t want to repeat that.
I think the approach above is fine if you have full control over your apps.
3
u/andersmurphy 6d ago
Haha, yeah it was partly inspired by OSGi and servelts. This is definitely only for when you have full control over your apps. There's no sandboxing here other than avoiding making it easy to accidentally mix app data (handlers only get their database passed in etc).
2
u/fk00 6d ago
What happens if one app crashes. What happens if it keeps crashing, or, worse, goes into endless loop, consuming all available resources? I'm not talking JVM is particularly good at working in a containerized environment, but there are practices there you can follow.
Saving resources is a good thing, but when monolith goes down, you loose all apps.
2
u/andersmurphy 6d ago
Apps don't crash other apps. The system is relatively draconian in terms of what/where they can run. Which makes monitoring trivial and opens up interesting options like canceling work by misbehaving apps to protect the wider system.
For example you could, if you wanted to set a max render time for a given render-fn (how the apps implement views) and either log or cancel. Same for the transaction thunks scheduled on the db.
For the record I'm not arguing against having separate boxes for different apps. This is more about when you have a single machine, with highly variable app resource usage/traffic. If all apps were easy to size correctly then a bigger box with separate processes and a reverse proxy is fine.
1
u/fk00 6d ago
So what happens when this monolith exhausts RAM?
3
u/andersmurphy 6d ago edited 6d ago
What happens when any system exhausts its resources? The process dies and restarts and the loop continues.
The same applies to a multiple node set up too. Except it's more complex.
4
u/didibus 6d ago
Just rollback, debug, restart. Honestly many services even if deployed on their own machine or container often break or have downtime, and cloud providers go down, etc. You have to think about your use case.
2
u/fk00 6d ago
Right, so when one app suffers from the bug, you rollback the entire set. And imagine your customer can suffer from inconvenience of missing access to one feature, but you suddenly revert the entire monolith. Not a great approach.
1
u/didibus 5d ago edited 5d ago
It looked to me from the post you can selectively rollback just one app. There's a project with versions per-app, so you can rollback the version of the app with issues and redeploy, rolling back only the app with issues and not the others.
It's not always going to be what you want, but I think it's an interesting approach when you control all apps and want to really minimize infra cost and have something simple to manage.
2
u/whoisarepo 5d ago
I like this! I use babashka sub processes for my clojuredart and clojure script projects, if this technique translates well then I can simplify some things, good work! I wonder how it handles data corruption from interruption between multiple writers, feels like the orchestrator eats the bulk of abstraction to make it feel magical
2
u/andersmurphy 5d ago
Not sure what you mean about corruption. Each app has it's own sqlite and batches to them separately. All apps implement CQS, so writes are async so the can be batched. You only see the changes in the next tick.
2
u/whoisarepo 4d ago
This makes a bit more sense, like the mechanics of a LAN Game server. It’s just…weird lol, but cool. And makes me wonder why haven’t more polylithic projects attempted unifying this way as it’s not clj specific
2
u/geokon 5d ago edited 5d ago
I always thought this would be the natural way to do things. Having to dance around the OS abstractions seems like an unnecessary straightjacket.
I don't work in the webspace, but is this effectively working through loopback having VM threads communicate that way?
You could probably reach into each others namespaces and pull at atoms, but this probably will lead to people taking shortcuts and making coupled code. Maybe that's what you've solved - and present a structured way to do interprocess communication (sorry, I couldn't quite figure it out from the Github)
Hopefully in the end you're gunna be copying memory buffers all over the place for no good reason (which is what the OS, loopback, and other isolating abstractions end up forcing you to do)
1
u/andersmurphy 5d ago
The apps are separate projects that can be run and developed on their own, so you have an element of decoupling there.
There's no inter app communication. The framework handles the scheduling. It's basically a simple game loop that batches writes and renders.
Not sandboxing though, so if you really wanted to you could have one app reach into another app, but that would be a bad idea so I've tried to at least make it hard to do.
7
u/andersmurphy 6d ago
I'm curious what people think about this part: If a deploy is indistinguishable from network blip did the app really go down?