Skip to content

Safe streaming pipelines from typed Wasm components.

Torvyn is an ownership-aware reactive runtime built in Rust on the WebAssembly Component Model. Define contracts in WIT, implement in any language, compose pipelines with built-in backpressure and tracing.

Get Started → GitHub
$ cargo install torvyn
crates.io ↗

Overview

Define typed contracts, compile components to Wasm, and let the host runtime handle scheduling, ownership, and observability.

graph LR W["Define WIT Contract"] --> C["Compile to Wasm"] C --> L["torvyn link"] L --> HOST subgraph HOST ["Host Runtime"] direction TB R["Reactor"] RM["Resource Manager"] O["Observability"] end HOST --> SRC["Source"] SRC --> PROC["Processor"] PROC --> SNK["Sink"] RM -.- SRC RM -.- PROC RM -.- SNK classDef dev fill:#1E5EF0,stroke:#1a4fd0,color:#fff classDef host fill:#0EA5A0,stroke:#0c918d,color:#fff classDef comp fill:#242938,stroke:#3D4458,color:#E5E7EB class W,C,L dev class R,RM,O host class SRC,PROC,SNK comp

Why Torvyn

Six engineering properties designed to work together, not bolted on after the fact.

Contract-First Composition

Typed WIT contracts govern every interaction. torvyn link validates compatibility before runtime.

Ownership-Aware Resources

Host-managed buffers with borrow, transfer, and copy semantics. Every byte tracked and accounted for.

Reactive Backpressure

Credit-based demand propagation. No unbounded queues. Block, drop, or rate-limit per stream.

Capability-Based Sandboxing

Deny-all by default. Each Wasm component receives only explicitly granted permissions.

Production Observability

Native OpenTelemetry. Per-flow traces, metrics, copy accounting, and backpressure diagnostics.

Portable Packaging

OCI-compatible artifacts. Same binary runs on cloud, edge, dev, and on-prem environments.

Under the Hood

Two mechanisms that make Torvyn different: explicit buffer ownership tracking and credit-based backpressure propagation.

Buffer Ownership Lifecycle
stateDiagram-v2 [*] --> Pooled Pooled --> Owned : allocate Owned --> Frozen : freeze after write Frozen --> Borrowed : lend to component Borrowed --> Frozen : component returns Frozen --> Pooled : release Owned --> Pooled : release
Credit-Based Backpressure
sequenceDiagram participant Sink participant Processor participant Source Sink->>Processor: grant 10 credits Processor->>Source: grant 10 credits Source->>Processor: emit element (9 left) Processor->>Sink: emit element (9 left) Note over Sink: slow consumer Note over Processor: 0 credits, paused Note over Source: 0 credits, paused Sink->>Processor: grant 5 credits Processor->>Source: grant 5 credits Source->>Processor: resume

Define. Implement. Compose. Trace.

A WIT contract specifies the interface. A component implements it. A config wires stages together. The runtime handles everything else.

streaming.wit WIT
package torvyn:streaming@0.1.0;

interface types {
    resource buffer;
    record packet-meta {
        trace-id: string,
        content-type: string,
        timestamp-ns: u64,
    }
    record stream-element {
        meta: packet-meta,
        payload: borrow<buffer>,
    }
    variant process-error {
        invalid-input(string),
        unavailable(string),
        internal(string),
    }
}

interface processor {
    use types.{stream-element, process-error};
    process: func(input: stream-element)
        -> result<stream-element, process-error>;
}
  1. 1

    Define contracts

    Write a WIT interface specifying inputs, outputs, and error types. This is the source of truth for every component boundary.

  2. 2

    Implement components

    Write your domain logic in Rust, C, Go, or any language that compiles to WebAssembly. No runtime boilerplate.

  3. 3

    Compose a pipeline

    Wire stages together in TOML. The linker validates all contracts before a single byte flows through the system.

  4. 4

    Run with full observability

    Launch with per-stage latency, copy accounting, backpressure metrics, and OpenTelemetry traces — out of the box.

