A common use case that occurs is when an aggregate changes from one status to another. The concept of a finite state machine is often used to aid in this: as actions are taken on the aggregate, it transforms into different states. And at each state, the aggregate has a certain set of attributes, and can only perform certain actions. Take the example of an order. A common flow is as follows
- An order is created
- Items are added to the order
- The order is placed
- The order is prepared
- The order is shipped
- The order is delivered
A finite state machine could be used in this example to model the different steps in the process, for instance, an OrderStarted state for step 1-2, an OrderPrepping for step 3-4, and an OrderAwaitingDelivery for steps 5-6. The usefulness of this organization is in how each state is allowed to perform. For instance, items cannot be added to an order that is in the OrderAwaitingDelivery state.
Axon does not support this use case at the present time. From what I have seen, this is typically handled by having a status flag on the aggregate that indicates what state it is in. This results in a very large aggregate, handling a large number of commands, and performing a large number of checks to see if it is in the right state to handle these commands.
It would be greatly beneficial to have this capability in Axon. In my research, I came across this example. However, the example works by creating new aggregates as it advances to the next state. This is not a finite state machine in its truest form. For it to be truly finite state, the aggregate must itself transform into different states. It must involve a single aggregate, rather than creating separate ones for each step in the process.
I would be interested to hear the teams take on this. I understand there are some barriers to getting this to work, but I think it would allow for much cleaner organization of aggregates.