Workflow Backend Pack
The Workflow Backend Pack is the third concrete Xian solution pack.
It is also the third pack that has been deepened into a fuller reference application slice.
It shows how to use Xian as a job-style workflow backend where clients submit items, workers claim them, and workers complete or fail them while off-chain systems consume events and indexed state/history.
When To Use It
This pattern fits well when you need:
- order or fulfillment workflows
- claims processing
- ticket or task lifecycles
- shared job queues with explicit state transitions
The application keeps richer business data elsewhere and uses Xian as the authoritative workflow state machine and transition history layer.
Why Xian Fits
This pack is the strongest expression of Xian as a decentralized backend:
- explicit workflow rules on-chain
- event-driven Python workers around the chain
- clear API-service integration
- strong history and auditability through indexed reads
- a clean operator story for backend-oriented deployments
Reference-App Pattern
The deeper reference-app slice for this pack uses a four-part shape:
- the Xian contract remains the authoritative workflow state machine
- a processor worker reacts to submitted items and drives the workflow
- indexed BDS events trigger a resumable projector
- the projector hydrates current item state from authoritative contract reads into a local SQLite projection
This is the clearest expression of Xian as a decentralized backend:
- the chain enforces workflow transitions
- a processor worker performs application work around the chain
- a projector builds queue and activity views for application reads
Recommended Operator Paths
Use these templates:
- local development:
single-node-indexed - remote deployment:
embedded-backend
Those operator paths match the pack:
- indexed reads for current workflow state and history
- backend-oriented runtime defaults
- monitoring and recovery surfaces that fit event-driven services
Pack Assets
Contract Asset
The reusable workflow contract lives in xian-configs:
solution-packs/workflow-backend/contracts/job_workflow.s.py
The intended deployed contract name in the examples is:
con_job_workflowThe contract models:
- submitted items
- worker claims
- completion
- failure
- cancellation
SDK Examples
The xian-py repo includes pack-specific examples under:
examples/workflow_backend/admin_job.pyexamples/workflow_backend/api_service.pyexamples/workflow_backend/processor_worker.pyexamples/workflow_backend/projector_worker.pyexamples/workflow_backend/event_worker.py
Those cover:
- bootstrap and worker setup
- API submission/query/cancel flows
- event-driven worker processing
- a local projected queue and activity model
Local Walkthrough
1. Create And Start A Local Indexed Node
cd ~/xian/xian-cli
uv run xian network create workflow-local --chain-id xian-workflow-local-1 \
--template single-node-indexed --generate-validator-key --init-node
uv run xian node start validator-1
uv run xian node health validator-12. Bootstrap The Workflow Contract
Use the admin job from xian-py:
cd ~/xian/xian-py
export XIAN_NODE_URL=http://127.0.0.1:26657
export XIAN_CHAIN_ID=xian-workflow-local-1
export XIAN_WALLET_PRIVATE_KEY=<private-key-hex>
uv run python examples/workflow_backend/admin_job.pyThe admin job:
- deploys
con_job_workflowif it does not exist yet - optionally adds worker accounts from
XIAN_WORKFLOW_WORKERS - optionally submits an initial item when
XIAN_WORKFLOW_ITEM_IDis set
3. Run The API Service
uv run uvicorn examples.workflow_backend.api_service:app --reload --app-dir .The service exposes:
GET /healthGET /projection/healthGET /projection/summaryGET /itemsGET /items/{item_id}GET /items/{item_id}/activityGET /activity/recentPOST /itemsPOST /items/{item_id}/cancel
The important split is:
items/{item_id}still exposes the authoritative contract readprojection/*,items, andactivity/*expose the local projected queue and workflow views
4. Run The Processor Worker
uv run python examples/workflow_backend/processor_worker.pyThe processor worker:
- watches
ItemSubmitted - claims new items
- completes or fails them
- keeps its own submission cursor so processing resumes cleanly after restarts
5. Run The Projector Worker
uv run python examples/workflow_backend/projector_worker.pyThe projector:
- backfills from indexed BDS events on first start
- persists a local SQLite queue/activity projection
- maintains resumable cursors inside that projection database
- hydrates current item state from
con_job_workflow.get_item
It consumes:
ItemSubmittedItemClaimedItemCompletedItemFailedItemCancelled
The default projection database path is:
.workflow-backend-projection.sqlite3Override it with:
export XIAN_WORKFLOW_PROJECTION_PATH=/path/to/workflow-backend.sqlite36. Query The Reference-App Views
Once the projector is running, you can query the richer application views:
curl http://127.0.0.1:8000/projection/summary
curl http://127.0.0.1:8000/items
curl http://127.0.0.1:8000/items?status=processing
curl http://127.0.0.1:8000/activity/recentThose routes demonstrate the intended division of labor:
- Xian stores and enforces workflow state
- the processor worker reacts to submitted items
- indexed events trigger projection updates
- authoritative
get_itemreads hydrate the projection - the API serves both on-chain reads and application-oriented queue views
Remote Operator Story
For remote Linux hosts, use xian-deploy with the embedded-backend deployment posture.
The main remote commands remain:
ansible-playbook playbooks/deploy.yml
ansible-playbook playbooks/health.yml
ansible-playbook playbooks/bootstrap-state-sync.yml
ansible-playbook playbooks/restore-state-snapshot.ymlUse recovery intentionally:
- prepared node-home archive:
push-home.ymlthendeploy.yml - application-state snapshot import:
restore-state-snapshot.yml - protocol state sync:
bootstrap-state-sync.yml
See Starting, Stopping & Monitoring for the concrete local and remote runbooks.
What This Pack Proves
The Workflow Backend Pack proves that Xian can act as:
- a shared job/workflow state machine
- an event-driven backend coordination layer
- a projected queue and activity source for backend services
- a practical integration target for Python services and workers
It is the third pack because it is the strongest full expression of the product thesis after the simpler ledger and approval patterns.