For operations where failure is not acceptable (sending a customer notification, recording a payment, logging an audit event), the retry-with-fallback patter...
For operations where failure is not acceptable (sending a customer notification, recording a payment, logging an audit event), the retry-with-fallback pattern tries the primary service, and if it fails after retries, routes to a backup service. This is more robust than n8n's built-in retry-on-error, which retries the same service.
Real-world example: Your workflow sends transactional emails via SendGrid. If SendGrid is down, it falls back to Amazon SES.
Trigger
|
HTTP Request - SendGrid (primary)
On Error: Continue (using error output)
|
+-> Success branch: Continue workflow
|
+-> Error branch:
|
Code Node - Log Failure
|
HTTP Request - Amazon SES (fallback)
On Error: Continue
|
+-> Success: Continue workflow
|
+-> Error: Slack Alert (both providers down)
```text
```json title="HTTP Request: SendGrid (Primary)"
{
"method": "POST",
"url": "https://api.sendgrid.com/v3/mail/send",
"authentication": "genericCredentialType",
"sendBody": true,
"bodyContentType": "json",
"jsonBody": {
"personalizations": [
{
"to": [{ "email": "={{ $json.customer_email }}" }],
"subject": "Your order #{{ $json.order_id }} has shipped"
}
],
"from": { "email": "orders@example.com" },
"content": [
{
"type": "text/html",
"value": "={{ $json.email_body_html }}"
}
]
},
"options": {
"timeout": 10000,
"retry": {
"maxRetries": 2,
"waitBetweenRetries": 2000
}
}
}
```text
```javascript title="Code Node: Log Failure and Prepare Fallback"
const originalInput = $('Trigger').first().json;
const sendgridError = $input.first().json;
console.log(`SendGrid failed: ${JSON.stringify(sendgridError)}`);
// Prepare the same email data in SES format
return [{
json: {
Destination: {
ToAddresses: [originalInput.customer_email]
},
Message: {
Subject: {
Data: `Your order #${originalInput.order_id} has shipped`
},
Body: {
Html: {
Data: originalInput.email_body_html
}
}
},
Source: "orders@example.com",
// Pass through original data for downstream nodes
_original: originalInput
}
}];
```text
> **Tip: Error Output Configuration**
>
> To use the error branch, configure the node's settings: **On Error** -> **Continue Using Error Output**. This adds a second output connector (red) that receives items when the node fails, including the error details. The success output (green) receives items when the node succeeds.
This pattern ensures critical operations complete even during provider outages, with full visibility into which fallback path was used.
**Related:** [Use Path Parameters in Webhook URLs for Dynamic Routing](../webhook-mastery/01-use-path-parameters-in-webhook-urls-for-dynamic-routing.md) | [Use Edit Fields in "Map Each" Mode for Simple Renames](../data-transformation/01-use-edit-fields-in-map-each-mode-for-simple-renames.md)
I build production n8n and Cloudflare automation for teams — the same engineering behind HarperFlow. Fixed-price, escrow-protected, US-based.