I am helping to model an e-commerce store backend, that also handles shipment processes, returns etc.
We have orders that are coming through API, and should be automatically actioned upon, often after some delay. And order can be temporarily “held” for some minutes, to make sure the user didn’t make a mistake ordering their things. It can be released from “holding” and either split to multiple shipments, merged with other shipments or can be moved to “backorder” status. It can also be a mixture of all above, where an order is held, then released after some minutes, then split, some the split shipments can be merged with others and some may be hold in “backorder” status if we have no items available on hand. When these missing items become available, we need to “release” the shipment, and it can again - be split, merged or even moved to backorder status if only some of the ordered items became available and not others.
If you plot the business logic as a activity chart, it’d look like something like this, but even more complicated:
Now, you can see that there are some chunks of logic that repeat itself, and “released” shipments can enter into the algorithm into other places after some time passes, or some event happens.
What I am struggling to do, is to find a nice way to model this code in a high-level terms, where I’d have developers being able to have a look at the code and understand what’s going on, or what the business logic is.
The closest I got was with Opus, Opus.Pipeline – Opus v0.3.1 but it doesn’t do great with multiple levels of branching - you end up with creating very small “linked” Pipelines that conditionally call other pipelines. It also doesn’t have the built-in means to handle “jumping into a step”, when a timeout, event or a condition is met that the shipment was waiting on to happen. We use Oban and Oban scheduler to handle that.
How do you structure code like that? Are there libraries / frameworks / tools in Elixir ecosystem that’d be helpful, or maybe you know of something like that from other ecosystems for me to have a look at?