Skip to main content
In v5 a Rust binary can be the process that runs your app. It owns the public port, claims the jobs, and consumes the events. Routes, jobs, and echoes declared in Rust run in Rust; everything else goes to your Orionjs app, which runs as a worker behind a private unix socket. Move a controller to Rust and it stops reaching Node, with no other change.
Without the host, v5 apps run like v4 apps. The host is opt-in.
Upgrading an existing v4 project? See Upgrading to v5. If you want to keep Node or Bun as the host and call Rust functions for CPU-heavy work instead, see Rust Libraries.

Breaking changes

  • Echoes: Kafka was removed. Pulse is the only event transport, configured as before in events.pulse:
    Top-level client, producer, and consumer, events.kafka, events.consumeFrom, events.publishTo, and onMessage are gone, and publish() no longer takes acks / timeout. Request echoes (/echoes-services) keep the same wire format, so v4 and v5 services can call each other.
Everything else is compatible with v4: same collections, same job and event protocols. v4 workers and v5 hosts can share jobs and Pulse consumer groups during a rolling deploy.

The Rust host

All crates are version 5.0.0, target Rust edition 2024 (Rust 1.88+), and live in crates/: The host is built on tokio (the async runtime), tower (middleware), and axum (the web framework). Add a server/ crate next to your app:
Run it from the app’s folder with the same env vars as the app (ORION_ENV_FILE_PATH, ORION_ENV_SECRET_KEY). It listens on http_port / PORT (default 3000) and starts the app with ORION_HOST=rust, a private unix socket (ORION_HOST_SOCKET), and a per-process secret token (ORION_HOST_TOKEN). The app keeps running its own jobs and event consumers until you give the host .jobs(...) or .echoes(...) (with .pulse(...)); from then on the host runs them. In development, override the worker command with ORION_NODE_COMMAND so the host runs orion dev instead of the built bundle:
orion dev restarts the worker on every change; the host keeps the port open and requests wait until the worker is back. On SIGTERM or SIGINT, the host stops taking new requests, jobs, and events, waits for what is running (in Rust and in Node), and then stops the worker’s process group (SIGTERM, then SIGKILL after 10 seconds). If the worker exits by itself, the host exits with an error so your orchestrator restarts both.

Routes

Rust routes are plain axum routes. Unmatched paths—and unmatched HTTP methods on a path handled by Rust—are forwarded to the Orionjs app, so you can move GET /items to Rust while POST /items stays in JS. Errors answer with the same JSON shape as @orion-js/http, so clients can’t tell where a route runs:
  • Error::user(code, message) and Error::user_with_extra(code, message, extra) answer 400 (UserError JSON).
  • Error::validation(errors) answers 400 (ValidationError JSON).
  • Error::auth(message) answers 401 (AuthError JSON).
  • Error::internal(message) and any std::error::Error converted with ? answer 500 with the same 10-character SHA-1 hash as @orion-js/http (while logging the underlying message).
The Jwt<Claims> extractor validates Authorization: Bearer <token> headers using jwt_secret / JWT_SECRET (HS256) automatically from the env file, or a custom JwtConfig passed via App::jwt(...) (JwtConfig::hs256 or JwtConfig::new for RS256, issuer/audience validation, etc.). Use Option<Jwt<Claims>> when authentication is optional (missing tokens become None; invalid tokens still return 401).

MongoDB and env

orionrs::env() loads the app’s encrypted env file once (ORION_ENV_FILE_PATH + ORION_ENV_SECRET_KEY). orionrs::mongo connects with the official mongodb driver and provides Orionjs-compatible IDs and dates:

Jobs

With .jobs(...), the host schedules every job from orionjs.jobs_dogs_records and orionjs.jobs_dogs_history. Jobs defined in Rust run in Rust; jobs defined only in the app are claimed by the host and run in Node, keeping their JS onError, onStale, getNextRun, executionGuard, canTakeJobs, getJobsFilter, and maxParallelExecutionsPerServer. Call startWorkers in the app as before: with the host it registers the jobs instead of polling.
Events scheduled from JS with job.schedule() or from Rust with scheduler.schedule(...), scheduler.schedule_named(...), or scheduler.schedule_many(...) run wherever the job is defined. A job defined in both runs in Rust. Long-running Rust jobs can renew their lock with context.extend_lock_time(duration).await and check context.is_stale().

Echoes

With .echoes(...), the host answers POST /echoes-services and—when .pulse(...) is configured—consumes all Pulse events. Echoes defined in Rust run in Rust; the rest are delivered to the app through echoes.deliver with the same retries and dead letters. If you omit .pulse(...), the host handles Rust request echoes and forwards other requests while the app keeps consuming its own Pulse events.
Use the same consumerGroup as the app. The requests password is read from echoes_password / ECHOES_PASSWORD (or set explicitly with .password(...)), and the handler path defaults to /echoes-services (override with .handler_path(...)). For batch consumers matching createEchoBatchEvent in JS, use .batch_event(topic, batch_size, EventOptions::default(), handler).

A full example

examples/backend-base runs a flow across both languages: a Rust route (POST /examples) publishes example.created, a JS echo schedules the JS job processExample, the host claims and runs it in Node, and it publishes example.processed, which a Rust echo handles. Its end-to-end tests (bun run e2e) start the real host binary and Orionjs app.