Hi everyone,
I’m building a workflow in n8n with two agents:
-
Planner agent — inserts plan to a database and should trigger an executor if no active task exists for a user.
-
Executor agent — executes the plan when triggered.
The logic is:
-
Insert a new plan in DB.
-
Check if there’s an active task for the same user.
-
If no active task, trigger executor.
-
If active task exists, do nothing.
The problem happens when two plans are created at the same time for the same user:
-
Workflow A inserts plan 1.
-
Workflow B inserts plan 2.
-
Both workflows check Redis/DB and see no lock/active task.
-
Both assume no active task and skip triggering executor.
So both tasks get stuck and never run.
To fix this, I tried using Redis as a lock, but n8n’s built-in Redis node doesn’t support atomic locking (SET key NX EX ttl) directly.
Questions:
-
What’s the correct way to implement an atomic Redis lock in n8n so that only one workflow execution can acquire it per user?
-
Are there any recommended solution to the issue I just described?
Any example workflows or configuration tips are appreciated!
Thanks!
Information on your n8n setup
- n8n version: 1.122.5
- Database (default: SQLite): Supabase Postgres
- Running n8n via (Docker, npm, n8n cloud, desktop app): n8n cloud