Hello,
I would like to ask if multiple instance of one automation can run in parallel and if they can, how do I prevent race conditions from happening?
Example
Suppose I have a table with columns “Customer email”, “Is registered” and “Welcome email sent” and an automation that sends a welcome email to every registered customer that has not received it yet. For some reason this automation is triggered by an HTTP request from other my systems.
The automation gets all rows, iterates on them, if the conditions are met it sends and email and then updates the “Welcome email send” field if the mail was sent successfully.
What if two trigger requests are received shortly after each other? Could it happen that some customers receive the welcome email twice?
Thanks for help.
I found the answer in the FAQ in docs: Baserow workflow triggers : Yes, workflows may run concurrently. Therefore it may happen that a welcome email is sent multiple times if there are multiple triggers in a very short time.
Is there a way to prevent this? e.g. is there any locking mechanism so that only one workflow works with each row at one time.
Hello @ygcec2meg, apologies for the delay in getting back to you.
You’re exactly right, our workflows can be executed in parallel.
We don’t currently have any native locking in place, but we are considering a feature where you can optionally choose to allow workflows to be run in parallel, or serially.
In your scenario, you could use a router node to determine if an email has already been sent. You would have two branch conditions:
- Email not sent (the formula condition would be
Welcome email sent = false)
- Send the email
- Update the row to set
Welcome email sent = true
- Email already sent (the default branch)
Regarding this:
For some reason this automation is triggered by an HTTP request from other my systems.
I’m afraid I’m not sure what you mean - the workflow is unexpectedly being executed by another source, other than you?
I think your approach ideally should be per row. When a customer registers, they then receive your email. It simplifies the workflow to:
- Rows created trigger
- Router (as described above)
Welcome email sent = false
- Send your email to
Customer email
- Update row (using your trigger’s row ID), setting
Welcome email sent = true
Welcome email sent = true
Cheers,
Peter Evans
Sorry, that’s a just a misunderstanding. I meant to say “It’s triggered by an HTTP request from my custom app and it doesn’t matter why”
That’s what I’ve decided to do in the end, but the e-mail might still be sent twice if “Send your email to Customer email" takes very long and the workflow is triggered again before Welcome email sent gets set to true.
I guess I will have to live with it for now.