Lucas Santos
All articles

n8n or custom code: which fits your automation?

n8n or custom code for business automation: when the visual tool is enough and when code costs less to maintain, with real cases.

Published on 4 min read

  • n8n
  • automation
  • AI agents
  • custom code

For n8n or custom code, the rule is simple: use n8n when the process is a clear sequence of steps between tools that already have ready integrations. Move to code when the agent needs its own rules, tests, high volume or deep access to your system. Both work, and I have used both in production. The right question is not which is better, but which costs less to maintain a year from now.

Where n8n and code fit

What is n8n and what is it for in a business?

n8n is a visual automation platform: you drag blocks (called nodes) and connect them. One node receives a trigger, such as a new spreadsheet row, the next queries an API, and the last sends the result by email or WhatsApp. It also has AI nodes for calling language models.

It works well for connecting systems that already have ready connectors, for validating an idea in a few days, and for letting an internal team see the flow on screen. I used it in projects such as Edu ai, which generates study plans with AI, and in parts of the Gac Academy course platform.

When is n8n the best choice?

n8n is the best choice when the flow is linear, the volume is moderate and the business rule fits in a few blocks. In those cases you ship in days, and people who do not code can adjust it.

Signs that n8n is enough:

  • The process reads "when X happens, do Y and Z", with few exceptions.
  • The tools involved (spreadsheet, CRM, email, WhatsApp) already have a node.
  • You need to validate the idea before investing in software.
  • The team wants to see and edit the flow without opening a repository.

n8n or custom code: when should you move to code?

Move to code when the AI agent must choose between many paths, use your own system's tools and be tested like software. Visual flows get hard to read as they grow, and testing a 60-node automation is harder than testing functions.

That was the case for the sales agent I built for a Brazilian pharmacy chain and for Finan, a personal finance agent. In both I used TypeScript with the Mastra agent framework, because the agent has to query a catalog, record a transaction, interpret audio and images, and follow rules that change. In code, each rule becomes a function with a test, and the agent is versioned like the rest of the system.

Signs it is time for code:

  • The agent needs memory, a knowledge-base search (RAG) or many tools.
  • Business rules change and need automated tests.
  • Volume is high and you need to control queues, retries and cost.
  • The flow grew so large that nobody understands it at a glance.

How do the two compare?

Criterionn8nCode
Time to first versionDaysWeeks
Who adjusts it laterNon-programmers, carefullyProgrammers
Automated testsLimitedComplete
Volume and queue controlBasicFull
Agent with memory and RAGPossible but limitedNatural
Cost of maintaining large flowsGrows fastGrows slowly
Risk of tool lock-inHigherLower

The timings in the table are orders of magnitude from small projects I have seen, not promises. Every case changes with complexity.

What mistakes should you avoid in an n8n automation?

The problems I see most do not come from the tool but from how the flow is built:

  • A flow with no owner. When nobody knows who changed it last, a small edit breaks the process. Name one person responsible and keep an exported copy of the flow.
  • No error handling. If an API goes down and the flow just stops, nobody notices. Set up an alert for the team when a run fails.
  • Keys and passwords inside the flow. Use n8n's own credentials, never loose text in a node.
  • Business rules hidden in blocks. Write down in a document what each flow decides. That is what makes migrating or auditing possible later.
  • AI with no limits. A node that calls a language model without cost and input-size control can surprise you on the invoice.

These cares apply to n8n and to code alike. The difference is that in code the repository and the tests already cover part of them.

Can you use both together?

Yes, and it is often the best design. Leave n8n with the simple integrations (alerting the team, updating a spreadsheet, sending an email) and code with the agent's brain, called through a webhook. The part that changes every week stays in the team's hands and the critical part stays tested.

On Gac Academy, for example, the AI tutor answers from the course content, and n8n handles the surrounding automations. Each piece sits where it makes the most sense.

Frequently asked questions

Is n8n free?

There is a version you install on your own server and a paid cloud version. License terms and plans change, so read the official page before deciding on cost.

Can I start on n8n and migrate later?

Yes, and it is a good way to validate. Document the business rules while you build, because migrating is easier when the logic is written down and not only drawn in blocks.

Is code always more expensive?

It is more expensive for the first version. It can be cheaper over a year if the flow grows, changes often or needs reliability. Do the math on the cost of maintaining it, not only of building it.

Next step

Sketch the process on paper, with the steps and the exceptions. If it fits on one page with few exceptions, start with n8n. If the exceptions take more room than the main flow, think about code from the start. For an example of an agent that needed code, read AI agent vs chatbot on WhatsApp.

Want to apply this in your business?

Tell me about your operation and I'll reply with next steps. No strings attached.

Message me on WhatsApp

Or leave your details and I'll get back to you