How Branching works in n8n Workflows | Smart Automations with Multiple Paths

Learn How Branching works in n8n Workflows | Smart Automations with Multiple Paths in this comprehensive n8n tutorial. Step-by-step guide with video, code examples, and expert tips from the n8n Zero to Hero course.

Table of Contents

Overview

This lesson is part of the n8n AI Automation - Zero to Hero course, Section: 3. Deep Dive Concepts.

Watch the video above for the full tutorial, or read the written guide below.

What is the Switch node and how does it create multiple paths in an n8n workflow?

The Switch node routes each incoming item to a named output branch based on configurable matching rules, replacing a chain of stacked IF nodes with a single, readable configuration. While the IF node produces only two outputs, true or false, the Switch node supports four or more branches simultaneously. In this lesson it evaluates order_status and splits 100 orders into pending, processing, canceled, and refunded streams in one step.

How to build a multi-branch order-routing workflow in n8n

The Manual Trigger node starts the workflow for testing, with a Schedule Trigger recommended for daily production runs at a fixed time. A Google Sheets node follows, configured with the "Get Rows" operation pointing to the mock orders spreadsheet, which returns all 100 records as a list of JSON objects. Every record shares seven properties: row number, order ID, first name, last name, customer email, order status, and order date. In n8n, even a single returned record is wrapped in a list because every node expects a list of items as input.

The Switch node connects directly after Google Sheets. Each routing rule compares $json.order_status against a fixed string value: "pending", "processing", "canceled", or "refunded". Dragging the field from the item properties panel into the value slot auto-converts it from fixed text to expression mode, where anything inside double curly braces is evaluated as JavaScript. Each rule maps to a renamed output branch, such as "pending orders" or "processing orders". Renaming outputs is a best practice: without it, the canvas labels branches only as output 0, 1, 2, and 3, forcing you to reopen the Switch node to understand what each branch does. Two additional options improve reliability: "Fallback output" handles items that match no rule (left blank to silently drop unmatched statuses like "shipped" or "delivered"), and "Ignore case" prevents routing failures when source data uses inconsistent capitalization.

Each branch connects to a specific action node based on business need. The pending-orders branch connects to an Amazon SES node that sends an alert email to the customer service team, with the subject built dynamically using $json.order_id as an expression. The processing-orders branch connects to a Slack node that posts to a dedicated high-priority channel so the operations team can expedite shipping without waiting for email. The canceled and refunded branches both connect into the same Amazon SES node and the same Slack node, because both statuses require identical downstream actions: a finance-team email and a Slack notification to the canceled-and-refunded channel. n8n allows multiple upstream branches to feed a single downstream node, so no duplication is needed.

Key Takeaways

  • The Switch node replaces stacked IF nodes when three or more distinct conditions exist, producing one named output branch per rule from a single configuration panel.
  • Routing rules use $json.<property> expressions, auto-generated by dragging a field from the item panel, to evaluate any property of the current item against a fixed value.
  • Renaming each output branch directly inside the Switch node, for example "pending orders", prevents canvas confusion where unnamed branches default to "output 0", "output 1", etc.
  • The "Ignore case" option makes string comparisons case-insensitive, preventing routing failures when order status values are entered with inconsistent capitalization in the source sheet.
  • Multiple upstream branches can share a single downstream action node, so canceled orders and refunded orders can both trigger the same email node and Slack node without duplicating either.

Next Steps

Continue your n8n journey with the full n8n AI Automation - Zero to Hero course.

Frequently Asked Questions

The Switch node handles three or more distinct conditions in a single node, producing a named output branch for each rule. The IF node supports only two outputs, true and false, so routing four order statuses like pending, processing, canceled, and refunded would require stacking multiple IF nodes. The Switch node keeps the canvas readable and the routing logic centralized in one place.

The Switch node uses `$json.order_status` in expression mode to read the order status field from each incoming item. Dragging the property from the item properties panel into the value field automatically converts the input from fixed text to an expression editor. Anything inside double curly braces is interpreted as JavaScript, but no manual expression writing is required when you drag and drop the field.

Multiple upstream branches can connect into a single downstream node without any special configuration. In this lesson, both the canceled-orders branch and the refunded-orders branch connect to the same Amazon SES email node and the same Slack node. n8n processes the items from each incoming connection as separate runs on that shared node, executing it once per connected branch.

The Switch node's fallback output determines what happens to items that match none of the defined routing rules. In this lesson, orders with statuses like "shipped" or "delivered" match no rule and are silently dropped by leaving the fallback blank. Configure a fallback branch whenever unmatched items need logging, a separate notification, or any downstream handling instead of a silent discard.

Dheeraj Sharma

Dheeraj Sharma

AI Systems Builder
Creator of the n8n Zero to Hero course (42 lessons, 31+ hours). I help solopreneurs build AI systems that grow revenue without growing workload.

Get the n8n Mastery Bundle

All workflows, cheat sheets, and premium resources from the entire course in one package.

Get Premium Resources