AI Engineering

Workflow patterns

The five canonical patterns side by side on the same task, with calls, latency, cost and failure behaviour — plus durable execution with a crash halfway.

Real vs simulated: Calls are simulated with the illustrative tiers; the crash/resume logic is real.

Prices and speeds: small $0.25/$2, mid $1/$5, large $3/$15 per M tokens (illustrative).

PatternModel callsLatencyCost / ticket
16.1 s$0.0127
36.3 s$0.0060
23.5 s$0.0049
45.9 s$0.0066
515 s$0.0266
3.17.1 s$0.0077
510 s$0.0292

Routing

RouterEasy → small model 70%Hard → large model 30%

Use it when: Distinct request types with different best handlers — or easy vs hard traffic.

How it breaks: Misroutes: a hard ticket sent to the small model gets a confident weak answer. Measure router accuracy.

Durable execution: crash halfway

#1 Fetch the ticket
#1 Classify and draft (model)
#1 Refund €30 (payments API)
💥 worker crashed after the call, before saving the checkpoint — job redelivered
#2 Fetch the ticket
#2 Classify and draft (model)
#2 Refund €30 (payments API) — DONE AGAIN
#2 Email the customer
#2 Close the ticket

What the outside world saw

  • ×2 Refund €30
  • ×1 Email sent
  • ×1 Ticket closed

Without checkpoints the redelivered job starts over and repeats side effects. Checkpoints resume from the last saved step — but the step that was in flight when the worker died runs again, so it must be idempotent. Durable-execution engines (Temporal, Step Functions, LangGraph checkpointers) give you the first; only your API design gives you the second.