Find Related products on Amazon

Shop on Amazon

Implementing State Machines in PostgreSQL (2017)

Published on: 2025-07-23 01:22:14

Implementing State Machines in PostgreSQL July 27, 2017 Published: Finite-state machine (FSM) is a wonderful model of computation that has many practical applications. One of my favorites is turning business logic into simple FSMs. For example consider the following requirements for an order management system: Orders must not ship before they are paid. Orders can be canceled, but only if they haven’t shipped yet. An order that has already been paid, needs to be refunded after canceling. Informally, turning such a list of requirements into an FSM is simply the process of coming up with: a set of states an order can be in, a set of events, a transition function that maps the combination of each state and event to a new state, and an initial state. In practice this is usually done by drawing up a directed graph that shows how the different states are connected to each other via events: Besides guiding our implementation, these graphs can be very useful for discussions and analysi ... Read full article.