Summary
Across multiple client portals and my own products like Fahm Al-Quran, roughly 80% of backend endpoints repeated the exact same pattern: verify the tenant and user, validate input, query MongoDB or PostgreSQL, call an external API or AI model, and trigger a cache refresh or email.
Building a single visual workflow engine in Go eliminated that boilerplate drift—but only after enforcing strict runtime invariants: radix-tree dispatch, forked contexts for parallel branches and loops, process-isolated JavaScript workers, and database-backed duplicate protection.
Why one compiled runtime beats scattered glue services
When every product spins up its own collection of Express routes, serverless functions, and cron scripts, operational overhead compounds fast. A rate-limit fix, an SSRF network guard, or an audit log format has to be updated in ten repositories.
In Yin Business, APIs and scheduled jobs are stored as versioned DAG graphs and executed by one Go runtime (bis-workflow-engine):
- Radix-tree dynamic routing: Every tenant's published HTTP triggers compile into an in-memory radix tree keyed by tenant, method, and path parameters. Route matching runs in microseconds with zero reflection overhead.
- Immutable published versions: Editing a workflow draft never touches production traffic. Publishing seals an immutable snapshot; rolling back a bad deployment is a single version-pin change.
- Pause and resume durability: Workflows that wait hours or days for a webhook callback or timer serialize their execution state and release the goroutine. A time-limited lease lets another worker instance recover the run safely if a node crashes.
- Built-in execution traces: Every step records its input, output, duration, and structured run logs in one place so debugging a production failure takes seconds rather than grepping across five services.
Radix dispatch & isolated branch execution
Go runtime- Radix gateway routerHTTP
- Tenant & HMAC guardAuth
- Sequential & parallel forkDAG
- Bounded step counterBudget
- Postgres / Mongo / R2Store
- Execution trace logAudit
Safety invariants
Invariant 01
Fork context on every parallel branch and loop iteration
Parallel branches and For-Each loops run on forked copies of the workflow context with a dedicated per-run step budget (100,000 steps max). Sibling branches can never mutate shared maps concurrently or corrupt each other's variables; outputs merge deterministically only after all branches finish.
Invariant 02
Isolate user JavaScript in separate worker processes
Custom code steps run inside hardened Goja sandboxes hosted in separate worker processes with OS-enforced memory caps and regex match timeouts. A runaway loop or memory spike kills only that worker slot rather than taking down the main Go engine. Throughput caps at ~500–800 code runs/sec per pool, which is a deliberate safety trade-off.
Invariant 03
Use the database—not Redis—for duplicate protection
Early load testing caught 13 to 39 duplicate executions whenever Redis restarted mid-burst, because idempotency claims lived in cache. Moving execution claims to MongoDB dropped double runs to zero at the cost of a small latency bump, while Redis fail-open logic ensures a cache outage degrades speed instead of blocking requests for 9 seconds.
Invariant 04
Strip credentials before errors reach logs or downstream steps
SQL, SMTP, and HTTP nodes enforce outbound network guards against private CIDRs and sanitize connection strings (including passwords containing special characters like @) before surfacing diagnostics to error-handling branches.
Continue reading
Have an architecture challenge to discuss?
Get in touch for staff-level architecture advisory or product collaboration.