r/Clojure • • 22d ago

Two apps one process

https://andersmurphy.com/2026/11/09/two-apps-one-process.html
29 Upvotes

30 comments sorted by

View all comments

8

u/andersmurphy 22d ago

I'm curious what people think about this part: If a deploy is indistinguishable from network blip did the app really go down?

7

u/bananasdoom 22d ago

> Disclaimer: all my writing and code is handcrafted by me. By the end of this you may wish it wasn't.

Your writing is charming.

Technically; On a principled level I think I agree this is a good approach, but as the other commenter pointed out, too much has been built on the assumption of machine level “dumb” isolation. Feels like one of those endeavours where for the want of shared process you’ll end up rebuilding the world.

3

u/andersmurphy 22d ago

Thank you! Yes there's definitely always a risk of rebuilding the world. But, simple isolation is easy enough, i.e apps can't crash other apps, apps can't accidentally access another apps database (unless you load your own sqlite driver and search the filesystem). So it's good enough for deploying apps you own/trust.

I didn't really go into it in the post as I was saving it for a more in depth write but the game loop based render/write batching gives you a lot of headroom and also makes detecting if the system is at capacity (tick overrun). I cover it a little in this post:

Discrete time based systems are simple to benchmark

I do need to add sampling for more fine grained profiling, but again the game loop model makes that relatively trivial.

3

u/yatadger 22d ago

>> Disclaimer: all my writing and code is handcrafted by me. By the end of this you may wish it wasn't.

> Your writing is charming.

Appreciate the ones who handcraft their craft

5

u/Krackor 22d ago

To address the question more directly, taking your app offline is done under the presumption that the next instance of the app will come up, and do so in a network blip's amount of time. In practice that is not always true, so some health check on the incoming app is prudent before rerouting traffic to it. What happens if some configuration server you depend on during start up is down for an extended period of time? Will you notice before shutting down the outgoing instance? You may need to keep the outgoing instance up until the startup dependencies are available again.

Philosophically, a short network blip is indistinguishable from a short downtime so it may not take away a meaningful 9 of uptime. But there are logistical factors to consider besides the happy path uptime math.

5

u/andersmurphy 22d ago

Oh definitely. This is very much on the spectrum of your app has no external dependencies that can crash it. The database is embedded sqlite etc. There is no configuration server. External feature flag server etc.

The only time it should crash is if backups are not working.

2

u/aHackFromJOS 18d ago

“A deploy is indistinguishable from a network blip” is definitely true if you have an invincible, autarkic app!

2

u/andersmurphy 16d ago

Thanks for teaching me a new word. Autarkic is definitely the goal.

3

u/Krackor 22d ago

Run N copies of the uberapp and blue green deploy. It depends on your use case but imo actual downtime between deployments would be unacceptable for most things I build for a paycheck. And if an app can't tolerate running concurrently, correctly, with another copy of itself or the prior outgoing version, is it a real app in the first place?

2

u/andersmurphy 22d ago

What things have you built where it was unacceptable?

In my experience most blue green deploys do lead to some level of degradation and/or anomalies. The added complexity often makes the system more fragile as there are more interdependent components.

A warm standby with a manual failover (avoid split brain) has always felt like the more reliable approach to me.

2

u/Krackor 21d ago

Microservices handling activity from public users. If a request chain is inflight I don't want to drop it on the floor by shutting down the outgoing instances until the request chain has had time to complete. I also don't necessarily trust the entire system to have good process durability and retry discipline so it's valuable for downstream services to be as reliable and prompt as possible. 

There are ways to design around these problems with a different architecture but one doesn't always have control over the holistic system design, and the design choices needed to make the "stop the world" deployment strategy work wouldn't necessarily make sense in a large enough system with a large enough team.

3

u/Liistrad 22d ago

Network blip is one of the effects, but there's more, especially around state like user sessions or caches that can be ephemeral. REPL sessions also come to mind.

I noticed your deploy process was uberjar + scp. Have you considered/tried not even doing uberjar? I've been toying with the idea of very long lived clojure processes that reload their code and it sorta sounds possible? Deps can now be reloaded at runtime, and source has been reloadable for a while.

https://github.com/filipesilva/invoker#deploy is an example of I'm talking about. Maybe it is fine to just push the source and reload the app.

3

u/andersmurphy 22d ago

Thanks for the link I'd check it out!

Yeah, I've been somewhat hand-wavy. The apps use datastar and have no client side state (other than animations/user input). All app state is in sqlite, so there's nothing ephemeral on the server that isn't transparent. I.e if a user sees a UI change it's been fsync'ed to disk. So there's nothin to lose on restart.

I do occasionally use the repl to patch a running jar. But, those changes don't persist when you restart.

I've considered not using uberjars and having source files on the server I think Biff does this. My problem is that reloaded workflows often break in weird wonderful ways.

I am considering exploring storing app code in the database and loading it from there at runtime.

3

u/jacobobryant 21d ago

Yeah, with biff you can do `clj -M:run deploy --soft` to eval files without restarting the process or any stateful components, and then omitting `--soft` does a process restart. it's kinda nifty. Took a bunch of work to make sure as much stuff as possible was using late binding.

2

u/whoisarepo 21d ago

That’s what I wondered, what about data assurance? For my style programs this is very useful but for multi tenant…it may work but needs a framework to handle what SoC did naturally, create boundaries between error types. It seems harder to diagnose now which app failed what and why without some telemetry service layer…which is all fine tbph but it’s the tip of the iceberg of a good idea…