Handling Concurrent Database Writes

How does Bubble handle concurrent database updates?

Consider the following data structure:

Transaction
amount (number)
balance (number)

Account
balance (number)

User

Consider the case where:

  • A user submits a Transaction to the database
  • A workflow queries the associated users’ Account Balances
  • The Transaction amount + Account balance is saved to the Transaction’s balance field as a new running total.
  • The Account’s balance field is updated to the new Transaction Balance.

Is it at all possible to prevent stale data in the case where two transactions are submitted simultaneously. If an Account with a zero balance receives two transactions crediting the user +100, both transactions would read the current balance as 0, and update the account balance to 100, instead of 200. Any suggestions here?

Are “Schedule API Workflows” guaranteed to execute in order?

Thanks!

Better handling of concurrent database writes is on their agenda.

See…

and

1 Like

@dserber, thanks for the reply, but I don’t see where those links provide an answer to my question.

@emmanuel, mind commenting here?

This something we currently don’t handle well, if workflows happen at the same time and modify the same data it can lead to inconsistent results. That’s quite high on our roadmap, so we’re hoping to fix this soon.

See “Workflow consistency guarantees” at bubble.is/roadmap

3 Likes

I’m running into this issue again. Can you guys provide any sort of ETA on workflow consistency guarantees?

In a scheduled workflow I’m creating a thing if the result of a search’s :count <= 0. But if the workflow is triggered twice in succession, two things are created.

This is app-breaking behavior, that makes it difficult to proceed.

1 Like

I don’t know if this will help for your use case but it helped with mine. Try adding more logic saying that if the if the result of a search’s :count <= 0. AND the last item added to the database is not equal to the result of a search.

Or you could add an exit the workflow workflow before your action that says the same thing. Some of the times it will catch the duplicate.

Hey @csblack ,

I’m having a similar problem… and what I found out that the only way to ensure that type of consistency you are looking with your workflow (creating a thing if the result of a search : count >=0) for high volume data is to purchasing more CPU capacity.

I’m on a professional plan with 2 extra units and now I need to add +5 units. One thing to notice is that my app didn’t go to production yet… So I’m kind concern with my total billing once is running.

@emmanuel - Can’t wait for the “Workflow consistency guarantees” feature!

1 Like