3 ms·
I worked at a business (in ruby) where the entire core logic of the app was a state machine, as an idea the thought was good, a state machine modeled order flow
by ianbutler 4y ago
I worked at a business (in ruby) where the entire core logic of the app was a state machine, as an idea the thought was good, a state machine modeled order flows pretty well, but in practice it was very slow and the amount of side effects that had to be considered as the business grew just compounded this.
It got to the point where this state machine approach was a real bottleneck and though I left before it was resolved last I heard they had to put real engineering time in to move off of it.
Be very careful when deciding to go this route.
- duffyjp 4y agoOn the flip side, I've built several production apps with AASM or Workflow that made adapting to changing business logic a breeze. If you're given a flow-chart you can translate that 1-1 and when that chart changes it's easy to adjust. It was also really easy to write tests for.
- SaltyBackendGuy 4y agoThis has been my experience as well with AWS Step Functions. Obviously your use case is critical to the architecture decision. For us it's made automating workflows a breeze.
- ianbutler 4y agoFor sure, this isn't an indictment against state machines, my message was exactly to be careful when making the decision to use them. They fit a lot of workflows and I've also worked in environments where they were not at all a bottlenecks, and regardless of the performance bottleneck it wasn't hard to reason about or adjust which for a long time meant more than performance for that business. I guess I could amend my statement to "be careful about which library or implementation of a state machine you go with"
- krainboltgreene 4y ago> but in practice it was very slow How in the world is updating a column from "in cart" to "purchased" to "complete" slow? There are only three things a state machine has to do: 1. Determine if the event can happen 2. Set the record to the new state 3. Call lifecycle hooks None of that should be "very slow".