# Effective state machines for complex logic by David Khourshid (Effect Days 2024)

> For agents: start with the [agent guide](https://ratstack.sh/llms.txt). Every page is Markdown by default; add `Accept: text/html` for HTML.

[Effect | TypeScript for the AI Era](https://www.youtube.com/@effect-ts) · Published 2024-05-14 · 30:05 · A tier · XState and state machines

[Watch on YouTube](https://www.youtube.com/watch?v=mZJxGgI7FXU) · [All RatTube videos](/tube)

## Summary

David Khourshid connects [state machines](/lore/lifecycles-are-machines) with [requirements](/lore/ui-behaviour-is-a-scene) written as given, when, and then. Invoked actors live for the lifetime of a state and can report results back, unlike fire-and-forget actions.

The talk explores actors built from promises or transitions and demonstrates a drink machine whose actors exchange messages. A sequence diagram makes those exchanges visible. Khourshid closes by discussing how [Effect](/lore/effect-basics) could execute the machine and supply runtime features.

## Section notes

- [5:13](https://www.youtube.com/watch?v=mZJxGgI7FXU\&t=313s): State transitions map directly to given-when-then requirements.
- [10:35](https://www.youtube.com/watch?v=mZJxGgI7FXU\&t=635s): Invoked actors live within a state's lifetime and communicate back.
- [16:00](https://www.youtube.com/watch?v=mZJxGgI7FXU\&t=960s): Promise and transition logic provide different actor behaviors.
- [21:29](https://www.youtube.com/watch?v=mZJxGgI7FXU\&t=1289s): A drink machine demonstrates actor communication and its sequence diagram.
- [26:59](https://www.youtube.com/watch?v=mZJxGgI7FXU\&t=1619s): Effect can supply execution, observability, and retries around machine logic.

## Key concepts

- [state machines](/lore/lifecycles-are-machines)
- [Effect](/lore/effect-basics)
- [requirements](/lore/ui-behaviour-is-a-scene)

## Our take

David Khourshid on where state machines sit above Effect for workflows, the difference between actions that fire and forget and actors that are live entities, and the actor model he would like to see in Effect. Pairs with the talk above and goes deeper on actors.

## Related videos

- [Effective State Machines with XState | David Khourshid | Effect Miami 2](/tube/effective-state-machines-with-xstate-david)
- [Webinar: State Machines and Actors with XState v5](/tube/state-machines-and-actors-with-xstate)
- [David Khourshid: Simplifying Complex UIs with Finite Automata & Statecharts | JSConf Iceland 2018](/tube/simplifying-complex-uis-with-statecharts)
- [Production-Grade TypeScript by Johannes Schickling (Effect Days 2024)](/tube/production-grade-typescript-by-johannes-schickling)

Summary based on the transcript. Written 2026-11-15.
