Lesson 8 of 12 Phase 3 · Advanced Techniques

Logic, Routing & Branching

Real-world automation is never a straight line. This lesson teaches you to build workflows that make decisions: routing data down different paths, merging parallel branches, and processing items conditionally with IF nodes, Switch nodes, and Merge nodes.

🔀
IF Node
True/False routing
🔁
Switch Node
Multi-path routing
⬇️
Merge Node
Combine branches
🎯
Expressions
Dynamic conditions
Section 1

IF Node — True or False Branching

The IF node is the most fundamental decision-maker in N8N. It evaluates a condition and sends each item down either the true output or the false output. Think of it as a fork in the road for your data.

1
Add an IF Node
Click + from any node, search "IF". The node has two outputs: "true" (green dot) and "false" (red dot). Connect downstream nodes to each output separately — they run independently.
2
Configure the Condition
Click the IF node. Click "Add Condition". Choose the left operand (usually a field from your data like {{ $json.status }}), select an operator (equals, contains, greater than, etc.), then enter the right operand value to compare against.
3
Chain Multiple Conditions
Add multiple conditions and set the combiner to AND (all must be true) or OR (any must be true). Example: status equals "active" AND score is greater than 80.
Example: Route by order status
Condition: {{ $json.order_status }} equals "shipped"

True path  → Send "Your order is on its way!" email
False path → Send "Your order is still being processed." email
Section 2

Switch Node — Multi-Path Routing

When you have more than two possible routes, use the Switch node. It routes each item to one of up to 4+ output ports based on the value of a field, similar to a switch/case statement in programming.

💡
When to use Switch vs IF: IF is for binary decisions (true/false). Switch is for categorical decisions where a field can have several distinct values — like routing by country, category, priority level, or user tier.
1
Set the Switch Mode
The Switch node has two modes: Rules (compare a value against different criteria) or Expression (dynamically route based on a formula). Rules mode is easier for most cases.
2
Define Output Cases
Add one rule per output. Example: Output 1 if priority equals "high", Output 2 if priority equals "medium", Output 3 if priority equals "low". Enable "Fallback Output" to catch anything that doesn't match any rule.
Switch Node — Priority Routing
Field: {{ $json.priority }}

Output 0 → equals "critical"  → PagerDuty alert
Output 1 → equals "high"      → Slack message
Output 2 → equals "low"       → Spreadsheet log
Fallback  → (anything else)   → Email digest
Section 3

Merge Node — Combining Branches

After branching with IF or Switch, you often need to bring data back together — for example, to send a single final email regardless of which path was taken. The Merge node does exactly this.

Append Mode
Collects items from all connected inputs and passes them all through together. The total output is the sum of all input items.
🤝
Merge by Key
Joins two streams like a database JOIN. Matches items from Input 1 and Input 2 on a shared key field (like user_id) and combines their properties.
Wait Mode
Holds all items until ALL connected branches have completed, then releases. Use this for parallel processing that must complete before the next step.
⚠️
Common mistake: Connecting three nodes all into one downstream node does NOT automatically merge them. You must explicitly add a Merge node. Without it, N8N will run the downstream node once per upstream node independently, which is rarely what you want.

🧠 Logic & Routing Check

1. Your workflow receives orders and needs to route "premium" users to one path and everyone else to a different path. Which node should you use?
2. You split data with a Switch node into 3 paths, process each, and want to send ONE final summary email combining results from all 3 paths. What do you need?
3. What does the Fallback Output on the Switch node do?
Finished Lesson 8?

You can now build workflows that make smart decisions. Try building a branching workflow!