Bubble Database Atomicity

Is there a way for bubble to handle atomicity using Database Connector?

Say I have 2 queries to simulate sending some money

  1. Update John amount: add $100
  2. Update Mary amount: minus $100

Query 2 fails due to enforcement of a database constraint (say Mary amount is less than 100, and cannot be negative)

However, Query 1 has executed and updated the database, leading to database inconsistency

Is there an implementation to avoid this?

No. You can’t do this on bubble 100% of the time. You might be able to come up with some kind of workaround to lock workflows somehow, but you can never lock the database truly for transactions 100% of the time.

Seems like it might lead to some potentially expensive bugs in a production environment if left unsolved, especially when there’s some complex workflow interacting with the database.
I haven’t deployed an application before so I lack the experience. Was wondering if this is an existing issue within the bubble community when deploying an application live.

I wouldn’t call this an existing issue. Even if you were building a solution with code you’d need to nail the logic on something like this.

A workflow is just going to execute in the order you arrange the steps and depending on how you structure it one thing may or may not be conditional on something else succeeding. So if step 2 or 10 or whatever has the chance of failing then the best way to structure that workflow would be to first validate that the workflow can in fact complete if not you return an error to your user and don’t start executing the steps.

In this case your first step should be to check that Mary has the required money. I would probably do this via a workflow, but you could also do a simple validation on the front end that doesn’t let Mary click the button that starts the workflow if the amount is greater than her balance or whatever. Doing both of these together is even better

Josh @ Support Dept
Helping no-code founders get unstuck fast :rocket:save hours, & ship faster with an expert :man_technologist: on-demand