Menu

Model business workflows as state machines
πŸ“°

Model business workflows as state machines

DEV Community: javaΒ·Ayush SoniΒ·about 8 hours ago
#xhKrUSSl
#devtojava#devto#dev#state#cancelled
Reading 0:00
15s threshold

Orders, refunds, subscriptions, tenants, support tickets, deployments β€” most business entities move through a lifecycle. And a whole category of production bugs comes from that lifecycle being implicit:

A cancelled order gets shipped because the cancel and the ship request arrived 50 ms apart.

A refund is issued twice because two retries both saw status = 'PAID' .

An account stuck in PROVISIONING for a week because a step failed and nothing defined what happens next.

In each case, the states existed only as a string column, and any code path could set any value. The fix is to make the state machine explicit, and to enforce it where concurrency actually happens: in the database.

Step 1: name the states and transitions

Write them down in one place. For an order:

Every arrow is an allowed transition; anything else is a bug.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.