keepcalculator

06 Numbers and Powers

N8n vs custom code: where to draw the line

Card No. 06·30202 · Updated · Standard formula, shown below

Choosing between n8n and custom code for engineering automation comes down to one rule: use n8n when the workflow is built from standard connectors and simple logic, and switch to custom code when you need complex branching, tight error handling, or performance guarantees. This article explains the practical boundary that prevents costly bugs, covering when each approach shines, where they fail, and how to make the call.

Background: what n8n actually is

n8n is a workflow automation platform that lets you connect APIs, databases, and services through a visual editor. You build workflows by dragging nodes—each node represents a step like fetching data, transforming it, or calling an external service. It runs self-hosted or in the cloud, and it supports custom JavaScript in function nodes for logic that the built-in nodes can’t express.

Custom code means writing the automation from scratch in a general-purpose language like Python, TypeScript, or Go, and deploying it as a service, a script, or a serverless function. You control everything: the HTTP calls, the retries, the logging, the data validation, and the deployment pipeline.

How n8n works under the hood

n8n executes a workflow as a directed graph. Each node receives data from the previous node, processes it, and passes the result along. The execution engine handles retries, error workflows, and parallel branches. You can add conditional logic with the IF node, merge data with the Merge node, and loop with the Loop node.

The key limitation is that n8n’s execution model is node-based, not code-based. Complex control flow—like dynamic retries with exponential backoff, or branching that depends on the content of an array of objects—requires either nested workflows or JavaScript in function nodes. Once you start writing significant JavaScript inside function nodes, you’re essentially debugging code through a visual interface, which is harder than debugging in a proper IDE.

When n8n is the right choice

n8n excels at workflows that are essentially data movement with light transformation. Common examples:

  • Syncing a CRM with a database nightly
  • Posting form submissions to a Slack channel and a spreadsheet
  • Fetching data from an API, filtering it, and sending a summary email
  • Orchestrating a simple approval chain with email notifications

In these cases, n8n gives you built-in retries, logging, and a UI that non-engineers can read. The cost of a mistake is low, and the workflow is easy to inspect.

When custom code is the right choice

Custom code becomes necessary when the automation’s correctness depends on precise control. Signs you’ve crossed the boundary:

  • You need to handle partial failures—e.g., process 10,000 records, but only retry the ones that failed, and log exactly why each failed
  • You need to guarantee exactly-once or at-least-once semantics, which n8n does not provide out of the box
  • You need to process data that doesn’t fit in memory, or you need to stream records
  • You need to implement a custom algorithm (e.g., a scheduling optimizer) that is more naturally expressed in code than in nodes
  • You need to test the logic with unit tests, property-based tests, or integration tests in a CI pipeline

A concrete example: an automation that ingests webhook events, deduplicates them, enriches them with a third-party API, and writes them to a database. In n8n, you’d build a chain of nodes, but deduplication requires a lookup that may race with concurrent executions. In custom code, you can use a database transaction with a unique constraint and handle the race condition explicitly.

How to choose: a practical decision framework

Use this checklist when deciding:

  1. List the workflow’s steps. If every step maps to an existing n8n node (HTTP Request, Database, Email, etc.), n8n is viable.
  2. Identify the error cases. If the workflow can fail in more than two distinct ways that require different recovery actions, custom code gives you clearer control.
  3. Estimate the data volume. n8n can handle moderate volumes, but if you’re processing millions of records, custom code with batch processing is safer.
  4. Consider the team. If the team is mostly engineers, custom code is maintainable. If the team includes non-engineers who need to edit workflows, n8n’s visual editor is a benefit.
  5. Think about testing. If the automation is critical (e.g., billing, data migration), you need automated tests. Custom code allows standard testing frameworks; n8n has testing options but they are less mature.

Common pitfalls and how to avoid them

One common misconception is that n8n is “no-code” and therefore requires no programming knowledge. In practice, you often need to write JavaScript in function nodes, and that code is harder to test and debug than code in a repository. Another pitfall is relying on n8n’s built-in retry mechanism for idempotent operations. If a workflow retries a non-idempotent API call, you can create duplicate records. Custom code lets you implement idempotency keys explicitly.

Another issue is error handling. In n8n, an error in a node stops the workflow unless you define an error workflow. That error workflow runs as a separate execution, and you can lose context about the exact input that caused the failure. In custom code, you can log the full payload and stack trace, and you can implement a dead-letter queue.

Finally, consider the cost of debugging in production. n8n’s execution logs show you the data at each node, which is excellent for simple workflows. But when you have complex transformations, the logs become huge, and you’ll wish you had a debugger with breakpoints.

Costs and maintenance

n8n has a free self-hosted community edition, but you pay for infrastructure and your own maintenance. The paid cloud version adds per-execution costs. Custom code costs are purely engineering time and infrastructure. The hidden cost of n8n is the learning curve for its execution model and the occasional need to work around its limitations. The hidden cost of custom code is the initial development time and the need to build your own retry, logging, and scheduling infrastructure.

Alternatives and hybrid approaches

You don’t have to choose one or the other. A common pattern is to use n8n for the orchestration and call a custom microservice for the heavy lifting. For example, n8n triggers on a webhook, then calls a Python service that does the complex processing, and n8n handles the notification steps. This gives you the visual overview and the code-level control where it matters.

Another alternative is to use a more code-oriented workflow engine like Temporal or Airflow, which give you durable execution and retries in code. These are more powerful than n8n but require more setup.

Frequently Asked Questions

Can n8n handle large data volumes?

n8n can process thousands of records per execution, but it loads data into memory. For millions of records, you’ll hit memory limits and slow execution. Custom code with streaming or batch processing is more reliable for large volumes.

Is n8n considered low-code or no-code?

n8n is low-code. While you can build simple workflows without writing code, most real-world workflows require JavaScript in function nodes for transformations or logic. Treat it as a tool that reduces boilerplate, not as a way to avoid programming.

How do I test n8n workflows?

n8n has a built-in execution tester that lets you run a workflow with sample data and inspect the output at each node. For automated testing, you can export workflows as JSON and use n8n’s CLI to run them in a CI pipeline, but it’s less straightforward than unit testing custom code.

What are the security implications of self-hosting n8n?

Self-hosting n8n means you’re responsible for securing the server, the database, and the credentials stored in the workflow. n8n encrypts credentials at rest, but you must manage the encryption key. Custom code gives you the same responsibility, but you have full control over the security architecture.

Can I mix n8n and custom code in the same automation?

Yes. A common pattern is to use n8n for the workflow orchestration and call a custom API for complex processing. n8n has an HTTP Request node that can call your microservice, and you can pass data back and forth.

What is the learning curve for n8n compared to custom code?

For simple workflows, n8n is faster to learn because you don’t need to set up a project, handle HTTP, or write boilerplate. For complex workflows, the learning curve shifts to understanding n8n’s execution model and debugging through the UI, which can be more frustrating than writing code in a familiar language.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →