Distributed Workflow Execution Lock using Redis - n8n Workflow

Use this powerful n8n workflow template to prevent simultaneous executions of critical workflows using Redis as a distributed locking mechanism. Ensures reliable, sequential n8n automation.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Users running mission-critical, scheduled n8n workflows that must execute sequentially.
Developers needing reliable concurrency control in their n8n templates.
DevOps engineers looking to implement robust execution monitoring and flow control using an n8n node.
Anyone self-hosting n8n and requiring shared state management across processes.

Overview

When dealing with mission-critical processes that cannot tolerate parallel execution—such as syncing data or processing financial batches—it is crucial to ensure only one instance of the job runs at a time. This specific n8n workflow provides a robust solution by implementing a distributed lock using Redis. Every time the n8n trigger fires, the system checks a dedicated status flag in Redis. If the flag is 'idle', the n8n workflow proceeds, sets the flag to 'running', executes the target workflow, and finally resets the flag to 'idle'. If the flag is already 'running', the execution is immediately terminated. This ensures sequential processing, making this pattern an essential technique for reliable high-frequency n8n automation using shared state managed by a Redis n8n node.

How it Works


  1. Scheduled Activation: The process begins with the Schedule n8n trigger, configured to run at a high frequency (e.g., every 5 seconds).

  2. Redis Status Check: The Get Status Redis n8n node dynamically retrieves the current lock status (workflowStatus_{{ $workflow.id }}) associated with this specific n8n workflow.

  3. Key Validation & Existence: An If n8n node (Redis Key exists) first confirms if the status key exists in Redis. If it doesn't exist, the workflow assumes it is safe to proceed and sets the lock.

  4. Concurrency Gate: A Filter n8n node (Continue if Idle) performs the core concurrency check, ensuring the n8n workflow only proceeds if the retrieved status value is strictly 'idle'. If the status is 'running', the execution stops here, preventing simultaneous runs.

  5. Set Running Lock: If cleared for execution, the Set Running Redis n8n node updates the Redis key to 'running', establishing the distributed lock.

  6. Execute Main Workflow: The Execute Workflow n8n node runs the target critical n8n workflow using its specified ID. This n8n node is configured to always continue execution to the next step, even if the sub-workflow fails.

  7. Release Idle Lock: Finally, the Set Idle Redis n8n node releases the lock by setting the status key back to 'idle', making the system ready for the next scheduled n8n trigger. This completes the cycle for one successful execution of the n8n workflow.

Installation Guide


  1. Import this n8n workflow JSON code into your n8n instance.

  2. Redis Credentials: Configure a Redis credential within your n8n setup. All Redis n8n nodes (Get Status, Set Running, Set Idle) must use this credential.

  3. Configure Target Workflow ID: Locate the Execute Workflow n8n node. You must update the Workflow ID parameter to match the ID of the critical n8n workflow you intend to protect from concurrent execution.

  4. Set Initial State: The workflow includes a troubleshooting section (currently disabled). Before activating the Schedule n8n trigger, it is highly recommended to manually activate and run the When clicking "Test workflow" -> Reset to Idle chain once to ensure the Redis key is initialized to 'idle' and the lock is free.

  5. Activate: Save and activate the Schedule n8n trigger to begin monitoring for execution windows.

Node Details

Schedule Trigger: This essential n8n trigger initiates the entire process on a timed basis (e.g., every 5 seconds). The frequency is adjustable based on the requirement of the protected n8n workflow.
Redis Node (Get Status): Reads the dynamic status key (workflowStatus_{{ $workflow.id }}) from Redis. This n8n node is vital for retrieving the current lock state.
If Node (Redis Key exists): Checks if the Redis status variable is populated. If the key is empty, the n8n workflow assumes a clean slate and proceeds to set the running lock.
Filter Node (Continue if Idle): This n8n node acts as the concurrency gate, only allowing data items through if the status key value strictly matches "idle".
Redis Node (Set Running / Set Idle): These two Redis n8n nodes manage the distributed lock. Set Running obtains the lock before execution, and Set Idle releases the lock after the Execute Workflow n8n node finishes.
Execute Workflow: The core action n8n node that calls and executes the separate, protected n8n workflow. Setting the correct Workflow ID here is critical.


  • Sticky Note n8n nodes: Used throughout the template to provide necessary context, especially around setting intervals and troubleshooting steps like manually resetting the status flag to 'idle'.

Related n8n Workflows

Free

Nodes: 8 Nodes
Updated: December 26 2025
View all
Created by

Workflow Optimization Expert | Software Architect. Use my link to book an initial consultation for custom built workflows using n8n.

Featured*