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 .…