Durable execution without an SDK: one money transfer, in plain Java
An AI agent, a sanctions check, a person in the loop and an undo, and not one line that names the engine.
Money must move once, even when machines fail. A transfer that is debited twice, or debited and never sent, is not a bug report; it is a phone call from a customer. That is why durable execution engines exist. Temporal, Restate, DBOS, Azure Durable Functions and AWS Lambda durable functions all promise the same thing: a workflow that survives a crash and continues where it stopped.
They are carefully engineered and widely used. They also ask something of the developer: the workflow is written against the engine's SDK, side effects go into activities or steps, parallel calls are written by hand, and a set of rules about what the workflow code may do lives in the developer's head, because the engine replays that code after a crash.
Cube Root takes a different route. The workflow is plain Java, TypeScript or Python, and a compiler turns it into a graph of durable steps kept in PostgreSQL. Here is what that looks like for one bank transfer.
The flow
import java.util.function.Function;
public class CoreTransfer {
private Function<Transfer, Transcript> riskPrompt; // the AI agent's question
private Function<Transcript, LlmResponse> riskModel; // the model that answers
private Function<LlmResponse, RiskVerdict> readVerdict; // its answer, read as a verdict
private Function<Transfer, ScreeningVerdict> sanctions; // the bank's screening service
private Function<Transfer, String> review; // a person, minutes or hours later
private Function<Transfer, String> debit;
private Function<String, String> send;
public String invoke(Transfer t) {
Transcript question = riskPrompt.apply(t);
LlmResponse answer = riskModel.apply(question);
RiskVerdict risk = readVerdict.apply(answer);
ScreeningVerdict screening = sanctions.apply(t);
String decision = "approved";
if (risk.level().equals("high") || screening.result().equals("hit")) {
decision = review.apply(t);
}
String outcome = "rejected in review";
if (decision.equals("approved")) {
try {
String posting = debit.apply(t);
String sent = send.apply(posting);
outcome = "sent " + sent;
} catch (Exception e) {
outcome = "refused by the rail - the debit is reversed";
}
}
return outcome;
}
}
Each field is a service the flow calls, typed with Java's own Function<what it is sent, what it answers> and asked with
apply. Which model answers the risk question (Claude, Gemini or ChatGPT) is chosen when the flow is deployed, not in the
code.
What the compiler sees
| In the code | What happens when it runs |
|---|---|
riskPrompt, riskModel, readVerdict |
three steps, one after the other: each needs the answer before it |
sanctions.apply(t) |
a step that runs beside the agent's three: it needs only the transfer |
if (risk ... \|\| screening ...) |
waits for both answers, then decides |
review.apply(t) |
the flow waits for a person, for minutes or for days; no thread waits with it |
try { debit ... send ... } |
two steps, in order |
catch (Exception e) |
if the rail refuses, the debit is undone first, then the catch runs |
Nobody wrote "run these two together". The compiler sees that the screening does not read anything the agent produces, so
the two run in parallel. Nobody wrote compensation code either: a try in a flow undoes the steps it finished when it fails,
last first, before its catch runs. Write keep: on the try when what it finished should stand instead.
When a machine dies
Every finished step is a row in PostgreSQL. If the machine running this flow dies after the debit and before the send, the flow continues from the rows: the debit is not run again, the send is. Nothing is replayed to rebuild where the flow was, so the question "is my workflow code deterministic enough to replay?" does not come up while it runs. The compiler checks the flow once, when it is built.
The rows are also the run record. What ran, where, how many tries, how long each call took: it is all in your database, a query away.
What is not in the code
- no workflow class, activity interface or worker registration
- no retry options, timeouts or task queues written into the business logic
- no
Promise.all, futures or async rules for the parallel calls - no compensation code for the undo
The flow still compiles and runs as ordinary Java, and it imports nothing of ours: each call is java.util.function.Function.
Let your language be your SDK: in Java, the JDK is your SDK. Python flows do the same with Callable, TypeScript flows with
a function type. Leaving means keeping your code.
Try it
The transfer above is one of the sample projects in the browser IDE at cube-root.com: open it, right-click and choose View execution graph to see what runs side by side and what waits. Nothing to install.
More: how Cube Root compares with Temporal, AWS Lambda, Azure Durable Functions, Inngest, Restate and DBOS, and questions, in detail on where the steps are, libraries and determinism.
Next in this series: replay or rows, three ways to make code durable.
Next articleReplay or rows: three ways to make code durable