Stateful Workflow with Teleport Pattern
detail.loadingPreview
Implement a stateful workflow pattern using n8n's 'Teleport' concept for long-running, resumable processes.
About This Workflow
This workflow demonstrates a sophisticated state management pattern in n8n, often referred to as the "Teleport" pattern. It enables the creation of long-running, multi-step processes that can be paused at specific checkpoints and resumed later via external triggers. This is crucial for scenarios like user onboarding, processes awaiting human approval, or maintaining state in chatbots.
The pattern effectively divides the workflow into two logical parts:
- The Main Process: This is where your core business logic resides. It initiates communication with the Async Portal to register its state, performs its tasks, and then pauses at designated 'Checkpoints' (typically
Waitnodes). It awaits an external event to signal its resumption. - The Async Portal: This acts as a state management engine. It keeps track of all active, paused Main Processes, storing their unique session identifiers and their respective 'resume URLs'. When new data arrives, the Portal can intelligently "teleport" this data to the correct, waiting Main Process execution.
Key Features
- State Persistence: Allows workflows to pause execution and retain their state across extended periods.
- External Resumption: Enables workflows to be resumed by external events or data, facilitating asynchronous operations.
- Session Management: Utilizes static workflow data to manage multiple, independent sessions based on unique identifiers.
- Checkpointing: Defines specific points within a workflow where execution can be paused (
Waitnodes). - Resume URL Generation: Automatically creates unique URLs for each paused execution, used for resuming the workflow.
- Error Handling: Includes logic to manage session resets or continuation based on error conditions.
How To Use
Main Process Setup:
- Entry Point (
A. Entry: Receive Session Infoor7f899a48-c96a-417e-957a-a2fa720f6d73): This node (typically aexecuteWorkflowTriggeror similar) receives the initial data for a new session, includingsession_id,resume_url(if applicable),input_items,workflow_id,execution_id, andstop_session_on_error. - Session Check (
B. Check if Session is New or Existingor14e9e8a7-b52b-43a7-a24c-133ed203789f): Thiscodenode uses$getWorkflowStaticData('global')to check if thesession_idalready exists. It stores new sessions and theirresume_urlandexecution_id, or retrieves the existingresume_urlfor a recognized session. - Routing (
C. Route Based on Session Stateor116121f5-8fa4-4d23-80f4-3000511f901a): Anifnode directs the workflow based on whether the session is new or existing. New sessions continue to process, while existing sessions might be handled differently (e.g., teleported to a checkpoint). - Processing (e.g.,
3. Process Initial Data (Before Checkpoint 1)or9c98707e-763a-4022-8996-9ded3f587754): Perform your primary business logic. - Checkpoint (
4. PAUSE at Checkpoint 1or9814ef51-c934-4b71-af89-4d6a3df671ff): Awaitnode configured withresume: webhook. This node pauses the execution, persists its state, and makes itsresume_urlavailable. It also registers this URL with the Async Portal. - Resumption Handling (
5a. Receive Resumed Dataor3bc4a204-04e8-4294-8d52-5fb1ae0d8f95): When the Async Portal sends data to theresume_url, thissplitOutnode receives the payload (usually thebody). - Further Processing: Continue with the next steps of your workflow after resumption.
- Multiple Checkpoints: The workflow can have multiple
waitnodes to allow for sequential pausing and resuming.
Async Portal Setup:
- Trigger (
A. Entry: Receive Session Infoor7f899a48-c96a-417e-957a-a2fa720f6d73): This is the entry point of the portal workflow. It receives data from external sources or the Main Process. - Session Management (
B. Check if Session is New or Existingor14e9e8a7-b52b-43a7-a24c-133ed203789f): Thiscodenode (using$getWorkflowStaticData('global')) is crucial for managing sessions. It stores new session registrations and checks for existing ones. - Routing (
C. Route Based on Session Stateor116121f5-8fa4-4d23-80f4-3000511f901a): Anifnode determines if the incoming request is for a new session or an attempt to resume an existing one. - Teleportation (
D. TELEPORT: Resume Paused Workflowor1ec4313c-df14-4c89-86e7-a51b2462428c): For existing sessions, thishttpRequestnode makes a POST request to the storedresume_urlof the corresponding Main Process execution. This action "teleports" the new data to the paused workflow. - Session Reset/Stop (
Stop Session On Error ?or54bdfb27-85ca-44c5-9cdb-3dc92d44000e,Reset Sessionord8bf9a2d-045d-4bbe-8c85-ca1183a4b86e): Logic to handle cases where a session needs to be reset or terminated, often based on error conditions received from the Main Process. - Completion (
E. Stop This Executionorab925a2d-f8b4-4267-8aa6-f6c2eeb1f150,Respond with Input Itemsorcf9710a0-8f0b-4370-a35e-39b5878f1cc2): Nodes that handle the termination or final response of the Portal's execution.
Key Data Flow:
- The Main Process registers its
resume_urlwith the Portal. - The Portal stores this information and can later use the
resume_urlto send data back to the Main Process. - The
session_idis used by both workflows to correlate states. $getWorkflowStaticData('global')is essential for the Portal to maintain a persistent registry of active sessions.
Apps Used
Workflow JSON
{
"id": "0e585563-9cf6-4311-a60b-8b391d69cda0",
"name": "Stateful Workflow with Teleport Pattern",
"nodes": 5,
"category": "State Management",
"status": "active",
"version": "1.0.0"
}Note: This is a sample preview. The full workflow JSON contains node configurations, credentials placeholders, and execution logic.
Get This Workflow
ID: 0e585563-9cf6...
About the Author
N8N_Community_Pick
Curator
Hand-picked high quality workflows from the global community.
Statistics
Related Workflows
Discover more workflows you might like
Automate Local Business Outreach with AI-Powered Yelp Scraper
This workflow automates the process of scraping local business details from Yelp using AI, then leverages that data to send personalized partnership proposals via Gmail. It's perfect for sales and marketing teams looking to streamline lead generation and outreach campaigns.
Automate Getty Images Editorial Search & CMS Integration
This n8n workflow automates searching for editorial images on Getty Images, extracts key details and embed codes, and prepares them for seamless integration into your Content Management System (CMS), streamlining your content creation process.
Universal CSV to JSON API Converter
Effortlessly transform CSV data into structured JSON with this versatile n8n workflow. Integrate it into any application as a custom API endpoint, supporting various input methods including file uploads and raw text.