Prevent Concurrent Runs Using Redis Locking - n8n Workflow

Use this robust n8n workflow template utilizing Redis to implement locking mechanisms, preventing concurrent execution of critical automation tasks in your n8n workflows.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Automation developers building highly available n8n workflows.
Users requiring synchronization for critical tasks (e.g., database updates or expensive API calls).


  • Anyone looking for advanced flow control mechanisms within an n8n node structure.

Overview

Complex business processes often require synchronization to prevent data corruption or resource overload caused by simultaneous execution. This n8n workflow template provides a robust solution by leveraging Redis as a centralized locking service. When a master n8n workflow starts, it attempts to acquire a lock (set a key in Redis). If the key already exists, the execution stops, preventing concurrent runs. Once the process finishes, the lock is released (key is unset). This reusable n8n workflow handles the entire Redis interaction logic (Get, Set, Unset) via an Execute Workflow Trigger node, allowing any other n8n workflow to easily manage concurrency using simple input parameters.

How it Works

This powerful n8n workflow is designed to be called by other n8n workflows (using the Execute Workflow node) to manage process state in Redis.

1. The Core Redis Logic (Reusable Component)

The automation starts with the When Executed by Another Workflow n8n trigger, expecting inputs for action (get, set, unset), key, value, and timeout. The Set Timeout node ensures a 600-second default expiration for the lock.

Routing: A Switch n8n node inspects the action input to determine the required Redis operation.
get action: The Get Key n8n node retrieves the status of the specific process key from Redis. If the result is null, the process is free to run.
set action: The Set Key n8n node creates or updates the key with the specified value (e.g., "working") and sets a TTL (timeout), acquiring the lock.
unset action: The UnSet Key n8n node deletes the key from Redis, releasing the lock.

2. Implementation Example (Preventing Duplicates)

The example section shows how a separate n8n workflow can use this logic:


  1. A standard n8n trigger (e.g., When clicking ‘Test workflow’) starts the execution.

  2. Check Status: An Execute Workflow n8n node calls the Redis logic with action: get to check for an existing lock.

  3. Concurrency Check: An If n8n node checks if the output from Redis is empty. If it finds an existing key (meaning the workflow is already running), the flow executes the Stop and Error n8n node, halting the execution.

  4. Acquire Lock: If the key is empty, the flow proceeds to an Execute Workflow n8n node with action: set to acquire the lock.

  5. Main Task: The heavy-lifting part of your n8n workflow runs (represented by the No Operation and Wait nodes).

  6. Release Lock: Finally, an Execute Workflow n8n node with action: unset releases the lock, making the n8n workflow template ready for the next execution.

Installation Guide

To deploy this comprehensive n8n workflow, follow these steps:


  1. Import the n8n workflow JSON: In your n8n instance, click '+ New' > 'Import from JSON' and paste the provided code.

  2. Configure Redis Credentials: Locate the Get Key, Set Key, and UnSet Key Redis n8n node instances (in the center column). You must configure a valid Redis credential for each.

Click the Redis n8n node.
Under 'Credentials', select or create a new 'Redis account' connection, providing your server hostname and port.

  1. Configure Execute Workflow Nodes: This template uses the Execute Workflow n8n node to call itself recursively. You must update the Workflow ID in all Execute Workflow nodes (like Is Workflow Active, Set Workflow Active, etc.) to point to the ID of this newly imported n8n workflow. The ID is visible in the browser URL when editing the workflow.

  2. Testing: Use the example sections (Example 1 and 2) starting from the When clicking ‘Test workflow’ n8n trigger to test the locking mechanism. Running it twice quickly should result in an error on the second run.

Node Details

When Executed by Another Workflow (n8n Trigger): Serves as the entry point for the reusable Redis locking logic, accepting dynamic inputs (action, key, value, timeout) from other n8n templates.
Set Timeout (n8n node): Ensures that the lock acquired in Redis has a default Time To Live (TTL) of 600 seconds, preventing indefinite lock retention if the workflow fails.
Switch (n8n node): Routes the execution based on the desired action (get, set, or unset), directing the flow to the appropriate Redis operation.
Redis (Get Key, Set Key, UnSet Key) (n8n node): These are the core locking nodes. They interact directly with the Redis instance to perform key retrieval (get), key setting with expiration (set), and key deletion (delete/unset). Keys are dynamically named using the input key (e.g., processstatus{{ $json.key }}).
Execute Workflow (n8n node): Used in the example sections to call the core Redis logic with specific parameters (e.g., checking for an existing lock with action: get, or acquiring a lock with action: set).
If (n8n node): Crucial for the concurrency check. It inspects the output of the 'get' action. If the Redis key exists (output is not empty), it prevents the workflow from continuing by routing to the Stop and Error n8n node.


  • Stop and Error (n8n node): Ensures that if a concurrent run is detected, the second instance of the n8n workflow immediately terminates with a clear error message.

Related n8n Workflows

Free

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

Hobbyist n8n automation maker, I build custom automations for people.

Featured*