r/programming • • 7d ago

Postgres is All You Need for Durable Workflows

https://www.dbos.dev/blog/postgres-is-all-you-need-for-durable-execution
159 Upvotes

28 comments sorted by

50

u/HolyInlandEmpire 7d ago

I love Postgres and everything it stands for. However, I do understand that for frequent updates it's inefficient because it the way it stores them and deals with indices, especially multiple of them.

Is this still an issue, or has it perhaps been fixed, with the right preparation?

35

u/axonxorz 7d ago

It's still an issue inherent with MVCC, but it's not really one you should care about. For the vast, vast, vast majority of apps, the benefits it provides at the cost of speed are much greater than the cost it would take to switch DBMS stacks, especially if you're doing things like in OP.

4

u/HolyInlandEmpire 7d ago

I do believe that, but then the question is if you are making a service that has the goal of having tons and ton of updates, are you better off starting with something else? To be certain I do agree with postgres as a default.

2

u/axonxorz 7d ago

Yeah there's certainly value in picking something that is more tuned for your workload out of the box. That said, you can tune PG for a more write-heavy workload and get really good performance.

0

u/dangerbird2 7d ago

If you're building a service that's having so many frequent updates that postgres can't handle it, you're should be making enough money that you can hire devs to build around those limitations.

59

u/toastyman1 7d ago

Nah, idk why you'd want to roll your own workflow engine - you'd just end up re-inventing something very temporal shaped - which you can already slap ontop of postgres.

Unless your companies core value prop relies directly on workflow orchestration, or your problem space is simple enough that a basic check pointing system will work - no way in hell I'd re-invent this wheel.

19

u/dangerbird2 7d ago

they're not really suggesting you roll your own workflow engine, they're promoting DBOS which already does that

6

u/toastyman1 7d ago

The word 'workflow' is what is throwing me off there - workflows are generally a solution for a distributed systems problem... Maybe this is more suited to durable execution all in process than across many services?

3

u/dangerbird2 7d ago

I'm using the term "workflow", since it's what temporal and DBOS call it. And they both really are designed to solve distributed systems problems; like keeping a web app's database synchronized with external api calls in the event of the later failing, retrying failed activities, or rolling state back if it's not possible. Fundamentally, they're basically apache airflow but for application logic.

And to clarify, things like DBOS aren't really "all in process", it's using postgres as its data store and message queue (using postgres NOTIFY), and in practice you'll have a worker service that actually runs the workflows separate from the API server, even if they share code. Instead of the workers and clients communicating over a dedicated orchestrator like temporal, dbos just uses postgres to do (mostly) the same thing. Which turns out to often being good enough because the distributed systems problems temporal and dbos tend to solve are about consistency and fault tolerance, not scalability.

2

u/toastyman1 6d ago

I think I get it, maybe I'll build a demo with it for myself to see if I can understand why it might useful beyond something like temporal...

Thanks!

3

u/ComicSansSavedMyLife 6d ago

It’s still an issue because it’s baked into how Postgres MVCC works. An update writes a whole new row version, and unless it qualifies as a HOT update, every index gets a new entry too, so you get write amplification and bloat. You can tune autovacuum to survive the load, but that’s managing the symptom. Other DB like a MariaDB handles this natively since InnoDB updates data in-place and manages visibility through an undo log. So there’s no vacuum to tune on that side, though long-running transactions can still make the undo log grow.

4

u/edgmnt_net 7d ago

I would understand some thin abstraction on top of the database, but these also tend to be full blown services. Why do you need them, really? Yes, a basic persistent store will work the same way it works for just about every non-web app. You just have to provide more persistence for web apps due to their nature, but otherwise this is a solved problem for mobile apps, even desktop apps to a significant extent.

2

u/Smallpaul 7d ago

I am struggling to understand this comment. Can you clarify?

These tools are for distributed systems including but not exclusively web apps. You would also want such a thing for long-running finance agents, as an example.

And I don’t know what fundamental point you were trying to make. Could you summarize?

3

u/edgmnt_net 6d ago

I'm trying to say that a certain class of enterprise applications seemingly reinvents the wheel and cannot do basic things without reaching for a bunch of external services that complicate everything including testing. That would be the summary.

I see this a lot. For example, some devs seem completely unwilling to write asynchronous code and just throw in a full-blown message queue service into the mix at the slightest provocation. It's often enough to have a slight mention of queue, messages or notifications pop up in the design and some one will say "ah, a good occasion to throw in Kafka". Even when it can otherwise be done with callbacks or threads/IPC or whatever, the usual way, like we've always done it.

Don't get me wrong, I like well-abstracted stuff that prevents mistakes, but it usually doesn't mean you end up with a conglomerate of needlessly distributed services. Unfortunately, in that ecosystem, most of those things aren't even libraries anymore, they are full blown services, often at least partly proprietary, and bring in nastier possible failure modes (e.g. network failures) that you now need to account for. I can understand that need for standalone databases, at least in a certain context, but taking this too far has costs. It can become a locally-untestable hot mess of dozens of services, with fragile and expensive APIs.

It probably also relates to the idea that a lot of applications are needlessly distributed, i.e. microservices. Yeah, just one more piece doesn't seem like much if you already have a hundred moving parts and you already lost the ability to write, test and merge logical changes easily.

8

u/DreamsTheyStole 6d ago

Using a database instead of running a whole orchestrator like Temporal is a reasonable call. On Postgres, workflow state means lots of row churn, so you get dead tuples and a lot of autovacuum work, and it can get ugly under load if you don’t tune it. InnoDB updates rows in place and keeps old versions in undo logs, and I’ve had a smoother time with MariaDB for this pattern. It also has a thread pool, which helps when a bunch of polling workers hit it at once.

15

u/Perfect_Wall_8905 7d ago

Temporal reached the same conclusion. Use that?

7

u/wizardwusa 7d ago

I find DBOS to have more natural abstractions, require less maintenance, and have less boilerplate. DBOS is sick.

10

u/dangerbird2 7d ago

the main difference is that Temporal is a networked service that can use postgres as a state store and broker, while DBOS is by default just a library you bundle and deploy, with no control plane or dedicated service. So it's significantly easier to deploy than even a minimal temporal instance. DBOS technically does have a control plane, but it's "optional" proprietary extension (arguably its biggest disadvantage, since they have basically zero observability integration in stock OSS DBOS, which is kinda a major problem for a resilient system)

1

u/Grouchy-Coat-4707 6d ago

We've found that most users are happy with configuring their own OTel backend. The DBOS SDKs generate OTel traces: https://docs.dbos.dev/python/reference/configuration#logging-and-tracing-settings

1

u/dangerbird2 6d ago

Oh, I didn't see that in the docs last time I evaluated it. Yeah, as long as there is decent instrumentation, and you can yeet the metrics and traces to an otel collector, it's going to be more than enough

-7

u/mykeof 7d ago

Did Postgres write this?

12

u/jeff303 7d ago

A company trying to sell their durable execution framework based on Postgres did

0

u/mykeof 7d ago

Yea that was gonna be my second guess

1

u/redditor3626 7d ago

Michael Stonebraker is the researcher who led the team that founded Postgres. He is now founder of DBOS.

0

u/Smallpaul 7d ago

Postgres is not an individual nor a corporation, so how could it write something?

3

u/mykeof 7d ago

Yea, it was meant as a joke. Clearly wasn’t obvious!

-8

u/RoyBellingan 7d ago

Next an hard disk and a plain text is all you need ?

8

u/ansible 7d ago

That's the idea behind plain text accounting: https://plaintextaccounting.org/

And no, that isn't a joke website.