Forum Academy Marketplace Showcase Pricing Features

Database - Avoiding 1st Edit Overwriting 2nd Edit

I’ve created a form and have it designed so that whenever a user changes a value, we update our database with the new value immediately.

It seems to me that there’s a bit of a risk that someone updates a field value twice very quickly, and the 2nd change could reach our database before the first one, such that the 1st one overwrites it. And, therefore, the database and client would be out of sync.

What are some good ways to mitigate or eliminate this risk? (we’re using auto-binding where possible, but have instances where we can’t use that)

Thanks!

If you are not using autobinding, can you not lock out the editing until you see the objects modified date change…

1 Like

Thanks @DaveA! This sounds like a smart solution and may work well in several places.

My most recent hurdle is a bit more complex and at first glance seems like it may require a different solution. A few more details:

I’m collecting 3 inputs from users (event start time, event duration, # of minutes per session) and then calculating the start-time of each session within the event (there can be between 1 and 20 sessions during the event). Then, I’m planning to schedule an API workflow (in the future) for each of the session start times.

Note - I suspect I’m going to need to pass this data into our database as well so that I can keep the ID of the scheduled API workflow (which I may need to cancel it), so perhaps there’s still a way to make your approach work.

Any other useful ways to address this type of problem?

Nothing that springs to mind, it is one of those things that unless you start to build and come across the problem, it is hard to think of a solution to the unknown!

Yep, I understand. I can usually think of a few ways to get things done ahead of time, but not on this one, lol.

I regularly run into challenges with this timing risk aspect of website design/architecture so it’d be good for me to get a bit smarter about potential solutions. Yours is definitely useful. I’m sure some other Bubblers have come up with some really creative and effective solutions as well – they always do!

Well I haven’t tried it in Bubble yet, but we talked about it here …

The optimistic lock is probably the one you want.

Thanks @NigelG! Very helpful.

If you are not using autobinding i would suggest you use:
When an input value is changed : Setstate of input “Locked” - “Add a pause bfore next action” - Setstate of input “Unlocked”
Link: https://testyyo.bubbleapps.io/version-test?debug_mode=true
Editor: https://bubble.io/page?name=index&id=testyyo&tab=tabs-1