Redis-Backed Idempotency and Item State Tracking Utility - n8n Workflow

Use this robust n8n workflow to prevent duplicate processing by centrally managing item states in Redis. Features include automatic troubleshooting links and detailed audit logging.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Advanced n8n Developers: Users who require high reliability and strict idempotency checks in their automations.
Scalability Engineers: Teams running multiple concurrent n8n workflows that process the same data streams (e.g., webhooks, queues).


  • Technical Operations Teams: Users needing granular control over process state and comprehensive audit logs for troubleshooting production n8n nodes.

Overview

When building complex, event-driven processes, a major challenge is preventing the same item from being processed twice. This often occurs when dealing with queue restarts, retries, or multiple simultaneous executions of an n8n workflow.

This utility solves this by providing a centralized, high-speed state management system using Redis. It acts as a single source of truth for all items being processed. Any parent n8n workflow can query the status (check), set a temporary lock (add), or record a final result (update).

A key feature of this specific n8n workflow is its built-in traceability: it automatically captures the execution ID of the calling workflow and generates a direct link for rapid troubleshooting, publishing this information to a Redis channel for real-time audit logging. This dramatically improves the maintainability of your overall n8n solution architecture.

How it Works

This utility is designed to run as a sub-workflow, triggered by an Execute Workflow n8n node in a parent process.


  1. Incoming Request: The process starts with the Execute Workflow n8n trigger, receiving key parameters like itemId, action (check, add, update, delete), and the parentExecution context.

  2. Context Preparation: The "Set: Context for Response" n8n node constructs the definitive Redis key (keyPrefix:itemId:keySuffix) and enforces a default Time-To-Live (TTL).

  3. Action Routing: The "Switch Action" n8n node routes the flow based on the requested action:

Check: Executes a Redis GET command to see if the key exists. The result determines if the item is already being processed.
Add: Executes a Redis SET command, typically marking the item as inprogress with a short TTL.
Update: Executes a Redis SET command, overwriting the lock with a final status object (e.g., completedsuccess), often with a much longer TTL.
Delete: Executes a Redis DELETE command, removing the tracking key entirely.

  1. Logging and Traceability: The "Code: Prepare Audit Log & Response" n8n node aggregates the context and the Redis result. Crucially, it dynamically generates a clickable URL pointing directly to the parent n8n workflow execution that initiated the request.

  2. Audit Publishing: The resulting log message is published to the redis-audit-log channel via a Redis Publish n8n node, enabling real-time monitoring by the companion logging n8n workflow.

  3. Response: The final clean JSON output, including the success status and the troubleshooting URL, is returned to the calling n8n workflow.

Installation Guide

To deploy this state management system, you will need to import the provided n8n workflow JSON twice (if using the audit listener) and configure credentials.


  1. Import: In your n8n instance, navigate to 'Workflows' and click 'New'. Import this JSON via the clipboard.

  2. Configure Credentials: Ensure you have your Redis credentials configured in n8n. Link these credentials to all "Redis" n8n node instances (Redis: GET, Redis: SET, Redis: DELETE, and the Redis Publish node).

  3. Deploy Audit Listener (Optional but Recommended): This workflow includes a secondary logic path (starting with the 'On new Redis event' n8n trigger) for persistent logging to Google Sheets. If you wish to use this feature, you must:

Deploy the listener portion separately (or ensure the trigger is active).
Set up Google Sheets credentials and link them to the redis-audit-log n8n node.
* Verify the Google Sheet document and sheet names are correctly configured.

  1. Activate: Ensure both the Item Tracker utility workflow and the companion Audit Listener workflow are set to 'Active'. The main Item Tracker should be called using an 'Execute Workflow' n8n node in all other n8n templates.

Node Details

Trigger (from other workflows) (Execute Workflow n8n trigger):
Function: Acts as the entry point, receiving item details (itemId, action) and the execution context (parentExecution) from a calling n8n workflow.
Key Configuration: Defines expected inputs like keyPrefix, itemId, and action to ensure robust inputs.
Set: Context for Response (Set n8n node):
Function: Prepares necessary variables, including calculating the fullKey (e.g., prefix:id:suffix) and setting a default TTL.
Switch Action (Switch n8n node):
Function: Routes the execution flow precisely based on the requested action (check, add, delete, update), ensuring the correct Redis operation n8n node is executed.
Redis: GET (Check Processed) (Redis n8n node):
Function: Used for the check action to query Redis and determine if the item tracking key already exists.
Redis: SET (Add to Processed) / Redis: SET (Update Result) (Redis n8n node):
Function: Sets or updates the item's state in Redis, implementing the temporary lock (add) or recording the final outcome (update).
Code: Prepare Audit Log & Response (Code n8n node):
Function: This crucial custom code n8n node builds the final response payload, generates a detailed audit log entry, and calculates a direct, clickable troubleshootExecutionUrl to the originating n8n workflow execution.
To_redis-audit-log (Redis n8n node - Publish):
* Function: Publishes the structured audit log JSON string to a Redis channel (redis-audit-log), decoupling the logging task from the main execution flow.

Related n8n Workflows

Free

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

Account Executive by day , Noco builder for fun at night and always a proud dad of Togo the Samoyed.

Featured*