Statehelm

Every workflow is a line on a map.

Statehelm runs AWS Step Functions style state machines on a PostgreSQL you already operate. It speaks the Step Functions API (tested with boto3) and needs only Postgres.

Read the source
Ready demo-parallel-catch

Press Replay a run to play back a recorded execution.

Recorded from a real run of the built-in demo machine, replayed slowly. A live demo will replace this recording.
All recorded events

    Run it locally.

    Clone the repository, then start Postgres, the engine and the Studio UI with one compose command. Ports are published on localhost only.

    Terminal

    docker compose up -d --build
    open http://localhost:8080
    Statehelm Studio showing the choice-demo state machine as a graph. Validate and Route are green and finished, Approve is blue and running, and AutoApprove, Fallback, Reject and Done are grey and idle. The event log on the right lists six events.
    The Studio UI mid-run: the execution has passed Validate and Route and is on the Approve task.

    Python, with boto3

    import boto3, json, time
    
    sfn = boto3.client(
        "stepfunctions",
        endpoint_url="http://localhost:8080",
        region_name="us-east-1",
        aws_access_key_id="local",
        aws_secret_access_key="local",
    )
    machine = sfn.create_state_machine(
        name="hello",
        roleArn="arn:aws:iam::123456789012:role/unused",
        definition=json.dumps({
            "StartAt": "Greet",
            "States": {"Greet": {"Type": "Pass", "Result": "hello", "End": True}},
        }),
    )
    run = sfn.start_execution(stateMachineArn=machine["stateMachineArn"], input="{}")
    while (
        status := sfn.describe_execution(executionArn=run["executionArn"])["status"]
    ) == "RUNNING":
        time.sleep(0.5)
    print(status)  # SUCCEEDED

    The default auth mode skips signature checks. That is fine on your own machine and wrong on an exposed one. The tests use boto3, and other AWS SDKs take the same endpoint override. The AWS Terraform provider works too.

    Test results and benchmarks.

    Each row can be reproduced from the repository.

    Measured results
    LineResultDetail
    Crash recovery 200 of 200 finished 3 replicas, 8 processes killed with SIGKILL mid-run. No lost transitions, no duplicate events, no stuck steps. Run it yourself with tests/chaos/run.sh.
    API compatibility 37 of 37 passing The official boto3 client against a running engine, across all 19 Step Functions actions in scope.
    Automated checks Passing on every push About 380 Java tests with a real PostgreSQL, the boto3 suite, the crash test, the UI tests and a Docker image smoke test all run in CI.
    Throughput 234 to 851 transitions per second Pass-only machine of 5 states: 374 on one replica, 851 on three. Machine with HTTP tasks, 3 states: 234 and 394. One run per row on a single laptop, with Postgres and the load generator on the same machine. p99 latency 0.5 to 1.1 seconds. Results vary a lot between runs. No other engine was measured, so there is no comparison.
    Transitions per second, one run per bar. The table above has the caveats.

    How it works.

    Postgres is the only datastore. Any number of identical replicas run against it.

    1. Claiming steps

      Replicas take due steps with FOR UPDATE SKIP LOCKED in a single statement, so they never wait on each other's rows.

    2. One transaction per transition

      A step runs outside any transaction. Applying its result is one transaction guarded by status and attempt number, so a stale replica cannot overwrite a newer claim.

    3. At least once

      If a replica dies, a reaper returns its step to pending and another replica runs it again. Task targets must tolerate a repeated call.

    4. The SSRF guard

      The check runs inside the HTTP client's DNS lookup, so a hostile DNS answer cannot swap the address between the check and the connection.

    What it does not do yet.

    Statehelm is version 0.1.

    • It supports a subset of the language: no JSONata, distributed S3 Map, activity polling or the 200 plus native AWS integrations.
    • Published state machine versions are not supported, so ListStateMachineVersions always returns an empty list.
    • SQS is tested against ElasticMQ, an SQS-compatible server, but not against AWS SQS itself.
    • It has not run under production load. There is one benchmark, on a laptop.
    • Steps run at least once, so a target that is not safe to call twice needs its own deduplication.

    Read the code.

    The code, the tests and the design notes are in one repository, under the Apache License 2.0.

    Read the source on GitHub