How Temporal and AWS Step Functions compare for long-running backend workflows: code versus state machine definitions, execution limits, retries, history, local testing and hosting, and when a simple queue and a state table is enough.

Both tools solve the same problem: a business process that takes many steps, may take days, and must survive crashes, retries and deploys without losing its place. Where they differ is how you describe the process and who runs the machinery underneath.
Step Functions is a managed AWS service driven by JSON state machines. Temporal is a workflow engine where the definition is code.
A Temporal workflow is a function, so loops, branches, try blocks and timers are the language's own, and the engine records each step in an event history so it can replay the function after a crash and resume at the same point. The constraint is determinism: workflow code must not read the clock or random numbers directly, and long histories have to be split with Continue-As-New. The Temporal workflow docs cover the model.
Step Functions defines the same process as a state machine in JSON, with task, choice, wait, parallel and map states. Direct integrations with services such as Lambda, SQS and DynamoDB mean many flows need no glue code, and the visual execution view helps with debugging. The cost is a definition language that gets verbose for complex logic.
The Step Functions quotas give Standard workflows a one-year maximum and a 25,000-event history, which a loop over thousands of items can reach, and the usual workaround is to start new executions or use a distributed map. Express workflows stop at five minutes, and they are better for high-volume, short, idempotent work. The workflow type guide explains the exactly-once model for Standard and at-least-once for Express.
Temporal terminates an execution above 51,200 events, so long-lived or loop-heavy workflows call Continue-As-New periodically to carry state into a fresh execution.
Pick Step Functions when the flow is mostly orchestrating AWS services, your team is already on AWS, and you want no servers to run. Pick Temporal when the logic is complex, you want to unit test workflows as code, you need cloud portability, or you are comfortable running the server or paying for the managed service. Both add a concept to learn, so neither is a free upgrade over a queue and a table.
Many multi-step flows are a handful of steps, each safe to repeat, with a status column. A topic carrying the next step, idempotent subscribers and a state table cover order fulfillment, onboarding and report generation without a workflow engine. Reach for Temporal or Step Functions when you need durable timers over days, human approval steps, large fan-out with aggregation or compensation across many services.
Encore brings infrastructure from code, and for the simple case the whole flow is declared in the application: a Pub/Sub topic carries the next step, subscribers retry and dead-letter on failure, and a Postgres table holds the current state. For flows that need a workflow engine, Encore documents using Temporal with Encore, so the engine runs alongside services whose infrastructure is still declared in code.

Run in your terminal to get started locally.
// orders/orders.ts
import { api } from "encore.dev/api";
import { SQLDatabase } from "encore.dev/storage/sqldb";
import { Topic, Subscription } from "encore.dev/pubsub";
const db = new SQLDatabase("orders", { migrations: "./migrations" });
type Step = "reserve" | "charge" | "ship";
interface StepMsg {
orderId: string;
step: Step;
}
const steps = new Topic<StepMsg>("order-steps", { deliveryGuarantee: "at-least-once" });
// orders(id TEXT PRIMARY KEY, state TEXT NOT NULL DEFAULT 'new')
export const place = api(
{ expose: true, method: "POST", path: "/orders/:id" },
async ({ id }: { id: string }): Promise<{ state: string }> => {
await db.exec`INSERT INTO orders (id) VALUES (${id}) ON CONFLICT DO NOTHING`;
await steps.publish({ orderId: id, step: "reserve" });
return { state: "new" };
},
);
// Each step moves the order from one state to the next with a conditional update,
// so a repeated message does nothing, then publishes the following step.
const next: Record<Step, { from: string; to: string; then?: Step }> = {
reserve: { from: "new", to: "reserved", then: "charge" },
charge: { from: "reserved", to: "charged", then: "ship" },
ship: { from: "charged", to: "shipped" },
};
const _ = new Subscription(steps, "advance-order", {
retryPolicy: { minBackoff: "10s", maxBackoff: "5m", maxRetries: 8 },
handler: async (msg) => {
const t = next[msg.step];
await doStep(msg.step, msg.orderId); // call the warehouse, payment or carrier; must be repeatable
const moved = await db.queryRow<{ id: string }>`
UPDATE orders SET state = ${t.to} WHERE id = ${msg.orderId} AND state = ${t.from} RETURNING id`;
if (moved && t.then) await steps.publish({ orderId: msg.orderId, step: t.then });
},
});
async function doStep(step: Step, orderId: string): Promise<void> {
// Use idempotency keys such as `${step}-${orderId}` with every external call.
}
encore run starts a local Postgres and runs the topic and subscription in process, so the whole flow can be tested end to end. Messages that exhaust their retries land in a dead-letter queue for the subscription. On deploy, the topic runs on SNS and SQS or GCP Pub/Sub in your own account as the AWS infrastructure docs describe, and a coding agent that adds a step edits the map, the handler and the test together.
Best fit: Teams whose flows are a few repeatable steps and who want them in application code before taking on a workflow engine.
Temporal workflows are ordinary code in a language such as Go or TypeScript, replayed deterministically from an event history, and you can self-host the open source server or use a managed service. Step Functions workflows are state machines defined in Amazon States Language and run only on AWS, tightly integrated with AWS services.
Standard workflows can run for up to one year and are limited to 25,000 events in the execution history, and they follow an exactly-once model for states unless you add retries. Express workflows run for up to five minutes and use an at-least-once model.
A workflow execution is terminated when its event history exceeds 51,200 events, and warnings begin at 10,240. The usual answer is Continue-As-New, which closes the current execution and starts a fresh one carrying the state forward.
Yes. For many flows with Encore, a sequence of steps can be a Pub/Sub topic, idempotent subscribers and a Postgres table for the current state, all declared in application code. For long timers, human approvals and complex compensation, Encore documents how to use Temporal alongside it.
Deploy to your cloud on AWS and Google Cloud
without managing infrastructure
Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.