Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

Multi-step flows break in two places — here they are

A lead arrives, an approver signs off, a record gets registered. Three steps. The code that moves a record from step to step is usually fine. What breaks first is the part nobody writes down: what happened, in what orde

A lead arrives, an approver signs off, a record gets registered. Three steps. The code that moves a record from step to step is usually fine.

What breaks first is the part nobody writes down: what happened, in what order, and who was allowed to do it. After that, two things fail in production — the transition that runs twice, and the approval that runs under the wrong role.

Break point 1: the transition has no key of its own

Every hand-off between steps needs an identifier that survives a retry. Not the database row id (it does not exist yet), not the timestamp (it changes on retry). Something derived from the business event:

// the same approval, sent twice, must register one record
const key = `${approval.request_id}:${approval.step}:${approval.version}`;

const existing = await db.transitions.findByKey(key);
if (existing) return existing;            // replay, not a second write

await db.transitions.insert({ key, ...approval });
await queue.publish("register", { key });

Without that key, the retry path is the bug path. A queue redelivers after a timeout, a user refreshes the approval screen, a cron re-runs a sweep — and the register step creates the second record. Nobody notices until two teams call the same customer.

The equation worth putting in the runbook:

  • retry without a transition key = two records = a double follow-up call
  • approval without approver_id + decided_at = an approval nobody can attribute
  • register without source_ref = a record that cannot be traced back to the request

Break point 2: the role that approves is not the role that retries

Step-based permission is where multi-step flows quietly diverge from single-step ones. Three separate questions get collapsed into one:

Question Where it is usually answered Where it is actually enforced
Who may see the request? UI list filter query scope
Who may approve? button visibility server-side role check
Who may retry a failed step? nobody decided inherited from the approver

That third row is the one that hurts. In single-step builds, whoever can see the record can usually retry it. In a four-step flow, the person who can retry a failed registration is often an operator who must not be able to approve. If the retry endpoint reuses the approval permission, you have built a way to skip a step.

Test it as permissions, not as UI: call the retry endpoint with an operator token and assert 403, then with an admin token and assert 200 and exactly one new record.

The four rows I would put in the acceptance table

Copy this into your own handover document. It works for three steps or seven.

Hop What must be written Failure if missing
submit → draft request_id, attempt count double submit creates two drafts
draft → approval approver_id, decided_at, reason approval cannot be attributed or replayed safely
approval → register source_ref, idempotency key register runs twice
any step → failed error_code, queue row, retry owner silent loss, ticket closed as "user error"

Fill the "actual" column from a demo or a test environment, not from a promise, and write PASS or FAIL in the last column. "Checked" is not a verdict.

What the scope actually contains

A multi-step build — fixed sequence, roles, notifications, acceptance table — is 5.9M KRW on marketplaces and 6.9M KRW on the studio site, VAT excluded, and the scope table is signed before the first commit. Excluded and quoted separately: historical data migration, a second integration, paid third-party API plans, and monitoring beyond the operator handover session. Included and excluded in one table is the whole point; the split appears later anyway at rates nobody agreed to.

If you want to see the failure modes before paying anyone, there is a free browser app with no sign-up that reproduces this class of problem: resubmit the same request, watch the record count, then force a 503 and watch the queue. The same link has a four-field contact form (workflow, tools, timing, reply email) and answers with a scope table the same day:
https://web.intelliliving.kr?utm_source=devto&utm_medium=organic&utm_campaign=b2b_obsidian&utm_content=dv_03

Which step in your flow has no key — the submission, the approval, or the register? One word is enough, and I will send the matching table row.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.