n8n-workflow-patterns
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesen8n Workflow Patterns
n8n工作流模式
Proven architectural patterns for building n8n workflows.
用于构建n8n工作流的经过验证的架构模式。
The 5 Core Patterns
5种核心模式
Based on analysis of real workflow usage:
-
Webhook Processing (Most Common)
- Receive HTTP requests → Process → Output
- Pattern: Webhook → Validate → Transform → Respond/Notify
-
- Fetch from REST APIs → Transform → Store/Use
- Pattern: Trigger → HTTP Request → Transform → Action → Error Handler
-
Database Operations
- Read/Write/Sync database data
- Pattern: Schedule → Query → Transform → Write → Verify
-
AI Agent Workflow
- AI agents with tools and memory
- Pattern: Trigger → AI Agent (Model + Tools + Memory) → Output
-
Scheduled Tasks
- Recurring automation workflows
- Pattern: Schedule → Fetch → Process → Deliver → Log
基于对真实工作流使用情况的分析:
-
Webhook处理(最常见)
- 接收HTTP请求 → 处理 → 输出
- 模式:Webhook → 验证 → 转换 → 响应/通知
-
- 从REST API获取数据 → 转换 → 存储/使用
- 模式:触发器 → HTTP请求 → 转换 → 操作 → 错误处理
-
数据库操作
- 读取/写入/同步数据库数据
- 模式:调度 → 查询 → 转换 → 写入 → 验证
-
AI Agent工作流
- 具备工具和记忆功能的AI Agent
- 模式:触发器 → AI Agent(模型 + 工具 + 记忆)→ 输出
-
定时任务
- 周期性自动化工作流
- 模式:调度 → 获取 → 处理 → 交付 → 日志
Pattern Selection Guide
模式选择指南
When to use each pattern:
各模式的适用场景:
Webhook Processing - Use when:
- Receiving data from external systems
- Building integrations (Slack commands, form submissions, GitHub webhooks)
- Need instant response to events
- Example: "Receive Stripe payment webhook → Update database → Send confirmation"
HTTP API Integration - Use when:
- Fetching data from external APIs
- Synchronizing with third-party services
- Building data pipelines
- Example: "Fetch GitHub issues → Transform → Create Jira tickets"
Database Operations - Use when:
- Syncing between databases
- Running database queries on schedule
- ETL workflows
- Example: "Read Postgres records → Transform → Write to MySQL"
AI Agent Workflow - Use when:
- Building conversational AI
- Need AI with tool access
- Multi-step reasoning tasks
- Example: "Chat with AI that can search docs, query database, send emails"
Scheduled Tasks - Use when:
- Recurring reports or summaries
- Periodic data fetching
- Maintenance tasks
- Example: "Daily: Fetch analytics → Generate report → Email team"
Webhook处理 - 适用于:
- 接收外部系统的数据
- 构建集成(Slack命令、表单提交、GitHub webhook)
- 需要对事件做出即时响应
- 示例:“接收Stripe支付webhook → 更新数据库 → 发送确认通知”
HTTP API集成 - 适用于:
- 从外部API获取数据
- 与第三方服务同步
- 构建数据管道
- 示例:“获取GitHub问题 → 转换 → 创建Jira工单”
数据库操作 - 适用于:
- 数据库之间的同步
- 按计划运行数据库查询
- ETL工作流
- 示例:“读取Postgres记录 → 转换 → 写入MySQL”
AI Agent工作流 - 适用于:
- 构建对话式AI
- 需要具备工具访问能力的AI
- 多步骤推理任务
- 示例:“与可搜索文档、查询数据库、发送邮件的AI聊天”
定时任务 - 适用于:
- 周期性报告或摘要
- 定期数据获取
- 维护任务
- 示例:“每日:获取分析数据 → 生成报告 → 发送给团队邮箱”
Common Workflow Components
通用工作流组件
All patterns share these building blocks:
所有模式都包含以下构建模块:
1. Triggers
1. 触发器
- Webhook - HTTP endpoint (instant)
- Schedule - Cron-based timing (periodic)
- Manual - Click to execute (testing)
- Polling - Check for changes (intervals)
- Webhook - HTTP端点(即时触发)
- 调度 - 基于Cron的定时(周期性)
- 手动 - 点击执行(测试用)
- 轮询 - 检查变更(按时间间隔)
2. Data Sources
2. 数据源
- HTTP Request - REST APIs
- Database nodes - Postgres, MySQL, MongoDB
- Service nodes - Slack, Google Sheets, etc.
- Code - Custom JavaScript/Python
- HTTP请求 - REST API
- 数据库节点 - Postgres、MySQL、MongoDB
- 服务节点 - Slack、Google Sheets等
- 代码 - 自定义JavaScript/Python
3. Transformation
3. 转换
- Set - Map/transform fields
- Code - Complex logic
- IF/Switch - Conditional routing
- Merge - Combine data streams
- 设置 - 映射/转换字段
- 代码 - 复杂逻辑
- IF/开关 - 条件路由
- 合并 - 合并数据流
4. Outputs
4. 输出
- HTTP Request - Call APIs
- Database - Write data
- Communication - Email, Slack, Discord
- Storage - Files, cloud storage
- HTTP请求 - 调用API
- 数据库 - 写入数据
- 通信 - 邮件、Slack、Discord
- 存储 - 文件、云存储
5. Error Handling
5. 错误处理
- Error Trigger - Catch workflow errors
- IF - Check for error conditions
- Stop and Error - Explicit failure
- Continue On Fail - Per-node setting
- 错误触发器 - 捕获工作流错误
- IF - 检查错误条件
- 停止并报错 - 显式失败
- 失败后继续 - 节点级设置
Workflow Creation Checklist
工作流创建检查清单
When building ANY workflow, follow this checklist:
构建任何工作流时,请遵循以下检查清单:
Planning Phase
规划阶段
- Identify the pattern (webhook, API, database, AI, scheduled)
- List required nodes (use search_nodes)
- Understand data flow (input → transform → output)
- Plan error handling strategy
- 确定模式(webhook、API、数据库、AI、定时)
- 列出所需节点(使用search_nodes)
- 理解数据流(输入 → 转换 → 输出)
- 规划错误处理策略
Implementation Phase
实现阶段
- Create workflow with appropriate trigger
- Add data source nodes
- Configure authentication/credentials
- Add transformation nodes (Set, Code, IF)
- Add output/action nodes
- Configure error handling
- 使用合适的触发器创建工作流
- 添加数据源节点
- 配置认证/凭证
- 添加转换节点(设置、代码、IF)
- 添加输出/操作节点
- 配置错误处理
Validation Phase
验证阶段
- Validate each node configuration (validate_node)
- Validate complete workflow (validate_workflow)
- Test with sample data
- Handle edge cases (empty data, errors)
- 验证每个节点的配置(validate_node)
- 验证完整工作流(validate_workflow)
- 使用示例数据测试
- 处理边缘情况(空数据、错误)
Deployment Phase
部署阶段
- Review workflow settings (execution order, timeout, error handling)
- Activate workflow using operation
activateWorkflow - Monitor first executions
- Document workflow purpose and data flow
- 检查工作流设置(执行顺序、超时、错误处理)
- 使用操作激活工作流
activateWorkflow - 监控首次执行情况
- 记录工作流用途和数据流
Data Flow Patterns
数据流模式
Linear Flow
线性流
Trigger → Transform → Action → EndUse when: Simple workflows with single path
触发器 → 转换 → 操作 → 结束适用场景:单一路径的简单工作流
Branching Flow
分支流
Trigger → IF → [True Path]
└→ [False Path]Use when: Different actions based on conditions
触发器 → IF → [真路径]
└→ [假路径]适用场景:根据条件执行不同操作
Parallel Processing
并行处理
Trigger → [Branch 1] → Merge
└→ [Branch 2] ↗Use when: Independent operations that can run simultaneously
触发器 → [分支1] → 合并
└→ [分支2] ↗适用场景:可同时运行的独立操作
Loop Pattern
循环模式
Trigger → Split in Batches → Process → Loop (until done)Use when: Processing large datasets in chunks
触发器 → 分批拆分 → 处理 → 循环(直到完成)适用场景:分块处理大型数据集
Error Handler Pattern
错误处理模式
Main Flow → [Success Path]
└→ [Error Trigger → Error Handler]Use when: Need separate error handling workflow
主流程 → [成功路径]
└→ [错误触发器 → 错误处理]适用场景:需要独立的错误处理工作流
Common Gotchas
常见陷阱
1. Webhook Data Structure
1. Webhook数据结构
Problem: Can't access webhook payload data
Solution: Data is nested under
$json.bodyjavascript
❌ {{$json.email}}
✅ {{$json.body.email}}See: n8n Expression Syntax skill
问题:无法访问webhook负载数据
解决方案:数据嵌套在下
$json.bodyjavascript
❌ {{$json.email}}
✅ {{$json.body.email}}参考:n8n表达式语法技能
2. Multiple Input Items
2. 多输入项
Problem: Node processes all input items, but I only want one
Solution: Use "Execute Once" mode or process first item only
javascript
{{$json[0].field}} // First item only问题:节点处理所有输入项,但我只需要一个
解决方案:使用“仅执行一次”模式或仅处理第一个项
javascript
{{$json[0].field}} // 仅第一个项3. Authentication Issues
3. 认证问题
Problem: API calls failing with 401/403
Solution:
- Configure credentials properly
- Use the "Credentials" section, not parameters
- Test credentials before workflow activation
问题:API调用返回401/403错误
解决方案:
- 正确配置凭证
- 使用“凭证”部分,而非参数
- 激活工作流前测试凭证
4. Node Execution Order
4. 节点执行顺序
Problem: Nodes executing in unexpected order
Solution: Check workflow settings → Execution Order
- v0: Top-to-bottom (legacy)
- v1: Connection-based (recommended)
问题:节点执行顺序不符合预期
解决方案:检查工作流设置 → 执行顺序
- v0:从上到下(旧版)
- v1:基于连接(推荐)
5. Expression Errors
5. 表达式错误
Problem: Expressions showing as literal text
Solution: Use {{}} around expressions
- See n8n Expression Syntax skill for details
问题:表达式显示为文本字面量
解决方案:在表达式前后使用{{}}
- 详情请参考n8n表达式语法技能
Integration with Other Skills
与其他技能的集成
These skills work together with Workflow Patterns:
n8n MCP Tools Expert - Use to:
- Find nodes for your pattern (search_nodes)
- Understand node operations (get_node)
- Create workflows (n8n_create_workflow)
- Deploy templates (n8n_deploy_template)
- Use ai_agents_guide for AI pattern guidance
n8n Expression Syntax - Use to:
- Write expressions in transformation nodes
- Access webhook data correctly ({{$json.body.field}})
- Reference previous nodes ({{$node["Node Name"].json.field}})
n8n Node Configuration - Use to:
- Configure specific operations for pattern nodes
- Understand node-specific requirements
n8n Validation Expert - Use to:
- Validate workflow structure
- Fix validation errors
- Ensure workflow correctness before deployment
以下技能可与工作流模式配合使用:
n8n MCP工具专家 - 用于:
- 查找适用于你的模式的节点(search_nodes)
- 理解节点操作(get_node)
- 创建工作流(n8n_create_workflow)
- 部署模板(n8n_deploy_template)
- 使用ai_agents_guide获取AI模式指导
n8n表达式语法 - 用于:
- 在转换节点中编写表达式
- 正确访问webhook数据({{$json.body.field}})
- 引用之前的节点({{$node["Node Name"].json.field}})
n8n节点配置 - 用于:
- 为模式节点配置特定操作
- 理解节点特定要求
n8n验证专家 - 用于:
- 验证工作流结构
- 修复验证错误
- 确保工作流在部署前正确无误
Pattern Statistics
模式统计
Common workflow patterns:
Most Common Triggers:
- Webhook - 35%
- Schedule (periodic tasks) - 28%
- Manual (testing/admin) - 22%
- Service triggers (Slack, email, etc.) - 15%
Most Common Transformations:
- Set (field mapping) - 68%
- Code (custom logic) - 42%
- IF (conditional routing) - 38%
- Switch (multi-condition) - 18%
Most Common Outputs:
- HTTP Request (APIs) - 45%
- Slack - 32%
- Database writes - 28%
- Email - 24%
Average Workflow Complexity:
- Simple (3-5 nodes): 42%
- Medium (6-10 nodes): 38%
- Complex (11+ nodes): 20%
常见工作流模式:
最常见的触发器:
- Webhook - 35%
- 调度(周期性任务)- 28%
- 手动(测试/管理)- 22%
- 服务触发器(Slack、邮件等)- 15%
最常见的转换:
- 设置(字段映射)- 68%
- 代码(自定义逻辑)- 42%
- IF(条件路由)- 38%
- 开关(多条件)- 18%
最常见的输出:
- HTTP请求(API)- 45%
- Slack - 32%
- 数据库写入 - 28%
- 邮件 - 24%
平均工作流复杂度:
- 简单(3-5个节点):42%
- 中等(6-10个节点):38%
- 复杂(11个以上节点):20%
Quick Start Examples
快速入门示例
Example 1: Simple Webhook → Slack
示例1:简单Webhook → Slack
1. Webhook (path: "form-submit", POST)
2. Set (map form fields)
3. Slack (post message to #notifications)1. Webhook(路径:"form-submit",POST)
2. 设置(映射表单字段)
3. Slack(向#notifications发送消息)Example 2: Scheduled Report
示例2:定时报告
1. Schedule (daily at 9 AM)
2. HTTP Request (fetch analytics)
3. Code (aggregate data)
4. Email (send formatted report)
5. Error Trigger → Slack (notify on failure)1. 调度(每日上午9点)
2. HTTP请求(获取分析数据)
3. 代码(聚合数据)
4. 邮件(发送格式化报告)
5. 错误触发器 → Slack(失败时通知)Example 3: Database Sync
示例3:数据库同步
1. Schedule (every 15 minutes)
2. Postgres (query new records)
3. IF (check if records exist)
4. MySQL (insert records)
5. Postgres (update sync timestamp)1. 调度(每15分钟一次)
2. Postgres(查询新记录)
3. IF(检查是否存在记录)
4. MySQL(插入记录)
5. Postgres(更新同步时间戳)Example 4: AI Assistant
示例4:AI助手
1. Webhook (receive chat message)
2. AI Agent
├─ OpenAI Chat Model (ai_languageModel)
├─ HTTP Request Tool (ai_tool)
├─ Database Tool (ai_tool)
└─ Window Buffer Memory (ai_memory)
3. Webhook Response (send AI reply)1. Webhook(接收聊天消息)
2. AI Agent
├─ OpenAI聊天模型(ai_languageModel)
├─ HTTP请求工具(ai_tool)
├─数据库工具(ai_tool)
└─窗口缓冲记忆(ai_memory)
3. Webhook响应(发送AI回复)Example 5: API Integration
示例5:API集成
1. Manual Trigger (for testing)
2. HTTP Request (GET /api/users)
3. Split In Batches (process 100 at a time)
4. Set (transform user data)
5. Postgres (upsert users)
6. Loop (back to step 3 until done)1. 手动触发器(测试用)
2. HTTP请求(GET /api/users)
3. 分批拆分(每次处理100条)
4. 设置(转换用户数据)
5. Postgres(更新或插入用户)
6. 循环(回到步骤3直到完成)Detailed Pattern Files
详细模式文档
For comprehensive guidance on each pattern:
- webhook_processing.md - Webhook patterns, data structure, response handling
- http_api_integration.md - REST APIs, authentication, pagination, retries
- database_operations.md - Queries, sync, transactions, batch processing
- ai_agent_workflow.md - AI agents, tools, memory, langchain nodes
- scheduled_tasks.md - Cron schedules, reports, maintenance tasks
如需各模式的全面指导:
- webhook_processing.md - Webhook模式、数据结构、响应处理
- http_api_integration.md - REST API、认证、分页、重试
- database_operations.md - 查询、同步、事务、批量处理
- ai_agent_workflow.md - AI Agent、工具、记忆、langchain节点
- scheduled_tasks.md - Cron调度、报告、维护任务
Real Template Examples
真实模板示例
From n8n template library:
Template #2947: Weather to Slack
- Pattern: Scheduled Task
- Nodes: Schedule → HTTP Request (weather API) → Set → Slack
- Complexity: Simple (4 nodes)
Webhook Processing: Most common pattern
- Most common: Form submissions, payment webhooks, chat integrations
HTTP API: Common pattern
- Most common: Data fetching, third-party integrations
Database Operations: Common pattern
- Most common: ETL, data sync, backup workflows
AI Agents: Growing in usage
- Most common: Chatbots, content generation, data analysis
Use and from n8n-mcp tools to find examples!
search_templatesget_template来自n8n模板库:
模板#2947:天气到Slack
- 模式:定时任务
- 节点:调度 → HTTP请求(天气API)→ 设置 → Slack
- 复杂度:简单(4个节点)
Webhook处理:最常见的模式
- 最常见场景:表单提交、支付webhook、聊天集成
HTTP API:常见模式
- 最常见场景:数据获取、第三方集成
数据库操作:常见模式
- 最常见场景:ETL、数据同步、备份工作流
AI Agent:使用率增长中
- 最常见场景:聊天机器人、内容生成、数据分析
使用n8n-mcp工具中的和查找示例!
search_templatesget_templateBest Practices
最佳实践
✅ Do
✅ 建议
- Start with the simplest pattern that solves your problem
- Plan your workflow structure before building
- Use error handling on all workflows
- Test with sample data before activation
- Follow the workflow creation checklist
- Use descriptive node names
- Document complex workflows (notes field)
- Monitor workflow executions after deployment
- 从能解决问题的最简单模式开始
- 构建前规划工作流结构
- 为所有工作流添加错误处理
- 激活前使用示例数据测试
- 遵循工作流创建检查清单
- 使用描述性的节点名称
- 为复杂工作流添加文档(备注字段)
- 部署后监控工作流执行情况
❌ Don't
❌ 不建议
- Build workflows in one shot (iterate! avg 56s between edits)
- Skip validation before activation
- Ignore error scenarios
- Use complex patterns when simple ones suffice
- Hardcode credentials in parameters
- Forget to handle empty data cases
- Mix multiple patterns without clear boundaries
- Deploy without testing
- 一次性构建工作流(要迭代!平均每次编辑间隔56秒)
- 激活前跳过验证
- 忽略错误场景
- 能用简单模式时使用复杂模式
- 在参数中硬编码凭证
- 忘记处理空数据情况
- 无清晰边界地混合多种模式
- 未测试就部署
Summary
总结
Key Points:
- 5 core patterns cover 90%+ of workflow use cases
- Webhook processing is the most common pattern
- Use the workflow creation checklist for every workflow
- Plan pattern → Select nodes → Build → Validate → Deploy
- Integrate with other skills for complete workflow development
Next Steps:
- Identify your use case pattern
- Read the detailed pattern file
- Use n8n MCP Tools Expert to find nodes
- Follow the workflow creation checklist
- Use n8n Validation Expert to validate
Related Skills:
- n8n MCP Tools Expert - Find and configure nodes
- n8n Expression Syntax - Write expressions correctly
- n8n Validation Expert - Validate and fix errors
- n8n Node Configuration - Configure specific operations
关键点:
- 5种核心模式覆盖90%以上的工作流使用场景
- Webhook处理是最常见的模式
- 为每个工作流使用工作流创建检查清单
- 规划模式 → 选择节点 → 构建 → 验证 → 部署
- 与其他技能集成以完成完整的工作流开发
下一步:
- 确定你的用例模式
- 阅读详细的模式文档
- 使用n8n MCP工具专家查找节点
- 遵循工作流创建检查清单
- 使用n8n验证专家进行验证
相关技能:
- n8n MCP工具专家 - 查找和配置节点
- n8n表达式语法 - 正确编写表达式
- n8n验证专家 - 验证和修复错误
- n8n节点配置 - 配置特定操作