Phase 2: n8n for AI Automation · 50 min · n8n · Docker · Langfuse
Error Handling and Production Patterns
A demo works when everything goes right. Production works when things go wrong.
Hiring signal: Error handling is what separates demos from production systems. In automation interviews, the question 'what happens when the AI API times out at 3am?' filters out candidates who've only built prototypes. Being able to describe error triggers, retry logic, and execution logging demonstrates production ownership.
What you will learn
- Configure n8n Error Trigger nodes to catch failures and route to error handling workflows
- Set up retry logic with exponential backoff on individual nodes
- Manage credentials securely: storing, rotating API keys and OAuth tokens
- Use execution logging for debugging and monitoring production workflows
The Problem
An n8n workflow processes 500 customer emails per day: classify with AI → extract data → update CRM → send response. It works perfectly for two weeks. Then at 3 AM on a Saturday, the OpenAI API returns a 429 (rate limit) on one email. The workflow fails. The email is lost — not processed, not retried, not flagged. The customer never gets a response. On Monday, the team discovers 12 emails from the weekend that were silently dropped.
This is the production gap. Demos assume everything succeeds. Production assumes everything fails eventually. The question isn't "will things go wrong?" — it's "what happens when they do?"
Production readiness is about failure modes, not features
Your workflow doesn't need more nodes. It needs error triggers, retry logic, dead-letter queues, credential rotation, and execution logging. These aren't nice-to-haves — they're the difference between a workflow that runs for two weeks and one that runs for two years.
The Concept
The Error Handling Stack
┌─────────────────────────────────────────────────────────────┐
│ Layer 4: Alerting │
│ Slack/email notification when errors exceed threshold │
├─────────────────────────────────────────────────────────────┤
│ Layer 3: Dead Letter Queue │
│ Failed items stored for manual review and reprocessing │
├─────────────────────────────────────────────────────────────┤
│ Layer 2: Error Trigger Workflow │
│ Catches failures, logs them, routes to recovery │
├─────────────────────────────────────────────────────────────┤
│ Layer 1: Node-Level Retry │
│ Automatic retry with exponential backoff on each node │
├─────────────────────────────────────────────────────────────┤
│ Layer 0: Input Validation │
│ Validate data before processing — fail fast on bad input │
└─────────────────────────────────────────────────────────────┘
Node-Level Retry Settings
Every node in n8n has retry settings under Settings → Retry on Fail:
| Setting | What It Does | Recommended Value |
|---|
| Retry on Fail | Automatically retry the node if it errors | Enable for external calls |
| Max Tries | Number of retry attempts | 3–5 |
| Wait Between Tries | Delay between retries | Exponential: 1s, 2s, 4s |
Your AI classification node fails intermittently due to API rate limits. What's the best retry strategy?
Exponential backoff gives the API time to recover between retries. 1s → 2s → 4s → 8s means the total wait is 15 seconds across 4 tries. Immediate retries hammer a rate-limited API and make it worse. Fixed 60s delays are too conservative for transient errors. No retry means every transient failure goes to the error trigger unnecessarily.
Error Trigger Node
The Error Trigger is a special trigger that fires when any workflow in your n8n instance fails:
Credential Management
| Practice | What It Means | Why It Matters |
|---|
| Store in n8n credentials | API keys in n8n's encrypted credential store | Never hardcode secrets in Code nodes |
| Use environment variables | process.env.OPENAI_API_KEY in Code nodes | Keeps secrets out of workflow JSON |
| Rotate keys regularly | Replace API keys every 90 days | Limits damage from leaked keys |
| Scoped credentials | Use least-privilege API keys | A webhook-only key can't delete data |
| Separate prod vs dev | Different keys for dev and production | Dev testing can't affect prod data |
Execution Logging
n8n stores execution history with full input/output data for each node:
| Log Level | What's Captured | Retention |
|---|
| Full | All node inputs/outputs | 7 days (configurable) |
| Metadata only | Execution status, duration, error | 30 days |
| None | Not recommended for production | — |
Execution logs contain your data
If your workflow processes PII or sensitive data, execution logs may store it. Configure data retention policies and consider using the "Don't save execution data" option for sensitive workflows, logging only to external systems with proper access controls.
Unlock the full lesson
You've read the first 2 sections. The rest of this lesson covers Build It, Use It, Ship It, Exercises, Key Terms, Common Pitfalls — plus a hands-on lab, quiz, and project artifact.
Create a free account to unlock Phase 0 and Phase 1 of every course — no credit card.
Browse all courses · View pricing · DeVenture Academy