How to avoid a race condition with parallel jobs started by a callback?

Hello.

I had the same problem. I end up using RabbitMQ. I don’t know the ins and outs of RabbitMQ but it is very simple.

Setup a RabbitMQ docker container.

Create a workflow that sends data to rabbitmq and create a trigger rabbitmq node on the workflow you want to run sequentially.

Here is an example.

This is the workflow to send data to RabbitMQ

This is the workflow with the trigger rabbitmq

Activate the trigger in n8n and keep in mind that you have to be careful in RabbitMQ trigger to set the Parallel Message Processing Limit to 1

The way it works is, you start a job and send the message to rabbitmq, then rabbitmq trigger read the queue sequentially. If the job you start fire agains, the message goes to rabbitmq server. The n8n rabbitmq trigger node wait to finish the first message from the queue before running the next request from the message queue.

5 Likes