Developer Toolchain

Every stage validates correctness. Contract mismatches, missing capabilities, and cyclic dependencies are caught before runtime — not in production.

Define
Write .wit contracts specifying typed interfaces, data types, and error variants.
*.wit
Check
Validate WIT syntax, semantic correctness, and type consistency.
torvyn check
Build
Compile components to Wasm from Rust, C, Go, or any supported language.
torvyn build
Link
Verify contract compatibility across all components. Detect cycles and missing capabilities.
torvyn link
Run
Launch the pipeline with OpenTelemetry tracing, backpressure, and per-flow diagnostics.
torvyn run

How Torvyn Compares

Wasm-level isolation without network overhead. Typed contracts at every boundary. Built-in observability.

Microservices Containers In-Process Torvyn
IsolationProcessOSNoneWasm sandbox
ContractsSchema (lax)NoneNoneWIT (strict)
Boundary cost~ms (network)~100 µs~0< 5 µs
PolyglotYesYesNoYes (Wasm)
ObservabilityPer-serviceExternalManualBuilt-in OTel
BackpressureQueue overflowExternalManualCredit-based

See detailed comparisons →

Get Up and Running

Three commands to a traced, backpressure-aware pipeline.

1. Install

Install the CLI from crates.io.

$ cargo install torvyn

2. Create a project

Scaffold contracts and config.

$ torvyn init my-pipeline

3. Run

Validate, link, and launch.

$ torvyn run --trace

Architecture

13 crates in six build tiers. Strictly acyclic dependency graph enabling maximum parallel compilation.

Crate Dependency Graph
graph TB subgraph T6 ["Tier 6 · Entry Points"] CLI["torvyn-cli"] HOST["torvyn-host"] end subgraph T5 ["Tier 5 · Topology"] PIPELINE["torvyn-pipeline"] PACKAGING["torvyn-packaging"] end subgraph T4 ["Tier 4 · Composition"] LINKER["torvyn-linker"] REACTOR["torvyn-reactor"] end subgraph T3 ["Tier 3 · Resources"] RESOURCES["torvyn-resources"] SECURITY["torvyn-security"] end subgraph T2 ["Tier 2 · Core Services"] CONFIG["torvyn-config"] CONTRACTS["torvyn-contracts"] ENGINE["torvyn-engine"] OBS["torvyn-observability"] end subgraph T1 ["Tier 1 · Foundation"] TYPES["torvyn-types"] end CLI --> HOST HOST --> PIPELINE HOST --> PACKAGING HOST --> REACTOR PIPELINE --> LINKER PIPELINE --> REACTOR PACKAGING --> LINKER LINKER --> CONTRACTS LINKER --> ENGINE LINKER --> RESOURCES LINKER --> SECURITY REACTOR --> ENGINE REACTOR --> OBS REACTOR --> RESOURCES RESOURCES --> CONFIG RESOURCES --> OBS SECURITY --> CONFIG CONFIG --> TYPES CONTRACTS --> TYPES ENGINE --> TYPES OBS --> TYPES
Stream Element Hot Path
sequenceDiagram participant S as Source participant H as Host Runtime participant RM as Resource Manager participant P as Processor participant K as Sink rect rgb(232, 245, 233) S->>H: pull() returns output-element Note right of S: COPY 1 H->>RM: transfer buffer ownership end rect rgb(227, 242, 253) H->>P: process(stream-element) Note right of P: COPY 2 (read) + COPY 3 (write) P-->>H: process-result H->>RM: release input, transfer output end rect rgb(255, 243, 224) H->>K: push(stream-element) Note right of K: COPY 4 K-->>H: backpressure-signal H->>RM: release buffer to pool end

Full architecture guide →

Build something with Torvyn

We are looking for early adopters. Try it, break it, tell us what worked and what did not.