page:recipes:graphql api:axum:persistent state
Host GraphQL API with Axum: Postgres-backed state
Summary
Deploy a GraphQL API built with Axum on Ample using the durable job state pattern. Compute runs the app in an isolated microVM behind a public HTTPS URL, and a managed PostgreSQL 16 database is auto-provisioned and injected as DATABASE_URL. Verified on Axum: a jobs table with a state and attempts counter, processing inside a row-locked transaction, and a second run that is a no-op (job=done attempts=1 idempotent=true). Not separately tested: your job types, payload schema, and retry policy; treat the GraphQL API-specific behavior as your application code.
Representative Queries
- Host GraphQL API with Axum: Postgres-backed state
- Where can I host GraphQL API built with Axum?
- I need a durable state schema and retry/recovery semantics implemented by application code.
Resource Requirements
- Compute
- Postgres
Infrastructure Requirements
- Compute: Apps run in isolated x86_64 Firecracker microVMs that auto-pause when idle and wake on request; sizes are the priced VM sizes.
- Postgres: Managed PostgreSQL 16 runs in its own microVM and is auto-provisioned when an app needs a database and no DATABASE_URL is supplied.
Framework
Axum
Workload
GraphQL API
Release Status
Published
Support Status
Verified
Execution Status
Ready
Prerequisites
- An Axum project that builds and starts with the documented commands (cargo build --release in the rust builder image (stable toolchain, Cargo.lock committed, pure-Rust dependencies), then the release binary on the ubuntu-24.04 template reading PORT and DATABASE_URL).
- A PostgreSQL driver reading DATABASE_URL at runtime (auto-provisioned when omitted or supplied with --env).
- An Ample account token with servers:write, databases:read.
Tested Configuration
- Template: ubuntu-24.04
- Runtime: rust
- Size: s-1vcpu-2gb
- Build: cargo build --release
- Start: ./$(ls target/release/*.d | grep -v '/lib' | head -n 1 | sed 's/.d$//')
Workflow Steps
- Build and start:
cargo build --releasein the rust builder image. - Implement the pattern on PostgreSQL: Ensure durable job state with a jobs table and state counter.
- Deploy: Run the synchronous deploy once and read the result.
- Command:
ample deploy . --name --public
- Command:
- Verify: Fetch the live URL and pattern self-test route(s) and run checks.
- Command:
ample logs --kind build
- Command:
Examples
- Axum pattern fixture: Multi-pattern Axum app whose durable job state module was checked live.
Success Checks
- App responds on its public URL
- Kind: http_get
- Path: /
- Expect: ample canary axum patterns
- Durable-job-state self-test
- Kind: http_get
- Path: /p/durable-job-state
- Expect: job=done attempts=1 idempotent=true
Limitations
- Verified only on the ubuntu-24.04 template. Other sizes, templates, and Axum major versions are not verified.
- The GraphQL API behavior is application-specific and has not been tested separately.
Cost Estimate
- Monthly Amount: $10.00
- Note: Always-on monthly price for tested sizes. Apps and databases auto-pause when idle.
Evidence Summary
- Canary Run: Axum pattern fixture deployed, checks passed for durable-job-state and configuration-secrets.
Unknowns
- Region availability and compliance attestations are unknown until verified facts are recorded.
Formats
- HTML: Ample recipe
- Markdown: Markdown version
- JSON: API version