A Restate-native AI pipeline platform.
- Restate is the durable runtime and the run store.
- Kafka and REST start workflows.
- A Postgres catalogue, fed by each unit's
metadata.json, is the control plane. - Each workflow or service is an independently deployable container.
- LLM calls go through LiteLLM, which routes to host Ollama.
One example ships with it:
transcriptgenerates a source-language transcript for a video/audio Content's artifact via the privatewhisperservice, then translates it into each configured target language, each as its ownTranscriptenrichment object. Triggered by REST or by the generic Kafkacontent.publishedevent. Read workflows/transcript/EXPLAINED.md before writing a workflow: it walks through every decision the handler makes and why.
REST ──► core-api ──(restate-sdk-clients)──┐
▼
Kafka ──► TranscriptTrigger ──────────► Transcript (workflow) ──► WhisperService
content.published │ └ ctx.run → faster-whisper
└─► LiteLLM → per-language translation
core-api (control plane) ──► Restate admin: deployments · subscriptions · SQL introspection
──► Postgres catalogue: definitions · deployments · dependencies · triggers
The design is in docs/plan.md. Settled decisions and lessons learned are in docs/decisions.md. The annotated example is in workflows/transcript/EXPLAINED.md.
| Path | What it holds |
|---|---|
packages/contracts |
zod schemas (./<unit>) and restate.iface bindings (./<unit>/api), per unit |
packages/api-contract |
the HTTP surface: request/response schemas, the error envelope and its code union |
packages/metadata |
the metadata.json schema (./metadata), Restate naming (./naming), ./run-ids |
packages/runtime |
small helpers: ./retry, ./options, ./kafka-trigger, ./config, ./serve |
packages/ai |
Generate over LiteLLM (AI SDK); providers stay behind it |
packages/observability |
pino logger and optional OTel SDK |
packages/typescript-config |
the shared tsc presets every package extends |
packages/eslint-config |
the shared lint rules, including the handler determinism checks |
packages/contract-<name> |
a contract a second unit needs, e.g. contract-whisper |
services/whisper |
WhisperService, private; streaming download + VAD-chunked transcription |
workflows/transcript |
the reference workflow (walkthrough); REST + Kafka triggers |
apps/core-api |
Fastify: HTTP (routes/, plugins/) over rules (domain/) over stores (store/) |
apps/cli |
pnpm pipeline …: commands/ over a typed API client and a Docker port |
tests/fixtures/versioned-sleeper |
test-only workflow used for the versioning e2e |
tests/e2e |
end-to-end suites against the compose stack |
Packages export one entry point per purpose rather than a barrel index.ts, so a consumer pulls in
what it uses and no more — core-api reads catalogue schemas without loading the Restate SDK, and a
service that has no Kafka trigger never loads kafkaTrigger(). turbo boundaries enforces the
direction of the graph: contracts depend on nothing above them, and nothing depends on an app.
You need Docker, Node 22.13 or newer, pnpm 11 (corepack enable), and a host Ollama serving qwen3.5:4b (ollama pull qwen3.5:4b).
cp .env.example .env
pnpm install && pnpm build
docker compose up -d --build # postgres, kafka, restate, litellm, otel, core-api
pnpm pipeline deploy transcriptwhisper is a Python service; the CLI's unit discovery only covers the TS workspace, so it is
built and run separately from its own Dockerfile — not yet wired into pnpm pipeline deploy.
All ports bind to 127.0.0.1 only:
| Service | Address |
|---|---|
| core-api | :3000 |
| Restate admin API and UI | :9070 |
| LiteLLM | :4000 |
| Kafka (host listener) | :29092 |
| Postgres | :5432 |
| OTLP | :4318 |
The Restate ingress (8080) stays internal; REST requests go through core-api.
# REST: start a run (Idempotency-Key makes it idempotent), then read it
curl -s localhost:3000/v1/workflows/transcript/runs -H 'content-type: application/json' \
-H 'idempotency-key: demo-1' \
-d '{"input":{"identifier":"do_1","objectType":"Content","mimeType":"video/mp4"}}'
pnpm pipeline run transcript <runId>
# Kafka: publish a content-published event (the adapter maps it to the workflow input)
echo '{"eid":"BE_JOB_REQUEST","edata":{"action":"content-published","identifier":"do_2","objectType":"Content","mimeType":"video/mp4","enrichmentTypes":["Transcript"]}}' | \
docker compose exec -T kafka /opt/kafka/bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic dev.content.published
pnpm pipeline runs transcriptworkflows/transcript/EXPLAINED.md explains what it returns and why it is built the way it is.
| Area | Route |
|---|---|
| Workflows | POST /v1/workflows/:name/runs { input } with optional Idempotency-Key → 202 { runId, invocationId, status } |
| Runs | GET /v1/runs?workflow=&status=&limit=&cursor= |
| Runs | GET /v1/runs/:workflow/:runId (returns output once completed) |
| Runs | POST /v1/runs/:workflow/:runId/cancel (graceful — the handler unwinds) |
| Runs | POST /v1/runs/:workflow/:runId/kill (immediate — no unwinding, children abandoned) |
| Runs | POST /v1/runs/:workflow/:runId/resume (a paused run; see the retry policy below) |
| Catalogue | GET /v1/workflows?kind= |
| Catalogue | GET /v1/workflows/:name (schemas, config, triggers with desired and observed state, dependencies, versions, deployments) |
| Catalogue | PATCH /v1/workflows/:name/triggers/:id { enabled } |
| Control plane | POST /v1/deployments (posted by each unit on boot; 200 alreadyRegistered when the same build is live) |
| Control plane | GET /v1/deployments?name= (includes in-flight counts) |
| Control plane | DELETE /v1/deployments/:id (retire; refused until drained) |
| Health | GET /health/live, GET /health/ready |
- Run statuses are
running,completed,failed,cancelledandpaused. pausedis reachable by design. The LLM retry profile is uncapped and pauses an invocation when its retries are exhausted rather than failing it, so a gateway outage does not destroy a run's journal.GET /v1/runs?status=pausedfinds them andPOST …/resumerevives them once the cause is fixed. A pipeline that can pause but not resume would need the Restate CLI to recover.- A
RunViewcarriesrunId,invocationId,workflowVersion,deploymentId,triggerandtraceId. - Errors come back as
{ "error": { "code", "message" } }. - Run history is Restate's retention: 7 days for workflows and journals. It is operational history, not an audit log.
pnpm pipeline new <workflow|service> <name> [--kafka <topic>] scaffold a deployable unit
pnpm pipeline deploy <name...> [--dev] build (skipped when unchanged), start, await self-registration
pnpm pipeline deployments [name] deployments with in-flight counts
pnpm pipeline retire <deploymentId> retire a drained deployment and stop its container
pnpm pipeline workflows | start <wf> --input '{…}' [--key k] | runs [wf] | run <wf> <id> | cancel <wf> <id>
Start from workflows/transcript/EXPLAINED.md. It walks
through transcript — the reference workflow — decision by decision: the two triggers, the
adapter's skip-versus-fail rule, when to call a service and where ctx.run belongs, which
contracts move into a package, and what each level of test proves. Its last section is the
checklist below in long form.
pnpm pipeline new workflow order-fulfilment --kafka orders.placed # or: new service embedding
pnpm install
pnpm pipeline deploy order-fulfilmentThat generates a unit that builds, lints, typechecks and deploys as it stands — the handler body is
the only thing left to write. It writes metadata.json, the contract, the zod schemas, the
restate.iface binding, the handler, main.ts, both tsconfigs, the lint config and the boundaries
tag, all agreeing with each other.
What it generates, and why:
| File | Holds |
|---|---|
metadata.json |
kind, name, restateName, version, config, triggers, dependencies |
src/schemas.ts |
the zod input, output and config — no Restate SDK, so the catalogue side stays light |
src/api.ts |
the restate.iface binding. A workflow's entry handler must be run |
src/contract.ts |
the ContractEntry the unit registers itself with on boot |
src/unit.ts |
metadata and the config, validated against the contract at import |
src/workflow.ts |
the handler |
src/trigger.ts, src/adapters.ts |
with --kafka: the trigger service and the record adapter |
Triggers are declared in metadata.json and reconciled by the control plane:
- REST is
{ "id": "api", "type": "rest" }. - Kafka is
{ "id", "type": "kafka", "cluster", "topic", "adapter"? }, paired withkafkaTrigger({ metadata, input, adapters }). An adapter is a pure(event) => input | null, wherenulldrops the record without starting a run and throwing fails it terminally. - A Kafka trigger also needs its topic to exist — add it to
kafka-initincompose.yaml.
Each unit is independently deployable, and adding one does not disturb the others. A unit owns
its own contract; there is no shared registry to edit. packages/contract-* exists only for a
contract that a second unit needs — contract-whisper moved into its own package the moment a
second workflow was expected to call WhisperService. This is not just tidiness: the artifact
digest covers a unit's workspace dependencies,
so a shared registry would mean adding one workflow changed every other unit's artifact and forced a
round of version bumps. apps/cli/src/artifact.test.ts pins the property.
Each later change to a unit is a new artifact: bump version, or iterate with --dev.
The handler rules (all I/O in ctx.run, deterministic code, RestatePromise combinators) are in
CLAUDE.md, and enforced by lint.
The four catalogue tables are created when Postgres is provisioned, not by the API:
infra/postgres/init/ is mounted into /docker-entrypoint-initdb.d, which the official image runs
once against an empty data directory. In a real environment the same SQL is applied by whatever
provisions the database.
The API assumes the tables are already there. It never issues DDL, so it needs no such privileges,
and apps/core-api/src/store/schema.test.ts fails the build if a repository queries a table the
provisioning SQL does not create.
The files are re-runnable (IF NOT EXISTS throughout), but docker-entrypoint-initdb.d runs only on
first initialisation — after a docker compose down without -v, an existing volume is not
re-provisioned. To apply a change to a volume that already exists:
docker compose exec -T postgres psql -U pipeline -d pipeline < infra/postgres/init/20-catalogue.sql- Deployments are immutable. Every artifact gets its own container and endpoint (
<name>-<digest12>:9080) and its own Restate deployment. - New runs go to the newest deployment, and in-flight runs finish on the deployment they started on. The older deployment shows as
draining. pnpm pipeline retire <id>is refused (DEPLOYMENT_NOT_DRAINED) while runs are still pinned to it.- The same
versionfrom a different artifact or contract is refused (VERSION_ARTIFACT_CONFLICT/VERSION_CONTRACT_CONFLICT). --devoverwrites a single<name>-devendpoint in place. It is for local iteration only.
Tracing is collected in two ways:
- Always on: Restate server spans, SDK spans (per attempt and per
ctx.run) and service spans go to the OTel collector. The base collector config only logs them — nothing is stored until the overlay adds an exporter. - With the Langfuse overlay: the same spans plus the LiteLLM generation, in one trace per run,
which is the property that makes a run debuggable end to end.
- Verified: a run's Restate spans and its LLM generation share one
traceId, andRunView.traceIdleads to it. - Known gap: the generation carries its latency but not token usage or cost — LiteLLM's
langfuse_otelcallback does not emit thegen_ai.usage.*attributes Langfuse maps those from. LiteLLM's nativelangfusecallback does report usage, but creates its own trace, which would break the single-trace property. Not worth that trade for a local overlay; if cost tracking matters, read it from LiteLLM's own spend logs instead.
- Verified: a run's Restate spans and its LLM generation share one
To start the overlay:
docker compose -f compose.yaml -f compose.observability.yaml up -d # Langfuse UI: http://127.0.0.1:3001The overlay needs about 4 GB of extra memory. The traceId in a RunView is the Langfuse trace ID. The Restate UI at :9070 shows each invocation's journal.
| Command | What it runs |
|---|---|
pnpm check |
one turbo run: build, typecheck (tests included), lint, unit tests, formatting — then turbo boundaries |
pnpm test |
unit tests only |
pnpm test:replay |
always-replay Restate tests (Testcontainers; needs Docker) |
pnpm test:e2e |
against the running stack: catalogue, REST, Kafka, immutable versioning |
pnpm check is the gate. It fails on a formatting drift as readily as on a type error, because a
reformat changes a unit's artifact digest and therefore needs a version bump — so drift is a
deployment problem here, not a cosmetic one.
pnpm verify runs all three in order, which check alone does not — the replay and e2e suites are
the ones that catch durability and stack problems, and nothing else runs them.
The findings from testing the pipeline end to end, and what was done about each, are in
docs/qa-report.md. One is worth knowing while operating it: a trigger's
observedStatus: active means Restate holds a subscription, not that records are being consumed.
If ingestion ever stops, toggle the trigger off and on — the subscription is recreated and the
backlog drains from the committed offsets.
manifests/ holds a collection covering every route, with assertions, and a local environment:
npx newman run manifests/ai-pipeline.postman_collection.json -e manifests/local.postman_environment.jsonIt doubles as the API reference — every request is documented, including the refusals. A test
(apps/core-api/src/routes/collection.test.ts) fails the build if a route is added without a request,
or a request outlives its route, so it cannot quietly go stale.
.claude/settings.jsonenables Restate's official plugin (thebuilding-restate-servicesskill plus therestate-docsMCP server) andtypescript-lsp.- Trust the project and restart the session to activate them.
typescript-lspneedsnpm i -g typescript-language-server typescript.
.mcp.jsonadds these MCP servers: the Mastra docs server,langfuse-docs, andkafka(Confluent's MCP server pointed atlocalhost:29092).- Project skills (
skills-lock.json): turborepo, fastify-best-practices, pnpm, vitest, docker-compose-patterns, langfuse, mastra.
- Always pass
-f compose.yaml -f compose.observability.yamltogether while the overlay is running. docker compose down -vwipes both Postgres (the catalogue) and Restate (runs, deployments, subscriptions). Remove the runtime containers too:docker ps -aq --filter label=ai-pipeline.name | xargs docker rm -f.- Kafka topics are created by the
kafka-initjob; auto-creation is off. Add new topics there. - If a subscribed topic disappears (e.g. Kafka recreated without its volume), Restate's consumer stops. Toggle the trigger to recreate the subscription (
PATCH /v1/workflows/<wf>/triggers/<id>with{"enabled":false}then{"enabled":true}). It resumes from its committed offsets.