Architecture
How a Sendwend journey goes from TypeScript to a running instance, what lives in your repository, on the host and in your Postgres, and why the compiled workflow is data rather than code.
Sendwend splits a customer journey into three things that change at different speeds: the workflow you write, the engine that interprets it, and the platform that keeps it running for days or weeks. You write workflows as TypeScript. A compiler turns them into a versioned intermediate representation (IR), which is plain JSON. One generic runner, deployed once, reads that IR and executes every journey. This page explains how those pieces fit and why they are cut where they are.
From code to a running journey
- You write a contract (events and profile fields as Zod schemas), templates, workflows and segments, and register them in one
workflow.config.ts. - The compiler (
compileConfig) checks the whole project and produces aBundleIR: every workflow as a tree of nodes, each with a content hash. See Versioning. - Deploying writes the bundle's routing table to Postgres: which event or segment starts which workflow, under which re-entry policy.
- Your api reports what users do through
JourneyClient.ingest(). The host validates the batch against the contract, records the events, and starts an instance for each workflow whose trigger matches. - The runner loads the instance's IR by the hash it entered on and walks it node by node. Each message, action and wait is a durable step, so a crash or redeploy resumes where it stopped.
The three planes
The package itself is divided along the same line:
| Plane | What it is | Where it lives |
|---|---|---|
| Authoring | The DSL, compiled to IR by compileBundle | sendwend |
| Execution | The interpreter, over abstract ports | sendwend/engine |
| Adapter | Bindings, ingest, the runner for one host | sendwend/cloudflare, sendwend/aws, sendwend/node |
The interpreter never touches a database or the network. Everything it needs (reading a profile, sleeping, sending a message, emitting an event) arrives through the ports defined in sendwend/engine. That boundary is what makes a journey testable without deploying one, and what lets the same interpreter run on three different platforms.
Why the IR is data
The DSL looks like a chain of method calls, but none of it runs at send time. Chained calls and condition expressions build a serializable graph. Sub-flow callbacks run exactly once, while the workflow is being defined, and values that are only known at run time are always references (u.name, checkout.payload.value), never closures.
compiles to a tree of a message node, a delay node and a wait_until node, with u.name stored as a reference to resolve when the email is sent. Keeping the workflow as data has concrete consequences:
- One deployed runner executes every journey. A new workflow is a new bundle, not a new code path. On Cloudflare, one Worker serves all of them; on AWS, one Lambda function.
- A running journey can be pinned to a version. Each workflow's IR is stored under its content hash, and an instance keeps the hash it entered on, so it finishes the version it started however often you deploy. See Versioning.
- A deploy can be checked before it happens.
plan()diffs two bundles, and the in-flight check compares a new bundle against the IRs journeys are still running on. Neither has to execute anything. - It can be drawn. Sendwend Studio and the canvases on this site render the same IR the runner executes.
Branching stays declarative on purpose: there are no custom conditions. An action that needs to influence routing writes a property or emits an event, and the decision is an ordinary condition on that data, so the canvas can always explain why a user took a path.
What lives where
| Place | What it holds |
|---|---|
| Your repository | The contract, templates (React email components, push, Slack, Discord), workflows, segments, custom actions and workflow.config.ts. Everything is reviewed and versioned like the rest of your code. |
| The host | The compiled bundle and the code that serves it: the HTTP API (/ingest, /devices, /subscriptions, tracking routes), the runner, the senders. Secrets such as API_TOKEN and provider keys come from its environment, never from the config. |
| Your Postgres | Everything the engine remembers: profiles and events, the routing table, stored IRs, the entry ledger, message copies with opens and clicks, opt-outs, devices and segment membership. The tables live in one schema, workflow by default. |
The engine's tables are generated as a drizzle file (pnpm exec sendwend generate) or as plain DDL (renderPostgresDdl() from sendwend/store), and your migrations create them. Nothing creates or alters tables at runtime: a deploy checks the live schema first and refuses with every missing table or column. See Postgres.
The hosts
The same config runs on three hosts. They differ in what provides durability, not in what a journey does:
| Host | Import | What makes steps durable | Guide |
|---|---|---|---|
| Cloudflare Workers | sendwend/cloudflare | Cloudflare Workflows, with Postgres reached through Hyperdrive | Cloudflare |
| AWS Lambda | sendwend/aws | Lambda durable functions, behind a Function URL | AWS Lambda |
| Node (self-hosted) | sendwend/node | Postgres itself: instances are rows, taken a turn at a time | Self-hosting |
On every host, steps are at least once: a process that dies between a step's effect and its checkpoint leaves the step to run again. Messages are kept to at most once on top of that by a claim in Postgres; Delivery explains how.
The SDK holds the hosts to one behavior with a conformance suite: one config, deployed on Node, Cloudflare and AWS, driven through the HTTP API every host serves, with each held to the same observable results (the actions called, the copies handed to the sender, and the entry, instance, message, event and subscription tables). A scenario never names a host. A difference between hosts has to be recorded on the scenario as a known divergence rather than hidden, and a script a local harness cannot drive is skipped with the reason in its title. Today no scenario records a divergence; a few are skipped on AWS, whose local durable runner cannot hold an instance in the middle of a sleep.