Why Waymark

An API request shouldn't have to wait for a long import, a batch of emails, or an agent run. Moving that work into a background task frees the request, but then you need to track what finished and recover when a process crashes.

After a few years of running almost all of the available job libraries and services in production, I came away with a short list of things a background-job library should provide:

  • Control flow you write as ordinary code in the language you already use.
  • The same execution path locally as in production.
  • Reasonable defaults that get you to product-market fit before you have to performance-tune anything.

Waymark is built around those priorities. Today that language is Python; JavaScript is planned.

The pitch

A workflow defines what runs first, what runs in parallel, and what happens when something fails. An action does the work on a worker process. Its inputs and result are serialized so the workflow can save progress between calls. Actions may run again, by retry policy or after a node crash; you make their side effects safe to repeat. Write both in a supported language; this example uses Python:

import asyncio
from waymark import Workflow, action, workflow

@action
async def fetch_users(user_ids: list[str]) -> list[User]:
    ...

@action
async def send_email(to: str, subject: str) -> EmailResult:
    ...

@workflow
class WelcomeEmailWorkflow(Workflow):
    async def run(self, user_ids: list[str]) -> list[EmailResult]:
        users = await fetch_users(user_ids)
        active_users = [user for user in users if user.active]

        results = await asyncio.gather(
            *[send_email(to=user.email, subject="Welcome") for user in active_users],
            return_exceptions=False,
        )
        return results

Waymark compiles the workflow's control flow. For Python, it parses the syntax tree of run():

  • each await on an action dispatches it to a worker
  • the comprehension becomes a filter
  • the asyncio.gather a parallel fan-out

The compiled program is stored in Postgres. From that point on, your authored body never executes again - our Rust runtime executes the compiled program, dispatches actions to workers, and records progress.

Compile-once vs replay

Replay-based engines recover by running workflow code again and using recorded results for completed work. That requires replayed code to make the same decisions as before; time, randomness, and side effects need special handling.

Waymark compiles a workflow the first time it is run or scheduled, then the runtime executes that program and saves its state directly. The tradeoff is a restricted set of supported language patterns. Network calls, randomness, and other work outside that set belong in actions.

The compiler rejects unsupported patterns during registration, but it doesn't catch every case yet. Known issues lists Python patterns that compile and then behave differently from Python.

When to reach for Waymark

  • You're already on Postgres and a supported language (Python today), with any framework.
  • You have async-heavy code that needs to be durable and retryable: third-party API calls, slow database jobs, fan-outs.
  • You want local and production behavior to match.
  • You want background-job code to slot into your existing unit-test and static-analysis pipeline.
  • You're focused on getting to product-market fit, not on the next 10×.

Performance is a priority - Waymark has a Rust core and continuous benchmarks in CI - but it isn't the only priority. Postgres is an excellent backing store for ACID workflow state up to some scale. Once you're stressing Postgres' write capacity, you're in territory where a more specialized system is worth the operational cost.

When not to

  • You have latency-sensitive jobs that need sub-100 ms acknowledgement and dispatch.
  • You're coordinating tens of thousands of concurrent actions or more.
  • You've already outgrown another task coordinator and you need the next 10× of headroom.

For those workloads, compare systems built around a dedicated broker or a hosted workflow service. The extra operational work or service cost may be worth the capacity and support you need.

Status

Waymark is in early alpha. The runtime spec is changing quickly and we don't guarantee backward compatibility before 1.0.0. If you hit a workflow that you think should compile but doesn't, please file an issue - the compiler error includes the offending pattern and line, which is exactly what we need.

Ready to try it? Start with the Quickstart with Python.