This is not going to be a tutorial on how to write a state machine in code. There are lots of great libraries that handle the heavy lifting for you. We’re going to talk about how to identify the state machine that’s already present in your business (even if you don’t realize it), and how to model it in a way that you could plug it into code.
“a device that can be in one of a set number of stable conditions depending on its previous condition and on the present values of its inputs.”
What does that mean in real life? A state machine can be used to model any entity in your business that changes states over the course of its life. Here’s a simple example: There’s a telephone sitting on the desk. Its state is “hung up”. The telephone company can transition that phone to “ringing”. The person in the room can “pick up the phone” in either of these cases, but in the first case, it transitions to “dial tone”, and in the second, it transitions to “answered”.
Here’s a visual example that we’re more likely to see implemented in code:
What value does a state machine bring? First of all, it allows you to get a proper understanding of the business process being defined. The examples given are both fairly simple. Here’s a diagram of the state machine from a recent project.
This may seem overly confusing, but the reason for that is it’s not a straight progression from one state to the next. There’s a variety of events that can happen at multiple points in the process. If we re-look at the eCommerce diagram, you might notice some things that are missing.
Why do you want this complicated state machine diagram above? Your business might be working fine the way they are. The goals of a state machine are to define process flow, and enforce constraints. There are certain actions which can’t be taken at certain points without disrupting flows. Having clearly defined states and process flows allows objective decisions to be made, taking the thought process out of the everyday operation of your business.
Having the state machine diagramed out also allows you to improve your process one step at a time. You can take one state or one transition and optimize your processes around it without disrupting the rest of your system.
You simply start to map it out. This may seem hard at first, but the goal isn’t a perfect first draft. Once you’ve gotten started, you’ll start to identify what you’re missing as you progress through the process.
Your next steps will depend somewhat on your business. If you’ve modeled out a physical process, I love the ball of string validation.
State machines are well defined constructs in most programming languages. Beyond defining your states and transitions, you can add code which triggers each time the state transitions to handle any side effects that happen with that transaction (notification emails, etc). Every company and industry has the ability to improve a process with software so you can scale more effectively.
If you’ve got a complex business process like this, Headway can help. We can work with you to define your processes and see how a if a digital product can be built to help your company save time, reduce your costs, and keep growing.
See all the ways we can help you grow through design, development, marketing, and more.
A podcast about building successful software. We provide actionable advice around product validation, execution, and promotion.
A show where we go behind the scenes on what it really takes to bring a new product to market.
Receive the latest articles, resources, events, and more!