I’ve spent many years doing BPMN development. In general, I think its incredibly useful technology. However, for a few reasons, I hate creating process models visually. Basically, it is a form of visual programming which I’ve never liked.
Here’s a highly simplified process model for securing a loan:
Each rectangle is a service task. Assume each service task instance is queued to a pool of workers. A worker picks up the task, retrieves the necessary inputs from the process state, executes the necessary logic and finally inserts the necessary outputs into the process state.
When a task completes, a process engine uses the process model to determine the next service task to instantiate.
If you were to translate the process model into code it might look something like:
defProcess process_loan_application do
perform_fraud_check()
if (fraud_is_suspected()) do
deny_loan()
else
perform_credit_check()
if (credit_is_ok()) do
setup_loan()
else
deny_loan()
end
end
end
Everything that looks like a function call is really a service request queued to a pool of workers.
Personally, I think the code is just as readable as the diagram and doesn’t suffer from the things I don’t like about visual programming.
So, why am I posting this? My Elixir experience is limited to two years of Elixir/Phoenix/LiveView development, so I have only the vaguest idea on how this might be implemented. I’m guessing there would be macros for writing the process models and genservers for executing process instances.
I am considering starting an open source project for this. If you have managed to get this far, does anyone have any design suggestions?
I prefer to use with instead of nested if.
perform_fraud_check() and perform_credit_check should return something, thus You would not need to use additional check.
defProcess process_loan_application do
with perform_fraud_check(),
perform_credit_check() do
setup_loan()
else
_ -> deny_loan()
end
end
Your code is more succinct. The tricky thing is that the code will not get executed normally. Instead, it will be translated into a data structure which would get pushed into a store of some sort. Then, when a process model is instantiated, the process model data structure would be used by a server to guide service task instantiation.
The more Elixir syntax you bring into the process model, to more you have to translate into the resulting persisted data structure.
If you want to get a little more low-level, BPM can also be modeled with state-machines. Erlang and Elixir have a few libraries, but I don’t know what is the most used ones now.
I wonder if you were able to create a DSL with macros or otherwise whether you could also autogenerate a BPMN diagram as well as generating the rules model itself.