A job is a tree of processes
Billing a month of accounts, importing a large file or re-indexing a catalogue takes too long for one request and is too big for one machine. Chenile process management breaks such a job into a tree. The root process stands for the whole job. A branch process splits its work into sub-processes; a leaf process does a piece of the work; results are aggregated back up the tree until the root is done.
Every process is a row in your own database, and every process walks the same small state machine, written as a Finito flow. The work itself is done by plain typed classes called workers: a splitter, an executor and an aggregator per process type. The How it works tab shows a run from trigger to completion. This page explains the choices behind it.
The state machine: branch and leaf
A process definition says whether a process type is a leaf. The first state is an automatic decision on that flag, and from there branch and leaf processes follow different paths through one flow.
isThisLeafNode ─ leaf ─────▶ EXECUTING ── doneSuccessfully ──▶ PROCESSED
│ │ ↺ statusUpdate
│ └─ doneWithErrors ───────────▶ PROCESSED_WITH_ERRORS
└─ branch ─▶ SPLIT_PENDING ─ splitDoneWithErrors ─────▶ PROCESSED_WITH_ERRORS
│ splitPartiallyDone / splitDone
▼
SUB_PROCESSES_PENDING ◀── no ──┐
↺ splitPartiallyDone │
splitDone, subProcessDone… ─▶ areAllSubProcessesDone
│ yes
▼
AGGREGATION_PENDING ─ aggregationDoneWithErrors ─▶ PROCESSED_WITH_ERRORS
│ aggregationDone
▼
areThereErrors ─ yes ─▶ PROCESSED_WITH_ERRORS
└ no ──▶ PROCESSED
A leaf enters EXECUTING, and its executor is started. While it works it may report statusUpdate, which keeps
it in EXECUTING. It ends with doneSuccessfully (PROCESSED) or doneWithErrors (PROCESSED_WITH_ERRORS). If
the executor throws, the failure is reported as doneWithErrors, so a leaf always reaches a terminal state.
A branch enters SPLIT_PENDING, and its splitter is started. The splitter reports the children it made. A large
split can report them in batches with splitPartiallyDone and finish with splitDone, so the first children start
working before the last ones are known. Each child is a process of its own, created from its definition: a leaf, or
another branch, so the tree is as deep as the definitions say.
While its children run, the branch waits in SUB_PROCESSES_PENDING. Every time a child finishes, the branch passes
through areAllSubProcessesDone, an <if> that checks two things: has the split been completed, and has every child
reported? Both are needed. A child can finish before the splitter has reported its siblings, and the parent must
not aggregate early. When both hold, the branch moves to AGGREGATION_PENDING, and its aggregator is started with
the children’s outputs.
A child that ends with errors still counts as completed, and its error is added to the parent. So after
aggregationDone, the areThereErrors decision sends the branch to PROCESSED_WITH_ERRORS if any child failed, and
to PROCESSED otherwise. A failing splitter or aggregator ends the branch with errors directly.
The coordination rules are states and conditions in the flow, not code in the workers. A worker only does its job and reports one event; the state machine decides what that means for the tree.
Why a durable outbox, and no XA
Every state change has consequences: start a worker, create a child, tell the parent, announce that the process is done. Starting a worker means publishing a message to a broker. The obvious way is to save the process and then publish, and that has a gap. If the service crashes after the save but before the publish, the process waits forever for a worker that was never started. Publishing first is no better: the worker may start for a state change that is then rolled back.
Closing that gap directly would need one transaction across the database and the broker: XA, or two-phase commit. That is heavy to operate, not every broker supports it, and it ties every state change to the broker being available. Chenile does not use it.
Instead, every consequence is written as a row in an outbox table, in the same database and the same transaction as the state change. Either the new state and its next tasks are all stored, or none of them is. A dispatcher then reads the outbox, carries out each command, and marks it done. A command that fails is retried with backoff; after the last attempt it is marked dead, and an operator can replay it. The database’s own transaction is the only one needed.
Delivery from the outbox is at least once, so each command is guarded against running twice: by a unique key when it is written, by a claim on the row while it runs, and by a receipt for its effect. A child’s completion is counted once even if its signal is delivered twice; a successor is started once even if the completion is replayed.
The outbox is a core Chenile component, not a detail of process management, and it will get its own chapter. Triggers use the same outbox.
Triggers start the first process
Something has to start the root of a job, and that something is a trigger. Process management works with
Chenile’s trigger service: a trigger is a request to raise an event, here ProcessCreate, with a payload naming the
process definition and its arguments.
- External triggers. Another system calls the trigger service,
POST /trigger. It gets202 Acceptedwith the trigger’s id at once; the process is created afterwards. - Internal triggers. A cron schedule coming due or a file landing in a watched folder raises the same trigger
from inside, and code can call
TriggerServicedirectly.
With process management, the trigger service is durable. Every trigger is accepted as a DISPATCH_TRIGGER row in the
outbox, committed before the caller gets its answer, and dispatched like any other command. A trigger sent twice with
the same idempotency key starts one process, and a cron schedule fires each occurrence once. A trigger is recorded
before anything runs, and its status can be looked up by id afterwards.
Completion chains the next process
Many jobs are pipelines: bill the month, then send the invoices, then reconcile. Process management chains them by
data. When a process reaches a terminal state it raises ProcessCompleted. Any process definition that names the
completed type as its predecessor is started next:
{ "processType": "invoicing",
"predecessorProcessType": "billing",
"predecessorArgs": "OUTPUT" }
predecessorArgs says what the successor receives: the predecessor’s input, its output, or both. A successor is
started once per predecessor run, however often the completion is delivered, and it records its predecessor’s id, so
the chain can be followed later. Definitions are checked for cycles when they are saved.
Only a successful run starts its successors. A process that ended PROCESSED_WITH_ERRORS stops the chain: invoicing
should not run on a month that was only partly billed. ProcessCompleted is still published either way, with a
successful flag, so other subscribers can react to a failed run, for example by alerting someone.
Seeing the whole run
Each process stores the id of the trigger that started its tree, its parent and its predecessor. So the questions an operator asks have exact answers: what was triggered, which processes it started, where each one is now, and what followed.
The process management console, a React application over a management API, is built on those links:
- Executions lists the triggers, from cron, files, other systems or the console itself, with their delivery status.
- Processes lists processes by type, state, trigger, parent or predecessor, with each one’s input, output, errors and completion time.
- Trace draws the connected run, from the trigger through the tree to the processes chained after it, as a clickable graph and a timeline.
- It also creates and edits cron schedules, starts a run by hand and edits database-backed definitions.
Every view is scoped to a tenant. The administration guide covers the API and the console.
Book-keeping and work run apart
Process management separates two jobs with opposite needs.
- Book-keeping is the process manager server. It owns the process tables, the outbox and the state machine, runs the dispatcher and the triggers, and decides what happens next. It is stateful, and it is replicated for availability.
- Work is done by worker deployables. A worker receives a self-describing message from a topic, runs the splitter, executor or aggregator for that process type, and reports the result back to the server over HTTP. It never touches the process database. It is stateless, and it is scaled for throughput.
Because nothing couples them except the topic and the server’s HTTP endpoint, each side scales on its own terms.
CPU-heavy executors and memory-hungry aggregators can live in different worker deployables, each with as many
instances as its load needs, while the server stays the same. The JGen chenile-process-management blueprint
generates the deployment in this shape: a server, a shared worker listener and a worker jar per process definition.
A topic per client: no noisy neighbours
In a multi-tenant deployment, one client’s huge run should not hold up everyone else’s. With a single work topic it would: a million messages from one client sit in front of a handful from another.
The queue-based worker starter can name the topic per client. Give it a template filled from the process’s headers:
new QueueBasedProcessStarter("work-%{x-chenile-tenant-id}")
Each %{header} is replaced by that header’s value when the command runs; the outbox installs the process’s tenant
first. Client acme’s work goes to work-acme and client globex’s to work-globex. Each topic gets its own
worker deployment, scaled to that client’s load, and a burst from one client queues only behind itself. Without a
template, a definition can name its own topic in its queue setting.
The JGen blueprint does this for you: answer y to topicPerClient and the generated server publishes to
<workTopic>-<tenant id>, while PROCESS_WORK_CLIENT=acme ./run-workers.sh starts a worker deployment that consumes
only acme’s topic, in its own consumer group.
Where to go next
- How it works: a process run, animated.
- The process management guide and the durable outbox for the reference.
- Deploying process management and the p1 tutorial.
- Administration and the console, and process management compared with Temporal.