---
title: "Discussion on \"State of Affairs: Why Your Code Needs Finite State Machines\" | Hashnode"
description: "Discussion on \"State of Affairs: Why Your Code Needs Finite State Machines\". Learn what finite state machines are and how to use them to write cleaner code, build reliable web scrapers, and control autonomous AI agents."
url: "https://hashnode.com/posts/state-of-affairs-why-your-code-needs-finite-state-machines/6a392140b1e500eacf5b3f81"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [State of Affairs: Why Your Code Needs Finite State Machines](https://bitsofwisdom.hashnode.dev/state-of-affairs-why-your-code-needs-finite-state-machines?utm_source=hashnode&utm_medium=feed)

Learn what finite state machines are and how to use them to write cleaner code, build reliable web scrapers, and control autonomous AI agents.

Jun 22 · 7 min read · bitsofwisdom.hashnode.dev  
Read the article

-   [#system-design](https://hashnode.com/tag/system-design)
-   [#ai-agents](https://hashnode.com/tag/ai-agents)
-   [#architecture-design](https://hashnode.com/tag/architecture-design)
-   [#web-scraping](https://hashnode.com/tag/web-scraping)
-   [#finite-state-machine](https://hashnode.com/tag/finite-state-machine)

## Written by

[Matthew Wisdom](https://hashnode.com/@matt-wisdom)

@matt-wisdom · Nigeria

  
[View profile](https://hashnode.com/@matt-wisdom)

Backend and AI Engineer

I write about anything in the tech space

## Responses 2

Markdown supported · ⌘↵ to post

[OnlineProxy](https://hashnode.com/@onlineproxyio)

[Jun 27](https://hashnode.com/posts/state-of-affairs-why-your-code-needs-finite-state-machines/6a392140b1e500eacf5b3f81/comment/6a3ffe745eb239a47e0e6480)

Your teaching example is solid, but when you're actually scraping in the wild, you gotta add guards to keep bad retries from sneaking through, plus entry and exit hooks so your side effects don't end up scattered all over your codebase like socks after laundry. And here's the thing -- FSMs are great at blocking impossible state combos, but if you're running distributed scrapers across multiple workers, you need idempotency keys and locks to handle timing weirdness. And when you save state after a crash, don't just store the state name - grab a timestamp too, because resuming a backoff timer from 24 hours ago is the kind of silent bug that'll haunt your logs. Once you're past prototype stage, libraries like transitions Python or XState JS basically pay for themselves with built-in visualization and guard support. Overal, this should help people actually see the FSMs they're already building and start being intentional about it

[Matthew Wisdom](https://hashnode.com/@matt-wisdom)

[Jun 27](https://hashnode.com/posts/state-of-affairs-why-your-code-needs-finite-state-machines/6a392140b1e500eacf5b3f81/comment/6a3ffe745eb239a47e0e6480#reply-6a4036d12fe9d00471f3a60e)

Yes, Thank you. This isn't meant to be a full architectural guide. Its like you said, to help people be more intentional about architectural decisions. Thats very important now more than ever 😀
