I was re-learning about state diagrams this weekend, and realized that I may have been using them for years without realizing it.

Suppose i have an order record, with a bunch of fields including status, start date, end date, customer name, address, name, etc.

The status field has different states, and needs a transition to change states. When I look at the record in the context of that one field, I get that my order record is a state machine.

So here's my question- there are hundreds of fields on my record. does that mean my 1 order record contains many state machines? If so, then what, and does it lose it's power?


Confused Developer

  • Oh my. Hundreds of fields on a record. I understand why you're Confused. :) That being said, one record may or may not contain different state machines, if this record is currently saving the state of several workflows.
    – Machado
    Commented Sep 18, 2017 at 14:30

1 Answer 1


Well, for starters, let's take aside discussions about whether it's a good or a bad practice saving different states on a single record, because that would be off topic.

That being said, consider this example:

A user enters a e-commerce website and buys 1 item. A can of beer, for example.

This can of beer has to be paid, packaged and delivered. There are 3 different workflows involved.

Of course your could say that this consider a state machine, with the order containing 4 states:

Waiting Payment -> Paid (Waiting Packaging) -> Packed (Waiting Deliverance) -> Delivered

But each state has an inner workflow. Waiting Payment may involve actually sending the payment request to a credit card company, waiting return, rejected payments from the CC company, changing methods, etc...

Waiting Packaging means you may have to request transfers of that item from one storage location to another, approvals from different personnel, and on until someone (or something) puts a box around the can of beer, prints a label with the customer name and address and actually makes the box available for the logistics guys deliver the package.

Packed means someone has to actually sign off that the package was picked up at the storage location, place on a truck or plane, get a tracking number, etc...

Get the idea ?

Everything can be tracked within a single record, specially one with hundreds of fields. It doesn't mean it should be like this, but your business reality will tell what would be the optimal solution.

So, wrapping up:

"Does that mean my 1 order record contains many state machines?"

In the example above, yes. One state for each workflow.

"If so, then what, and does it lose it's power?"

I don't understand what do you mean by "lose it's power", but certainly storing different workflows under a single record may make your life harder as a developer, due to mixing different domains without proper boundary definition among them.

  • thanks for you answer- I have sooo many questions!!! In your example above, you talk about inner workflows between states, and that captures a similar situation of what i'm working with. Can you point me to an example on how you'd document that visually? I'm using state diagram similar to this and labeling the workflows, as transitions. It makes the diagram easier to understand, but doesn't capture the sub-states of those inner workflows. ...developer.atlassian.com/jiradev/files/23299083/23134555/1/… Commented Sep 18, 2017 at 15:26
  • I'd document it as 3 different processes. They are different problem domains, which requires different documentation, depth of analysis, etc... in DDD terms they'd be different bounded contexts, which happen to be persisted in the same table/record.
    – Machado
    Commented Sep 18, 2017 at 18:05
  • And in each specific state diagram I'd put the necessary details about the events that change the states. Some state changes on one diagram may trigger events on another diagram. Keeping consistent naming among them, and placing strategic notes on each diagram may be a good way to document how they talk to each other.
    – Machado
    Commented Sep 18, 2017 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.