DEV Community

Rogerio Maciel
Rogerio Maciel

Posted on

Compiling n8n Workflow JSONs into Standalone Fastify/TypeScript Microservices (Open-Source + Client-Side Playground)

n8n is fantastic for prototyping and visual orchestration. You can wire up webhooks, databases, and LLM calls in minutes.

The pain starts when a workflow grows into critical production infrastructure:

  • High-concurrency webhooks hit runtime overhead and container memory limits (~250MB+ per worker).
  • Subworkflows pay HTTP/DB round-trip overhead instead of running in-process.
  • Engineering workflows struggle with diffing 2,000-line JSON exports in Git, running unit tests, and enforcing strict TypeScript contracts.

To solve this without rewriting everything by hand, I built n8n-to-fastify β€” an Ahead-of-Time (AOT) compiler that converts exported n8n workflow JSONs into standalone Fastify + TypeScript microservices.


How it works

Instead of interpreting JSON nodes dynamically at runtime, n8n-to-fastify parses the workflow DAG, resolves node dependencies and n8n expressions, and emits clean, idiomatic TypeScript modules (workflow.ts + routes/index.ts).

Currently supported nodes

  • Triggers & Responses: Webhook, Respond to Webhook
  • Flow & Logic: IF / Filter, Switch, Merge, Split Out, Aggregate, Wait
  • Data & Code: Set / Edit Fields, Code / Function
  • Integrations: HTTP Request, PostgreSQL, OpenAI / Gemini
  • Subworkflows: Execute Workflow compiled to an in-memory WorkflowRegistry (zero network round-trip between subworkflows)

Benchmark (Bun + Fastify)

On a compiled Lead Intake + Subworkflow validation pipeline (bun run benchmark):

  • Compilation time: 2.77 ms
  • Throughput: 1,885 req/s
  • Average latency: 0.530 ms
  • p95 latency: 0.742 ms

Honest Limitations

It does not cover all 400+ n8n community nodes yet. When the compiler encounters an unsupported node, it generates a typed TODO stub in the output TypeScript so you can drop in your own SDK or handler cleanly. Credentials are mapped to environment variables (process.env).


Try it & Break it

Paste any exported n8n workflow JSON into the in-browser playground or clone the CLI:

git clone https://github.com/rogeriomaciel/n8n-to-fastify
cd n8n-to-fastify
bun install
bun test
Enter fullscreen mode Exit fullscreen mode

If a real-world workflow from your stack breaks on a specific node or expression ($json, $('Node'), etc.), open an issue on GitHub β€” and if you find the approach useful, a Star helps a lot!

Top comments (0)