A Field Guide to state-machines — Architecture article on state-machines

A Field Guide to state-machines

Patterns, anti-patterns, and the questions to ask before you commit to a direction. Ends with what we would do differently today.

We used a feature query, a polyfill, and a fallback that shipped the old behaviour. It is unglamorous and it works, and it has survived three major browser releases without incident.

Everything here assumes a single document and a single user. Both assumptions break eventually, and the resulting failures are interesting because they are the same shape as the original problem, only larger.

Start with the smallest thing that could possibly work. Not because it is the final answer, but because it gives you something to measure against, and measuring is how you find out whether the clever version is worth it.

There is a version of this that fits in a blog post and a version that fits in a book. The difference is what happens when it fails. If you cannot describe the failure mode, you do not understand the system well enough to ship it.