Dataflow-rs
A high-performance rules engine for IFTTT-style automation in Rust with zero-overhead JSONLogic evaluation.
Dataflow-rs is a lightweight, embeddable rules engine that lets you define IF โ THEN โ THAT automation in JSON. The builder compiles every rule's JSONLogic once at build time, so runs skip parsing and execute host functions on Tokio. Use it to route events, validate data, or build multi-step automation pipelines.
โก Performance
Dataflow-rs targets high-throughput hot paths. The builder compiles every expression, task config, and write path once at build time. A run evaluates against one view of the message and reads the clock once.
In the 4.0 release gate against 3.15.0, the benchmark harness scored 16 of 49 metrics faster, 25 better, and 6 equal, while the two remaining metrics matched at seven rounds. loop_scaling, a 1000-sweep append loop over a large context, finished in 1 to 3% of 3.15's time. See Performance for the benchmark methodology and commands.
๐งฉ Full-Stack Ecosystem
Run the same rule definitions across your stack:
- Rust Backend: Run natively with high speed and concurrency using
dataflow-rs. - Browser & Edge: Run client-side validations or edge routing through the WebAssembly bindings in @goplasmatic/dataflow-wasm.
- React UI Admin Portal: Let your team and your users visualize, edit, and step through rules with @goplasmatic/dataflow-ui.
How It Works: IF โ THEN โ THAT
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Rule (Workflow) โ
โ โ
โ IF condition matches โ JSONLogic against any field โ
โ THEN execute actions (tasks) โ map, validate, custom logic โ
โ THAT chain more rules โ priority-ordered execution โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Example: IF order.total > 1000 THEN apply_discount AND notify_manager
Core Concepts
| Term | In the API | Description |
|---|---|---|
| Rule | WorkflowDef |
A condition plus a list of tasks: IF the condition holds, THEN the tasks run |
| Action | TaskDef |
One processing step: a built-in (map, validation, ...) or a function you register |
| Message | Message |
Input and state for a run: payload, a context of data, metadata, and temp_data, an audit trail, and an error list |
| Engine | Engine |
Compiled rules plus registered functions; run takes a message through matching rules |
| Run | Run |
Report for one execution: status, per-rule records, and an optional trace |
Why dataflow-rs?
Dynamic business rules and user-customizable workflows outgrow hardcoded if/else branches, while distributed orchestrators (like Temporal or Zeebe) add infrastructure and network latency. Dataflow-rs sits between the two:
| Capability | Hardcoded Rust | dataflow-rs | Heavy Orchestrators (Temporal/Zeebe) |
|---|---|---|---|
| Hot Reload Rules | Recompile & redeploy | Compile the new JSON, swap the program | Deploy new worker code |
| Execution Overhead | None | Zero (pre-compiled JSONLogic) | DB reads/writes (tens of ms) |
| Browser Execution | Compile full app to WASM | Run same rules in JS via WASM | Network round-trip required |
| Visual Debugger | Build your own UI | Included React UI components | Included dashboard |
| Infrastructure | None | None (embeddable library) | Requires server clusters & DBs |
Getting Started
1. Add to Cargo.toml
[]
= "4.0"
= { = "1", = ["rt-multi-thread", "macros"] }
= "1.0"
JSONLogic's extended operator families are opt-in at runtime on
ExprEngineBuilder; ExprEngine::default() enables core JSONLogic only.
Read JSONLogic โ Operator Families
before enabling a family: turning one on can change how an existing rule behaves.
2. Define Rules in JSON
A message arrives with its body in payload. The engine evaluates conditions
and mappings against data, so the first rule loads the payload into data,
and the second rule acts on it. Chaining, the THAT in IF โ THEN โ THAT,
means rules run in order and each one sees what the previous rules wrote.
The engine evaluates a rule's condition before running its tasks. A condition reads what earlier rules produced, not what its own tasks will write. Place
parse_jsonin an earlier rule sopremium_ordercan check the parsed fields in its condition.
3. Run the Engine
use RunStatus;
use ;
use ;
async
run returns a Run for every outcome without short-circuiting. Pass
RunOptions to run_with when you need a channel, routing bucket, deadline,
cancellation token, trace, or per-run observer.
Handling Errors: Two Channels
A run reports errors through two channels:
run.status()reports how the run ended:Completed,CompletedWithErrors(rules finished, with error records on the message),Stopped(error)(a task failed and its policy stopped the run),TimedOut, orCancelled(the run hit its deadline or cancellation token).message.errors()holds every error record, including errors from tasks whose policies allowed the run to continue.
Using ? on run.into_result() surfaces only stopped, timed-out, or cancelled runs. Check both channels to handle all errors:
use RunStatus;
use ;
use json;
async
Task policies control what happens after each outcome. A 4xx status is a
rejection, governed by on_rejection: "continue" (default) or "halt".
A 5xx status or Err is a failure, governed by on_failure: "fail"
(default, which delegates to the workflow's on_failure of "fail" or
"continue"), "halt" (stops the workflow and continues the run), or
"continue". Because validation returns 400 on failure, it continues to
the next task unless you set "on_rejection": "halt". See the
error handling guide.
Branching on Task Failures
Both error channels live on the host side. Rule conditions evaluate against
data, metadata, and temp_data, which do not include message.errors().
Configure an ErrorContext path and the engine mirrors each failure's code into
the context as it occurs:
use ;
use ;
use ;
async
Each record is {workflow_id, task_id, code, status}, so a later rule can treat
a transient failure differently from a permanent one:
The engine writes to this path only when configured and resets it at the start of each run. The mirrored records omit the error message text because callers receive the serialized context.
Classifying Your Own Errors
Built-in error kinds cover engine concerns such as a missing function, a failed
evaluation, or an invalid path. When a function fails for a service-specific
reason (an open circuit breaker or a tenant rate limit), classify it with
Error::service:
use Error;
let e = service.with_retryable;
assert_eq!;
assert!;
The engine preserves your code string without changing its case and reads the
retryable flag you set. Task on_failure policies, audit entries, and
Run::status handle service errors like any other failure, while
Run::retryable returns the flag you declared.
Key Features
- IF โ THEN โ THAT Model: Define rules with JSONLogic conditions, execute actions, and chain workflows in priority order.
- Compile at Build: The builder compiles every expression, task config, and write path once and rejects invalid definitions with their authored paths.
- Complete Run Reports:
runreturns aRunwhether execution completed, stopped, timed out, or was cancelled, preserving the message and trace. - Full Context Access: Conditions read any field in
data,metadata, andtemp_data. - Isolated Secrets:
{"secret": "name"}reads an engine-scoped store that stays out of traces, audit entries, and serialized messages.build()rejects workflows that would write a secret into the message. - Async Host Functions: Host functions are
async fnon Tokio; the eight built-in functions run inline. - Tracing and Observability:
TraceOptionsrecords per-step changes that replay to reconstruct the context at any step, bounded by a byte budget and path redaction.Observerreceives inline task events and reads the clock only whenInterest::TIMINGSis set. - Built-in Functions: Parse, Map, Validate, Filter, Log, and Publish.
- Outcome Policies: Configure
on_failureandon_rejectionper task,on_failureper workflow,terminaltasks, and task groups sharing a condition. - Loops and Fan-Outs: Workflow
loopruns a task list for a bounded number of sweeps. Taskfor_eachcalls a host function per array element in isolation and folds results in element order at anymax_concurrency. - Deadlines and Cancellation:
RunOptions::deadlineandCancelTokenend a run asTimedOutorCancelled, returning the partial message and trace. - Routing and Rollout: Route by channel, split traffic by bucket range, and manage workflow
status(active,paused,archived), version, and tags. - Hot Reload: Compile new definitions with
engine.compiler()and swap the program withwith_programwhile in-flight runs finish on the old program. - Extensible: Implement
Functionwith#[derive(FunctionConfig)], wrap host calls in aCallLayer, and unit-test individual calls withfunction::testing::call. - Service-Classified Errors: Attach custom error codes and retryability with
Error::service, and mirror failure codes into the context withErrorContext. - 3.x Compatibility: The compat reader rewrites 3.x spellings into 4.0 format and reports each as an Advisory; see Migrating from 3.x.
- Browser and UI: Run rules in the browser with
@goplasmatic/dataflow-wasmand debug them with@goplasmatic/dataflow-ui. - Auditing: Record an audit trail of context changes as data moves through the pipeline.
Architecture
Compilation (startup). def::parse reads each definition, rewrites 3.x
spellings, and reports issues at their authored paths. Compiler compiles each
workflow against a Registry (expressions, task configs, write paths), so you
can quarantine invalid workflows and keep valid ones. link sorts compiled
workflows by priority into an immutable Program. Engine::builder().build()
runs all three steps and fails if any workflow is rejected.
Execution (runtime). run stamps the message and evaluates active
workflows in priority order, checking rollout and then condition. Built-in
functions run inline over one view of the context. Host functions receive a
Ctx whose writes apply on Ok and drop on Err. After each non-skipped
call, the engine updates metadata.progress so later rules can inspect what
ran. Run reports the final status and per-workflow results, Observer
receives inline events, and Trace records step diffs when requested.
Performance
Key design choices keep per-message overhead low:
- Compile at Build: The builder compiles expressions, folds constants, and pre-splits write paths ahead of time, so a run does no parsing.
- One View per Run: Built-in tasks evaluate against a single arena view of the context and splice writes in place.
- Overlay Writes: Host function writes land in a per-call overlay that the function can read immediately; the engine replays them into the context when the call returns
Ok. - Zero-Cost When Unwatched: A run reads the clock once. Observer and trace work runs only when attached; the unwatched path adds a single branch per call.
- Async I/O: Host functions run on Tokio without blocking, and fan-outs run calls concurrently without spawning tasks.
In the 4.0 release gate against 3.15.0, 16 of 49 metrics scored faster, 25
better, and 6 equal, while the two micro_subtree_write_bench rows matched at
seven rounds. loop_scaling ran in 1 to 3% of 3.15's time. bench/gate.py
compares a base commit against a candidate by alternating both builds within
each round and judging the median per-round ratio against a noise floor of 3%
or half the inter-quartile range.
Tuning tip: If you do not read audit trails, pass
RunOptions::default().capture_changes(false) or keep only recent entries
with .audit(AuditMode::Last(n)). Skipping per-write old and new value copies
gives the largest savings in mapping-heavy and looping workflows. See the
performance guide.
Run benchmarks with --release. The crate includes thirteen benchmark examples
(listed in CONTRIBUTING.md), and each verifies
its output before timing:
Runs vary by 2 to 3%. Compare the mean of three or more interleaved A/B runs.
Custom Functions
Extend the engine with your own async actions. A function declares a typed
Config, compiled once when the engine is built, receives a Ctx whose
writes record audit-trail changes for you, and returns an Outcome:
use OwnedDataValue;
use Output;
use ;
use RunStatus;
use ;
use ;
/// The task's `input`, compiled once when the engine is built. A malformed
/// one is refused there, with an issue at its key, not on the first message.
;
async
Outcome::Ok records status 200; Outcome::Status(n) records n, a 4xx
being a rejection and a 5xx a failure for the task's policies; Skip
records no entry; Halt records 299 and ends the rest of the workflow. A
call's writes reach the message only when it returns Ok: an Err drops them
whole, so a function never leaves a half-written message behind.
Every config field is JSONLogic, and the static spelling is free: a JSON
literal is JSONLogic for itself, so "channel": "orders" folds to a
constant at build time and costs nothing per message. Expr<T> is a field
the function evaluates (T fixes the result type), Output a destination it
writes through, and #[config(default = ...)] an authored default. One catch:
a single-key object whose key names an operator is that operator, so write
{"$cat": ...} for the literal object. See
Custom Functions and
Literal keys and the $ escape.
Built-in Functions
| Function | Purpose | Modifies Data |
|---|---|---|
parse_json |
Parse JSON from payload into data context | Yes |
parse_xml |
Parse XML string into JSON data structure | Yes |
map |
Data transformation using JSONLogic | Yes |
validation |
Rule-based data validation | No (read-only) |
filter |
Pipeline control flow: halt workflow or skip task | No |
log |
Structured logging with JSONLogic expressions | No |
publish_json |
Serialize data to JSON string | Yes |
publish_xml |
Serialize data to XML string | Yes |
The eight run inline, on the run's own view of the context, so a task calling
one cannot carry for_each; their names are reserved.
Filter (Pipeline Control Flow)
The filter function evaluates a JSONLogic condition and controls pipeline execution:
on_reject: "halt"stops the entire workflow when the condition is falseon_reject: "skip"skips only the current task and continues
Log (Structured Logging)
The log function outputs structured log messages using the log crate:
Log levels: trace, debug, info, warn, error. Messages and fields support JSONLogic expressions.
Channel Routing
Workflows name a channel ({ "id": "order_rule", "channel": "orders", ... }),
and a run can take only that channel's workflows:
use ;
/// Runs only the Active workflows of the `orders` channel.
async
Only active workflows run, with or without a channel. Workflows default to
the "default" channel, and the run stamps metadata.channel when it was
started on one.
Workflow Lifecycle
Workflows support lifecycle management fields:
{
"id": "my_rule",
"channel": "orders",
"version": 2,
"status": "active",
"tags": ["premium", "high-priority"],
"created_at": "2025-01-15T10:00:00Z",
"updated_at": "2025-06-01T14:30:00Z",
"tasks": [...]
}
| Field | Type | Default | Description |
|---|---|---|---|
priority |
number | 0 |
Run order: lower runs first, equal priorities keep their order |
channel |
string | "default" |
Channel for message routing |
version |
number | 1 |
Workflow version |
status |
string | "active" |
active, paused, or archived |
tags |
array | [] |
Arbitrary tags for organization |
rollout |
object | null |
Traffic split: {bucket_start, bucket_end} over 0..100 |
created_at |
datetime | null |
Creation timestamp (ISO 8601) |
updated_at |
datetime | null |
Last update timestamp (ISO 8601) |
All fields are optional. Unknown keys move into the node's ext map and produce an issue report.
Traffic Splits (Canary Rollouts)
Give a workflow a slice of its channel's traffic with a half-open bucket range
over 0..100, so a new version can roll out gradually alongside the old one:
{
"id": "checkout_v2",
"channel": "checkout",
"rollout": { "bucket_start": 0, "bucket_end": 10 },
"tasks": [...]
}
That workflow serves buckets 0..=9, 10% of traffic. bucket_start is
inclusive and bucket_end exclusive, so a {"bucket_start": 10, "bucket_end": 100}
sibling covers the remaining 90% with no overlap and no gap.
The engine does not derive the bucket. Set it per run with your own policy (a sticky hash of a user id, a random draw, round-robin):
use ;
async
Every workflow, split or not, admits a run with no bucket, so every caller
that predates rollouts keeps working unchanged. The engine skips an excluded
workflow before any other per-message work, and the Run records it as
SkippedByRollout.
Secrets
A signing key or partner token has to be readable by a condition and must never appear in a trace. The message context cannot express that, because everything in it is recorded. Secrets therefore live in a store on the expression engine, and expressions read them through one reserved operator:
use OwnedDataValue;
use ;
use ;
use json;
The value never enters a Message, so it cannot appear in anything derived
from one. build() refuses a map mapping or log expression that reads a
secret (SECRET_IN_MESSAGE_WRITE), and a name the store does not declare
(UNKNOWN_SECRET). A host function reads one through Ctx::secret or an
Expr field, and a layer's view of its config shows that field as null.
Derived values such as an HMAC belong in such a function. See the
Secrets page.
Reloading Definitions
An Engine is a program plus its config, behind an Arc. To reload, compile
the new definitions with the engine's own compiler, which shares its
functions, operators and secrets, and swap the program:
use Engine;
use ;
use Value;
/// An engine running `definition` in place of this one's program. `engine`
/// is unchanged, and keeps serving any message in flight.
Each workflow compiles on its own, so a host that quarantines keeps the ones
that compile and reports the rest. Compiler::check gives every issue of a
definition, Advisories included, for an editor's pre-save screen.
Execution Tracing & Observability
Ask a run for a trace and the Run carries one: the context after the run's
stamps, then one step per call, skip and failure with the changes it made.
Replaying the changes gives the context after every step, so a trace is a
step debugger's input without a message snapshot per task. TraceOptions
bound it up front: timings, changes, path redaction and a byte budget.
use TraceOptions;
use ;
async
For always-on aggregation instead of a per-request trace, attach an
Observer. It is called inline, once per task, built-ins included, and its
Interest says which events it wants: without TIMINGS no clock is read.
use ;
use EngineConfig;
use ;
use Value;
use Arc;
use ;
/// An engine over `definitions` that reports every run to `metrics`.
RunOptions::observer attaches one to a single run instead. With neither an
observer nor a trace attached, their costs, clock reads included, stay out of
the dispatch path.
Visualize & Debug Rules
Because every rule is plain JSON, the React UI can render it: JSONLogic expressions become readable flow diagrams, and the debugger runs a message through the engine and steps through its trace, rebuilding the context after every task from the trace's changes. A run that stops shows its status and the step that failed.
Ecosystem
| Package | Description | Install |
|---|---|---|
| dataflow-rs | The rules engine in Rust (this crate) | cargo add dataflow-rs |
| @goplasmatic/dataflow-wasm | The engine for the browser and Node: one WasmEngine, whose run(payload, options) resolves with the message, the run and a trace on every status, typed end to end |
npm i @goplasmatic/dataflow-wasm |
| @goplasmatic/dataflow-ui | React components for rule visualization, editing, and step-by-step debugging over the engine's traces | npm i @goplasmatic/dataflow-ui |
| datalogic-rs | JSONLogic compiler/evaluator used internally | cargo add datalogic-rs |
๐ Documentation: User Guide & API Reference ยท Interactive Playground ยท Visual Debugger
Migrating from 3.x
Existing 3.x definitions load through the compat reader, which is enabled by
default. The reader rewrites 3.x spellings into 4.0 equivalents
(continue_on_error and halt_on into on_failure and on_rejection, and
validate into validation) and reports each as a V3_SPELLING Advisory at
the 3.x key. dataflow_rs::compat::migrate_v3 writes a definition out in the
4.0 format. In the Rust API, Engine::run returns a Run on every status in
place of the process_message family, host functions implement Function with
#[derive(FunctionConfig)] in place of AsyncFunctionHandler and
TaskContext, Outcome replaces TaskOutcome, Error replaces
DataflowError, and Message::from_json or Message::from_parts replaces
Message::builder. Wire formats for Message, audit trails, and error records
match 3.x. See Migrating from 3.x.
Contributing
Contributions are welcome:
- Fork the repository and clone your fork
- Run tests:
cargo test --workspace --all-features(what CI runs) andcargo testat the root (the default feature set) - Make changes and add tests for new features
- Run the benchmarks before and after:
cargo run --example benchmark --release, interleaving the two builds - Submit a pull request describing your changes
See CONTRIBUTING.md for the CI checks and CHANGELOG for release history.
About Plasmatic
The Plasmatic team develops dataflow-rs and builds open-source tools for data processing and automation.
License
Apache License, Version 2.0. See LICENSE.