Skip to main content

Advanced Step Guarantees

View as Markdown

Read this page once Steps run in parallel, take a long time, or use ASYNC durability. Step covers the guarantees every Step has.

What Dex saves

In short: a method's writes are saved together, but they are not isolated from other Steps and RPCs.

Dex saves each WaitFor or Execute call on its own. It saves the call's Attribute writes and Channel publications together with its result, and only when the method succeeds. Calls to external systems are not part of this save.

A method reads the state as of dispatch; Dex does not recheck it at commit. Two methods that read then write one Attribute must both lock it. See Attribute locks.

State snapshot

A method's state snapshot is the Flow state that Dex passes to it: every ordinary Attribute, the size of every Channel, and the AttributeMap values and pending Channel messages that its StepOptions select. Dex takes it when it hands attempt 1 to a Worker. A retry of Execute reuses that snapshot, so it does not see Attribute writes made since then. To wait for such a write, have the writer publish a Channel message, and wait for it in the next Step's WaitFor. Hard-delete Attributes are the exception: Dex reads them again on every attempt. See Storing credentials.

A Step also keeps its declared locks through retry backoff and while a retry waits for a Worker. RPCs that need one of those keys can exhaust their lock wait before the retry runs.

Failure and redelivery

In short: when a method's outcome is uncertain, Dex runs the method again or tells you the outcome is unknown.

These cases repeat a method or leave its outcome unknown. They hold for every SDK:

  • A Worker stops in the middle of a method. The attempt fails, and the retry policy runs the method again. Its external calls may already have happened. A server restart or failover does the same to every attempt that a Worker had.
  • Heartbeats are fire-and-forget. A heartbeat checkpoint can be lost, so a rerun can start from an older checkpoint. Key each external effect by a stable ID, never by the checkpoint alone.
  • An ASYNC Step can repeat an attempt. See SYNC and ASYNC Steps.
  • Retries can run out without an answer. The recovery Step then learns that the work certainly did not run (NOT_STARTED) or that it may have run (NOT_COMPLETED). On NOT_COMPLETED, check the target system by the idempotency key before you repeat or report the effect.

Failure and redelivery in the SDK reference gives the exact rules for each case: Python · Go · Java · TypeScript · Rust.

SYNC and ASYNC Steps

A Step's durability chooses when Dex stores its progress.

  • SYNC is the default. A SYNC Step waits for two log commits: the attempt start, before the Worker receives the task, and the result, before the Flow moves on. Each commit is one write to object storage. Dex groups the commands that are ready at the same moment into one commit, so a commit can carry the work of many Flows.
  • ASYNC lets the Worker receive the task before Dex saves the attempt's start and lets the Flow move on before Dex saves the result. If a Dex Server node fails before the attempt start is saved, Dex can run the same attempt number again on a new state snapshot, so it can read different Attribute values. If the start was saved and its result was lost, an interrupted attempt can consume a retry, and a method retry reuses the ordinary snapshot. Keep ASYNC methods idempotent. See the default for commit.batchWindow.
  • A lost ASYNC result reruns later work only up to the first SYNC Step. Dex writes a Flow's commands to its log in order. Once a SYNC Step's start is stored, every earlier command of that Flow is stored too, so a SYNC Step that a Worker has received does not run again because of a lost ASYNC result.

Choose SYNC for effects that need the tightest guarantees. Choose ASYNC for short Steps where latency matters and a rare rerun is acceptable. Good ASYNC candidates are fast reads, internal bookkeeping, and calls that a key already makes safe to repeat. Keep SYNC for a payment, an email, or any call whose rerun on a newer snapshot could send different arguments. A StepOptions setting picks the durability of one Step, and FlowConfig sets it for a whole Flow. Performance gives measured latency for both.

Cancellation, completion, and order

Canceling a Step discards everything its current method has not saved: its Attribute writes, its Channel publications, and its decision. What its WaitFor already saved stays. A decision or an RPC never cancels the Steps that it starts itself. Canceled Steps return consumed messages says what happens to the messages a canceled Step consumed.

A canceled method's code keeps running until the method returns, and its external calls still take effect. The method should check for cancellation and return. See Step cancellation.

A canceled Step publishes nothing, and its failure route does not run. The Step or RPC that cancels it cannot publish on its behalf either. Dex decides which Steps to cancel only when it saves the result that cancels them. By then the canceled Step may already have published. So do not cancel a Step whose publications other Steps depend on, such as the token holder in a Critical Section. To stop such a Step early, send it a stop request that it checks, such as an Attribute that an RPC sets.

GracefulComplete ends its own branch and asks Dex to complete the Flow once no Step is active. The request stays in force: a later branch that ends with DeadEnd does not withdraw it. See Completion requests.

A Flow with no active Step keeps running until a GracefulComplete is pending, and an RPC can still start new Steps in it. End the last branch with a completing decision. If a Flow must not wait forever, set a Flow timeout.

Dex starts ready Steps roughly in the order they became ready, but not strictly. Do not rely on the order in which parallel Steps start or finish. Use a Channel or an Attribute lock when the order matters.

Next