Redis Locking for Reliable Concurrent Task Execution - n8n Workflow

Use this sophisticated n8n workflow template utilizing Redis to manage concurrency, prevent race conditions, and ensure reliable, idempotent execution of critical tasks triggered by webhooks.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Developers and engineers seeking to implement robust concurrency controls in their automation systems.
Users scaling their n8n deployments who need to prevent race conditions when handling external triggers.
Anyone utilizing n8n templates for critical, idempotent business processes.
Technical users who want advanced examples of flow control within an n8n workflow.

Overview

Handling external triggers, such as webhooks, often leads to concurrency issues, especially when the same resource is triggered multiple times rapidly. This scenario can result in race conditions, corrupted data, or resource exhaustion. This robust n8n workflow template solves this problem by integrating a Redis-based locking mechanism.

When a request hits the n8n trigger, the system attempts to acquire a unique lock associated with the task data. If the lock is already held by a concurrent n8n execution, the new execution either waits (polls) or is discarded as a duplicate, ensuring that the primary logic (simulated by 'Workflow 1/2/3') runs exactly once per unique resource. This is a professional-grade implementation of flow control within an n8n environment, showcasing how to build resilient automation using the standard n8n node set and an external Redis instance.

How it Works

This complex n8n workflow begins when the Incoming Webhook Data n8n trigger receives a payload.


  1. Data Preparation and Lock Value Generation: The Fetch Webhook Data & Declare lockValue n8n node (a Code node) parses the incoming data (var1, var2, var3) and concatenates them to create a unique identifier, lockValue.

  2. Initial Lock Check: The Check Redis Lock n8n node attempts to retrieve the current value of the lock key (xyz-lock) from Redis.

  3. Concurrency Decision: The redisLock existence boolean If n8n node checks if the lock key exists.

If the lock does not exist (no running process), the n8n workflow proceeds to Acquire Redis Lock.
If the lock does exist, the flow moves to another check (redisLock acquired booleans).

  1. Lock Acquisition and Task Execution: The Acquire Redis Lock n8n node sets the key with the unique lockValue and a 180-second TTL (Time To Live), effectively acquiring the lock. The n8n workflow then routes execution through the Workflow Switch to one of the simulated core tasks (Workflow 1, Workflow 2, or Workflow 3).

  2. Waiting and Polling (Contention): If the lock was already held (Step 3), the workflow moves through the If n8n node to Poll for lock (Wait node), pausing execution until the resource might be available.

  3. Duplicate Handling: After polling, the duplicateWebhook boolean If n8n node checks if the unique lockValue now matches the lock key's value. If it matches, it means a concurrent n8n execution successfully completed the task, and the current n8n instance is terminated via the END n8n node.

  4. Lock Release: Once the core tasks (Workflow 1/2/3) are complete, the final Discard Redis Lock n8n node deletes the lock key from Redis, releasing the lock for future tasks. This ensures the high reliability of the entire n8n workflow.

Installation Guide

To use this reliable n8n workflow template, follow these steps:


  1. Import the JSON: Copy the n8n workflow JSON provided and import it into your n8n instance.

  2. Redis Credentials: Ensure you have a Redis credential configured. The provided workflow uses credentials named 'Geoffrey Redis'. Update the Check Redis Lock, Acquire Redis Lock, and Discard Redis Lock n8n nodes to use your active Redis credentials.

  3. Webhook Setup: Activate the Incoming Webhook Data n8n trigger and copy the test or production webhook URL.

  4. Custom Code Adjustment: Review the Fetch Webhook Data & Declare lockValue n8n node. Adjust the parsing logic if your external system sends data fields other than var1, var2, and var3 to ensure your unique lockValue is correctly constructed.

  5. Core Logic: Replace the placeholder Set n8n nodes (Workflow 1, Workflow 2, Workflow 3) with your actual automation logic that needs concurrency protection.

Node Details

Incoming Webhook Data (n8n trigger): The entry point for the n8n workflow. Configured to listen for incoming HTTP requests that initiate the task.
Fetch Webhook Data & Declare lockValue (Code n8n node): Crucial for defining task uniqueness. It parses the payload and generates a unique string (e.g., var1-var2-var3) which serves as the identifier used in the Redis lock.
Check Redis Lock (Redis n8n node, GET): Retrieves the current value of the lock key (xyz-lock). This is the primary concurrency check in this n8n node flow.
Acquire Redis Lock (Redis n8n node, SET): Attempts to acquire the lock. Configured with a TTL (Time To Live) of 180 seconds to prevent permanent locks if the n8n workflow fails mid-execution.
If n8n nodes (Multiple): Used extensively for flow control based on Redis results, directing the n8n workflow path: checking for lock existence (redisLock existence boolean), verifying acquisition status, and handling duplicates after polling.
Poll for lock (Wait n8n node): Implements a polling mechanism, pausing the n8n workflow instance when contention is detected.
Workflow 1/2/3 (Set n8n nodes): Placeholder n8n nodes representing the actual, resource-intensive tasks protected by the Redis lock.
Discard Redis Lock (Redis n8n node, DELETE): Releases the lock by deleting the key (n8n-rca-lock—note that the key name changes slightly here from the acquisition step, which should be corrected for a perfect template, but its function is lock removal), guaranteeing the next task can proceed successfully.

Related n8n Workflows

Free

Nodes: 9 Nodes
Updated: December 26 2025
View all
Created by
Geoffrey Saxena
Geoffrey Saxena

Featured*