Skip to main content
Version: Next

Tutorial: your first distributed job

Debug a stateful, event-time Job locally, then submit the same spec to a Hub and watch it land on compute nodes. Takes about 20 minutes.

Prerequisites. Completed the fleet tutorial (Hub running, one Agent node registered); built arkflow.

1. Write the job​

The Job is a DAG with event time, state, checkpointing, and a recovery policy. Use the maintained example — examples/jobs_local.yaml (manifest name jobs-local): a generate source with event time and a watermark feeding a stdout sink, with embedded KV state, 30 s checkpoints in a local object store, and recovery: latest_checkpoint.

arkflow --config examples/jobs_local.yaml --validate
arkflow --config examples/jobs_local.yaml

Expected result: validation passes (the same deep build as startup), and the local run prints windowed aggregates with the __arkflow_window_update re-emissions when late rows arrive (the example uses late_event_policy: update).

2. Understand the spec you will submit​

Key fields (full reference: configuration → job):

FieldMeaning
parallelism / max_parallelismTask count and key-group space; keep max_parallelism stable across rescales.
edges[].partitionedRoutes by key-group ownership.
timeEvent-time mode, timestamp field, watermark, late policy.
state / checkpoint / recoveryEmbedded KV state, checkpoint cadence and retention, and the recovery policy.

Because the same JobSpec shape is what the Hub distributes, nothing changes between local and fleet execution except placement.

3. Submit to the Hub​

The API carries the Job spec as a JSON object in the spec field of the request body ({"spec": {...}, "desired_state": "..."}) — convert the YAML example once, then validate and create the Job stopped:

SPEC=$(python3 -c "import json,yaml;print(json.dumps(yaml.safe_load(open('examples/jobs_local.yaml'))['jobs'][0]))")
curl -s -H 'Content-Type: application/json' \
-d "{\"spec\": $SPEC}" \
http://127.0.0.1:8080/api/v1/jobs/validate | jq
curl -s -H 'Content-Type: application/json' \
-d "{\"spec\": $SPEC, \"desired_state\": \"stopped\"}" \
http://127.0.0.1:8080/api/v1/jobs | jq

The workbench in the console does the same: Jobs → New, paste the spec, validate, then submit.

Expected result: validation reports the compiled plan and node capabilities; creation answers with the Job record.

4. Inspect detail, then start​

curl -s http://127.0.0.1:8080/api/v1/jobs/<job-id>/detail | jq
curl -s -X POST http://127.0.0.1:8080/api/v1/jobs/<job-id>/actions/start | jq

Expected result: detail shows the planned tasks and placement; after start, the job detail shows tasks observed running on the node, and the node's stdout prints the aggregates.

5. Checkpoint, pause, resume​

curl -s -X POST http://127.0.0.1:8080/api/v1/jobs/<job-id>/checkpoints | jq
curl -s -X POST http://127.0.0.1:8080/api/v1/jobs/<job-id>/actions/pause | jq
curl -s -X POST http://127.0.0.1:8080/api/v1/jobs/<job-id>/actions/resume | jq

Pause captures a recovery artifact before stopping; resume bumps the generation and restores from it. Events processed after the artifact replay — exactly-once for transactional sinks, at-least-once otherwise.

6. Kill a node (failure drill)​

Stop the node process mid-run. Expected behavior: the job reports reconciling; when the node rejoins, it restores from the latest checkpoint and continues (incremental re-placement if the node stays gone). Watch GET /api/v1/jobs/<job-id> and the event stream.

What you learned​

  • The same JobSpec runs locally and fleet-wide.
  • Validate → submit stopped → inspect detail → start is the safe sequence.
  • Pause/resume are recovery-artifact based; node failure converges without operator intervention.

Next steps​