Writeback to source systems
A decision made in the Ontology is only real once the system that runs the work knows about it. Writeback delivers committed edits to systems of record, such as the ERP that owns shipments and the warehouse system that owns pick waves, through their connectors. Its job is to deliver an edit once, in order, without overwriting a change someone made in the source in the meantime, and to make anything that cannot be delivered visible to a person rather than lost
In the platform today
- An action type's
writebackentries queue one row per target inops.writeback_outbox, in the same commit as the edits and the action log entry, with a stable key per delivery - Each target is an operation in
systems.yaml; an operation withoutkind: httpupdates or inserts into a raw table that stands in for the system - An operation with
kind: httpis a call to the system's own API:baseUrl, an outboundallowHostslist, the idempotency key inidempotencyHeader, typedinputs, templates, secrets held by the platform and never in definitions,outputsread from the answer, chained calls (first:),timeoutSeconds,concurrencyandrateLimit, with every attempt kept inops.call_runs - A 2xx is delivered, a code in
unchangedOnmeans the system already had it, a code inretryOn, a timeout or a refused connection is temporary, and anything else is permanent - A temporary failure is retried by a timer after 30 seconds, then 2, 10 and 30 minutes, with the same key; a permanent one, or a fifth failed attempt, makes the row a dead letter, which raises a
writeback.failedwebhook event and shows in the inbox of the person who ran the action, and the log entry's writeback status follows its rows (delivered, retrying or failed) - A writeback entry with
when: beforecalls the system inside the run, before any edit, and its outputs, such as the purchase order number the ERP assigned, become operands for the rules, notifications and later writeback; if the call fails nothing is edited and the person sees the system's message (WRITEBACK_FAILED) - Undoing an applied action (
POST /api/v2/action-log/{logId}:revert) cancels writeback still waiting and puts back what delivered writeback changed, through the operation'sundocall or the undo record the platform keeps - A data branch makes no outside calls
- The rest of this page: the 72-hour backoff with jitter, ordering per target key, conflict checks with source refresh, the reference field with read-before-write, writeback through edge agents and the dead-letter API
- A
writebackentry on the action type and an operation insystems.yaml, either a call to the system's API (kind: http) or a stand-in raw table, with the system's credentials held by the platform - Owner on the ontology to declare writeback on an action type, and Administrator to create the connector and its credentials
- Every access label on the object types being written, both for the person defining the writeback and for whoever applies the action
- A connector for the target system with write access, and the operation it will call configured and tested
- An edge agent on the plant network for targets that are not reachable from the cloud, such as the MES or a local WMS
- A system of record named for each property the action edits, so the registry can check that every owned property has a writeback
The built format
In the platform service, writeback is declared on the action type in ontology.yaml and the targets are described in systems.yaml in the same ontology folder. The demo airline's ground-aircraft action writes the grounding to its maintenance information system
# ontology.yaml, on the action type
writeback:
- { system: maintenance, operation: set-aircraft-status,
payload: { fleetNumber: { parameter: aircraft }, status: AOG,
reason: { parameter: reason }, since: { now: true } } }
# systems.yaml: the raw table that stands in for the system
systems:
maintenance:
name: Maintenance information system
operations:
set-aircraft-status:
table: raw.mis_aircraft
# rows to update, which must exist
key: { fleet_number: fleetNumber }
# '=' marks a constant
set: { status: '=AOG', status_reason: reason, status_since: since }
Payload values use the same operands as action rules: parameters, properties of object parameters, the current user, now, templates, function results, one field of a function's result ({ function, args, property }) and an output of an earlier writeback ({ writeback, field }). An operation with insert instead of key and set appends a row, as create-deferral does. A raw table operation stands in for a system, so a demo or a test runs without one; a call to the system's own API is an operation with kind: http
Calls to a system's API
An operation with kind: http is a typed call. The system holds what every call shares, and each operation names its method, URL, inputs and outputs. A token call can be chained in front of the real one and its answer cached
# systems.yaml
systems:
erp:
name: ERP
baseUrl: https://erp.example.com/api
allowHosts: [erp.example.com] # outbound allow-list; default: the baseUrl's host
idempotencyHeader: Idempotency-Key # carries the writeback's idempotency key
timeoutSeconds: 20 # at most 180
concurrency: 4 # calls in flight, across every copy of the service
rateLimit: { perSecond: 5, perMinute: 120, perHour: 2000, perDay: 20000 }
operations:
get-token:
kind: http
method: POST
url: /oauth/token
form: { grant_type: client_credentials,
client_id: { secret: ERP_CLIENT_ID },
client_secret: { secret: ERP_CLIENT_SECRET } }
outputs: { token: access_token }
cacheSeconds: 3000
create-po:
kind: http
inputs: { supplier: { type: string, required: true }, total: { type: double } }
first: [{ call: get-token, as: auth }]
method: POST
url: /purchase-orders
headers: { Authorization: "Bearer {{ auth.token }}" }
body: { supplierId: "{{ supplier }}", total: "{{ total }}" }
outputs: { poNumber: id, firstLine: "items[0].id" }
retryOn: [429, 503]
unchangedOn: [409]
undo: cancel-po
cancel-po:
kind: http
inputs: { poNumber: { type: string, required: true } }
method: POST
url: /purchase-orders/{{ poNumber }}/cancel
| Part | Rule |
|---|---|
| Inputs | Typed as string, integer, double, boolean, date, timestamp, list or struct, and optional unless required: true. A writeback payload key that is not an input, or a required input it leaves out, is refused when the ontology loads |
| Templates | A value that is exactly one slot, "{{ total }}", keeps its type in a JSON body. Slots name an input or a chained call's alias. In the URL they are percent-encoded, so an input can never change the host. query: adds query parameters, and form: sends a form instead of body: |
| Secrets | { secret: NAME }, with an optional prefix: "Bearer ", resolved by the platform when the call is made. A header or field named like a secret must be one or a template, never a literal, and secret values are replaced with [secret] in everything the history keeps |
| Outputs | A path into the JSON answer (id, data.items.0.id, items[0].id, $.id), { header: Location } or { status: true }. required: true fails the call without it |
| Answers | A 2xx succeeds. A code in unchangedOn means the system already had it: delivered, with no undo kept. A code in retryOn (by default 408, 425, 429, 500, 502, 503 and 504), a timeout or a refused connection is temporary. Anything else is permanent, including a redirect, which is not followed |
| Chained calls | first: runs calls in order before the operation, each with its own inputs, limits and history row, at most four deep. A cycle is refused when the ontology loads |
| Limits | concurrency and rateLimit apply per system and per operation. When the service runs as several copies on one lake, the copies count together. A call waits up to 5 s for a slot, then fails as temporary (RATE_LIMITED) |
| History | Every attempt is a row in ops.call_runs: system, operation, kind (before, after, undo or chain), log and outbox ids, method, URL, idempotency key, status code, outcome, error, duration and, unless storeResponse: false, the outputs and the request and response bodies, 64 KB each at most. Rows are kept six months |
| Undo | undo names the operation an action revert calls, with this call's inputs and outputs |
| Branches | A data branch makes no outside calls (BRANCH_NO_CALLS): a call before the edits refuses the run, and one after the commit becomes a dead letter |
Administrators read each system, its operations and whether each secret is set with GET /api/v2/writeback/systems, and the call history, newest first, with GET /api/v2/writeback/calls?system=&operation=&logId=&outcome=&limit=
Writeback before the edits
Some systems assign the number everyone will use, such as a purchase order number. A writeback entry with when: before calls the system inside the run, before any edit, so the edits can carry what it answered
# ontology.yaml, on the action type
writeback:
- { name: po, system: erp, operation: create-po, when: before,
payload: { supplier: { parameter: order, property: supplier },
total: { parameter: order, property: total } } }
- { system: erp, operation: note-po,
payload: { poNumber: { writeback: po, field: poNumber } } }
rules:
- modify: { object: { parameter: order },
set: { poNumber: { writeback: po, field: poNumber }, status: Ordered } }
- The outputs are the operand
{ writeback: <name>, field: <output> }in rules, notifications and later writeback entries, and{{ writeback.<name>.<output> }}in templates. Conditions can't read them - If the call fails, nothing is edited and the person sees the system's message as
WRITEBACK_FAILED: 422 when the system refused it, 503 and retryable when it was unavailable or too slow, 502 otherwise. A temporary failure is first retried in place, once by default (retries), waitingRetry-Afteror at most 5 s - The call is made after a first check of the parameters and conditions and before the final check, so a slow system doesn't hold up other actions. The run then checks again and commits. Runs with such an entry on one object take turns, so a double submit makes one call
- If the run fails after the call, the call is undone through its operation's
undo, with the outbox retries. A call with no undo is named in the error asNOT_UNDONEand audited aswriteback.before.undone, for a person to put right - Calls made before the edits are recorded in the outbox as delivered rows with the run's commit, so the log's writeback status and an undo see them
- A dry run, a check and a proposal make no calls; their writeback operands read as null
Systems of record
Delivered on request. The Ontology does not replace the systems that run the operation. For each property you can name the system of record that owns it. The ERP owns a delivery's planned arrival and route, the warehouse system owns pick wave assignments, and the Ontology owns things that exist nowhere else, such as a delivery's expected arrival after bridge and weather advisories. When an action edits a property owned by another system, it must declare a writeback for it, and the Ontology registry refuses to save an action type that does not
The outbox
When an action commits, the same commit that writes its edits and its action log entry also writes one outbox row per writeback target. There is no moment at which edits are committed and writeback is forgotten, and no moment at which writeback has started for edits that were rolled back. The writeback service reads the outbox and does the delivery
Each outbox row in ops.writeback_outbox
| Column | Meaning |
|---|---|
outbox_id | Id of the row, for example wb_01JB2Q8M4T7N0XK5… |
log_id | The apply that produced it |
system, operation | Where and how to deliver, such as maintenance and set-aircraft-status |
payload | The fields to write, rendered at commit from the committed values |
idempotency_key | Stable across every attempt |
status, attempts, last_error | Delivery state: pending, delivering, retrying, delivered, dead_letter or cancelled, for writeback an undo stopped |
claimed_by, claimed_at | The copy of the service delivering the row now, and since when |
created_at, delivered_at | When the row was queued and delivered |
With several copies of the service, each row is claimed before it is delivered, so one copy sends it. A row whose copy stopped after claiming it is delivered again after 10 minutes. An action whose copy stopped part way through its commit is finished automatically before its writeback goes out. Steps of the platform's own, such as an email it sends, are delivered from the outbox after the commit and retried the same way
On request, each target record's rows are sent strictly in order and different records in parallel. If two actions edit the same delivery a minute apart, the ERP receives the first write before the second, even if the first needs retries
Idempotency keys
Every delivery attempt for one outbox row carries the same idempotency key, a stable key per delivery. Replaying the outbox after a failover produces the same keys, so the target can recognize a repeat however it arrives
# Built today: the same key on every attempt
Idempotency-Key: alog_01JB2Q8KZ3F6W9DT…:maintenance:set-aircraft-status
# On request: a generated key
Idempotency-Key: wb_6G2K9QF3X7M1T8V4B0C5D7E2RA
How the key reaches the target depends on what the target supports. The header is built; the reference field and the handling of append-only targets are delivered on request
- Native idempotency. APIs that accept an
Idempotency-Keyheader get it there, and the target itself discards repeats. Built:idempotencyHeaderon the system or the operation names the header forkind: httpcalls - Reference field. For targets without it, the connector writes the key into a reference field on the record, such as a custom field in the ERP, and uses read-before-write on any retry: it reads the record first, and if the key and the expected values are already there, it marks the row delivered without writing again
- Append-only targets. Targets that create a new record per call and offer neither, such as plain SMTP, are handled as described for email below
Ambiguous outcomes
The hard case is a timeout: the request may or may not have been applied, so retrying blindly can apply it twice and giving up can lose it. A timeout on a kind: http call is temporary and is retried with the same key in the idempotency header, and an operation can name the answer that means the system already had it with unchangedOn. On request, a target with no way to check is sent to a person instead of being retried
Retries
Failures are classified by what a retry could achieve. Built for kind: http operations: a code in retryOn (by default 408, 425, 429, 500, 502, 503 and 504), a timeout or a refused connection is temporary and keeps the row retrying, a code in unchangedOn counts as delivered, and any other answer is permanent and makes the row a dead_letter at once. A raw table operation that fails is retried, and becomes a dead letter after its fifth failed attempt
After the commit, a temporary failure is retried after 30 seconds, then 2, 10 and 30 minutes, and the fifth failure is a dead letter. On request, retries back off with jitter for up to 72 hours
Dead letters
A row that cannot be delivered becomes a dead letter. Dead letters are not a log file. They appear in Data, on the action log entry that produced them, and on the affected object, where the property shows a "Not written to ERP" marker next to its value. Today, a dead letter is an outbox row with status dead_letter, which raises a writeback.failed webhook event, shows in the inbox of the person who ran the action and can be read with SQL
SELECT outbox_id, log_id, system, operation, attempts, last_error, created_at
FROM ops.writeback_outbox
WHERE status = 'dead_letter'
ORDER BY created_at DESC;
On request, a person can retry a dead letter, retry it after refreshing the source record, resolve it by hand or revert the action, and every resolution is recorded in the audit log. Payloads cannot be edited in place, because a changed payload would no longer match the action log entry that explains it. To send something different, revert and apply the action again
Conflict handling
Between the moment a dispatcher reroutes a delivery and the moment writeback reaches the ERP, a transport planner may have changed the same shipment in the ERP directly, and writing the Ontology's value would silently undo their change. On request, before each write the connector checks the target still holds what the action saw, and asks the person who acted when it doesn't
Echoes and provenance
A successful write comes back. The ERP's change capture reports the updated shipment, and the sync service writes a new source version of the delivery. The sync service recognizes the echo, because the values equal the edit or the record carries the idempotency key, and marks the property as confirmed by the source instead of raising a conflict with the edit that caused it. On the object, each edited property moves through four states, visible on hover (on request). Today, the edit clears on the next sync that reports the same value, and the property leaves the object's _edited list
Where guarantees stop
Idempotency and exactly-once delivery are different promises. Idempotency means every attempt for one outbox row carries the same key, so a retry of the same edit is safe whenever the target honours that key. Delivery itself is at least once: the writeback service keeps trying until the target acknowledges or the row is dead-lettered, and it never stops silently. An exactly-once effect in the target follows only when the target or its connector deduplicates on the key, through a native header or a reference field with read-before-write
| Stage | Guarantee | Who owns it |
|---|---|---|
| Commit in the Ontology | All edits, the action log entry and the outbox rows are written atomically, or none of them are | The platform |
| Outbox to connector | Every row is attempted in order per target key, with the same idempotency key, until it is acknowledged or dead-lettered | The platform |
| Connector to target | A repeat is discarded only if the target accepts the key or the connector can read it back before writing | Shared: the connector's mapping and the target's support for keys |
| Accepted but not acknowledged | Retried with the same key. A target that ignores the key may apply it twice, and a target with no way to check is dead-lettered as Ambiguous | Your system |
| After the target acknowledges | No further guarantee. The target's own validation, triggers, jobs and later overwrites are outside the platform | Your system |
| Coming back by change capture | The echo is matched to the edit and marked confirmed, or raised as a conflict | The platform |
Put plainly, the platform's guarantee ends at the target's acknowledgement. If the ERP accepts a planned arrival and a nightly job overwrites it, the Ontology learns about it through change capture like any other source change, but it does not prevent it. Two systems are never updated in one transaction: an action that writes to the ERP and the WMS can leave one delivered and the other retrying or dead-lettered, and the action log entry shows each target's status separately
Examples by system
Calls to a system's own API are built with kind: http, as in calls to a system's API, and each implementation defines the operations for its systems. The conflict checks, reference fields, edge agent routes and SMTP handling in these examples are delivered on request
ERP
The creamery's ERP exposes shipments through an OData API in the cloud. In the built form, the shipment update is an http operation with the idempotency key in a header and the token held by the platform
# systems.yaml
systems:
erp-transport:
name: ERP, transport module
baseUrl: https://erp.example.com/odata/v4/transport
idempotencyHeader: Idempotency-Key
rateLimit: { perSecond: 5 }
operations:
update-shipment:
kind: http
inputs: { shipment: { type: string, required: true },
route: { type: string }, plannedArrival: { type: timestamp } }
method: PATCH
url: "/Shipments('{{ shipment }}')"
headers: { Authorization: { secret: ERP_TRANSPORT_TOKEN, prefix: "Bearer " } }
body: { Route: "{{ route }}", PlannedArrival: "{{ plannedArrival }}" }
# ontology.yaml, on reroute-delivery
writeback:
- { system: erp-transport, operation: update-shipment,
payload: { shipment: { parameter: delivery, property: shipmentNo },
route: { parameter: crossing },
plannedArrival: { parameter: eta } } }
On request, the connector maps each crossing to its ERP route code, uses the ETag for a conditional write, compares fields for conflicts and stores the idempotency key in a custom reference field
Warehouse management system
The cold store's WMS runs on the plant network. Writeback goes outbound from the cloud to the edge agent over mTLS, and the edge agent calls the WMS's local REST API, which supports idempotency keys natively. Wave reassignments are ordered per wave, so moving a pallet to wave 3 and then back to wave 2 always arrives in that order
POST http://wms.plant.local/api/waves/W-1024-03/reassign
Idempotency-Key: wb_3PZ8HN2Q6V0K4X7T1M9C5R2B8D
Content-Type: application/json
{ "pallets": ["PAL-77310", "PAL-77311"], "dock": "D2", "reason": "Ferry reroute DLV-5521" }
When a wholesale order's delivery date changes, the customer is told by email, and that email is a commitment to the customer, so it is sent as writeback with an outbox row rather than as a best-effort notification. Email is append-only: SMTP has no way to ask whether a message was already accepted. The connector sets a deterministic Message-ID built from the idempotency key and stores the relay's queue id on success. If the connection drops after the message body was sent but before the relay answered, the row is marked Ambiguous and dead-lettered for a person to check the relay's log, instead of risking a duplicate to the customer. There is no conflict check, since there is no prior value to compare
| ERP | WMS | ||
|---|---|---|---|
| Path | Cloud connector, OData | Edge agent, local REST | Cloud connector, SMTP relay |
| Idempotency | Reference field and read-before-write | Native header | Deterministic Message-ID, no automatic resend when ambiguous |
| Conflict check | Compared fields and ETag | Wave version | None |
| Order | Per shipment | Per wave | Per order |
Monitoring and limits
Each connector reports writeback_pending, writeback_delivery_seconds (commit to delivered), writeback_attempts_total by outcome and writeback_dead_letters_open, exported with the rest of the platform's metrics (on request). Built today: ms_writeback_outbox{system,status}, the number of outbox rows by system and status, on GET /metrics, every call attempt in ops.call_runs, and monitor rules of kind writeback that open an alert per system, for example on the first dead letter in a day
Built today: 5 attempts per row, a call timeout of 20 s by default and 180 s at most, concurrency and rateLimit per system and operation, chained calls four deep, and call history kept six months. The limits below are delivered on request
| Item | Default |
|---|---|
| Writeback targets per action type | 10 |
| Payload size | 1 MB |
| Retry window | 72 hours from the first attempt |
| Dead letter retention after resolution | 90 days, with the audit record kept for 7 years |
Limitations
- A failed row is retried five times over about 45 minutes, and rate and concurrency limits count every copy of the service together. The conflict check and the dead-letter API are delivered on request. An undo puts back what delivered writeback changed through the operation's
undocall or the stand-in table's undo record; a call with noundois left for a person - Writeback is not transactional across two systems. Each target is delivered on its own, and one can succeed while another fails
- Writeback after the commit cannot roll it back; an entry with
when: beforeruns first, so a refusal leaves nothing edited. A dead letter leaves the Ontology edit in place until someone retries, resolves or reverts it - Exactly-once effect in the target depends on the target honouring the idempotency key or exposing a field the connector can read back
- Dead-letter payloads cannot be edited. To send something different, revert the action and apply it again
- Ordering holds per target key only. Writes to different records in the same system can arrive in any order
- Append-only targets such as email have no conflict check and are never resent automatically after an ambiguous outcome
- A revert queues an inverse write, which the target may reject or which may conflict with changes made there in the meantime