state machine
A model in which something is always in exactly one named state, such as idle, loading, success or error, and only defined events move it to another.
In more detail
Writing the allowed transitions explicitly rules out impossible combinations, such as loading and error at the same time, that separate true-or-false flags allow. A dialog, for example, is closed, opening, open or closing. User interfaces, workflows and network protocols are commonly modelled this way.
Examples
In AWS: A defined set of steps and transitions that coordinates a multi-step process, as AWS Step Functions does for AWS services.In the browser: The HTML tokenizer is a state machine, and so is the service worker lifecycle, which moves from installing to installed to activated. Modelling behaviour this way makes it predictable: you can list every state and every allowed transition.A circuit breaker moves between Closed, Open and Half-Open.Related terms
- AWS Lambda — The AWS service that runs a piece of code, called a function, each time an event arrives, with no servers for you to manage.
- Lambda handler — The function in your code that Lambda calls for each event, receiving the event and a context object.
- Zag — A library of framework-agnostic UI component logic written as state machines, used by Ark UI and others.
- headless component — A component that provides behaviour, state and accessibility but no styling, leaving the look entirely to the consumer.
- race condition — A bug whose outcome depends on the timing of two things happening at once.
- async and await — Language keywords for writing code that waits for slow work, such as a network call, without blocking a thread.
- iterator — An object that produces the items of a sequence one at a time, on request, instead of all at once.
- continuation — The rest of a method that is scheduled to run once an awaited task completes.
- HTML tokenization — The parsing step that splits a stream of characters into meaningful pieces called tokens, such as a start tag, an end tag or a run of text.
- service worker lifecycle — The states a service worker passes through: installing, installed and waiting, activating, activated, and finally redundant when replaced or failed.
- circuit breaker — A wrapper around calls to another service that stops making calls for a while after repeated failures, so the failing service can recover.
- reducer — A pure function that takes the current state and an action and returns the next state.
- discriminated union — A type made of several object shapes that share one literal field, such as status or type, whose value tells them apart.
- Boolean — A value that can only be true or false.
- mass assignment — A bug where a handler copies every field of a request body into a data model, so a caller can set fields such as role or balance that were never meant to be writable.
- seat hold — A temporary reservation of a seat while a buyer checks out, released if they do not pay in time.
- make illegal states unrepresentable — A design rule: shape your types so that invalid combinations, such as loading and error at once, cannot even be written.
Taught in
- Four Hundred Missing Labels — AWS Certified Cloud Practitioner (CLF-C02) Exam Prep
- Technology Sprint: The Design Review — AWS Certified Cloud Practitioner (CLF-C02) Exam Prep
- Confusable Services Sprint: One Clue Each — AWS Certified Cloud Practitioner (CLF-C02) Exam Prep
- EventBridge Rules: The Rule That Matched Nothing — AWS Certified DevOps Engineer – Professional (DOP-C02) Exam Prep
- Serverless Compute (Lambda) — Cloud Infrastructure & Hyperscaler Architecture
- Headless Architecture: State vs Presentation Separation — Design Systems & Component Engineering
- Collections, Generics, and LINQ — Modern .NET Core, C# & Enterprise Microservices
- Async and Await: Managing Concurrency — Modern .NET Core, C# & Enterprise Microservices
- HTML Parsing, Tokenization And The Document Object Model (DOM) — Frontend Architecture & Web Platform
- Service Worker Lifecycle: Installation, Activation And Update — Frontend Architecture & Web Platform
- Resilience Engineering: Circuit Breakers & Retries — Production Full-Stack Engineering
- State with useState: Immutability And Asynchronous Batching — React 19 & Modern Component Architecture
- Complex State with useReducer: State Machines And Action Types — React 19 & Modern Component Architecture
- Slot Patterns And Headless UI Architecture in React — React 19 & Modern Component Architecture
- useTransition: Non-Blocking State Updates for Fluid UI — React 19 & Modern Component Architecture
- useOptimistic: Instantaneous UI Updates with Rollback — React 19 & Modern Component Architecture
- Mass Assignment — Application Security & Threat Modeling for Engineers
- Circuit Breakers — Scalable System Design & Distributed Architecture
- never: The Bottom Type And Exhaustive Switch Checking — Production TypeScript
- Discriminated Unions: Tagged Variants And Pattern Matching — Production TypeScript
- Const Type Parameters: Retaining Literal Types In Functions — Production TypeScript
- The Spine Artifact: Generating Typed Models From OpenAPI — Production TypeScript
References
- What is Step Functions?
- Statecharts: what is a state machine?
- Asynchronous programming scenarios
- HTML Standard: Tokenization
- Stately: State machines and statecharts
- React: Avoid contradictions in state
- W3C: State Chart XML (SCXML)
- NIST DADS: finite state machine
- MDN Web Docs glossary: State machine
- TypeScript Handbook: Narrowing