Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a workflow engine, state machine engine or rolling my own?

I'm confused. I'm developing a grails based internal tool for my company. One component in this tool is a simple issue tracker (a Helpdesk feature). I have domain objects such as Problem, Question and NewFeature. Each of these domain classes have different workflows.

My initial idea was to roll my own state machine functionality inside the domain objects. I then googled for state machine engines and workflow engines. And now I'm lost.

I would like to have comments how other developers have solved this problem. Do you use Drools, Jbpm, Activiti? Or some simpler state machine engine?

I have been reading some documentation for the Drools, Jbpm. They look very nice. But it seems like I only need a small part of the features these libraries provide.

I'm using Grails for this but it's of course easy to use Java libraries as well.

like image 403
Henrik Avatar asked Aug 17 '12 07:08

Henrik


People also ask

What is the difference between a rule engine and workflow engine?

Main differences between a rule engine and a workflow engine, is that rule engine does not track the state of the transaction, it should be stateless working only on the inputs you provide it. Workflow engine is statefull, it must know what current state is the workflow in and must save that state to a database.

What is the difference between workflow engine and state machine?

In other words, state machine is event driven and workflow engine is not. When trying to figure out which of the two systems to implement, it is necessary to analyze some of their major features.

How does a workflow engine work?

A workflow engine operates by automating, or task routing, a workflow input by the user. The engine tracks tasks and notifies users as they are completed with information regarding next steps.

Can a workflow engine change the state of multiple resources?

I have seen many examples where a workflow engine changes the state of multiple resources some of them guarded by state machines.


2 Answers

The main value of a Workflow engine is that it makes it possible to customize the flows through some workflow definition DSL. If you don't need to allow users to define their own arbitrary workflows, they you are better off just building your own.

Also workflow engines usually give you the ability to define business transactions & rules that are very long running. For example, you can have a workflow for authorizing purchase orders, where the first step is to enter some information about what needs to be purchased, then you have rules along the lines if the purchase is for less $100 okay it right away, if its between $100 & $2000 line manager can okay, if it's more then send it to some one else for approval ... etc. These types of business rules tend to change over the years as the amounts get increased, or the business policies for a company change. So it makes sense to use a workflow engine in those scenarios. Other good examples of complex business transactions that can benefit from a workflow engine are making an insurance claim, authorizing a loan or a mortgage, assessing a credit application from a customer ... etc. These business transactions tend to go through several people / departments and take several hours to days or weeks to complete.

Rule engines are good for extracting complex but changing rules from an application. Lets say you are an online retailer that ships to customer in the USA, Canada, UK, Germany, and France. You are required to charge taxes on the products you sell on your online shop but the rules for calculating taxes are different from country to country and from province to province within a country. Also some things are exempt from tax in one province but not in other provinces. Rule engines are great for these types of complex business rules that can change whenever the government changes their tax policy. Rules engines can give you an answer right way you just have to go to the rule engine say I want to run rule #10 and here are the inputs for rule #10 x,y,z and you get back an answer.

Main differences between a rule engine and a workflow engine, is that rule engine does not track the state of the transaction, it should be stateless working only on the inputs you provide it. Workflow engine is statefull, it must know what current state is the workflow in and must save that state to a database. Workflow engines also wait for input from external sources such as people or systems.

From what you are describing about your app I would just write some groovy classes to compute the next state of a ticket and make sure that the class is well documented and easy to update in a few years. I think rule engines and workflow engines are overkill for your situation, the amount of time it would take you to set them up and use them is much bigger that it would take you to write the code in groovy. If over time you discover you need the complexity of rule engines and workflow engines, I would pay the price then rather than now, keeping it simple is always the best choice.

like image 93
ams Avatar answered Sep 29 '22 18:09

ams


I can't agree more with above AMS' answer, and one more thing i want to add is for most scenarios, using workflow/rule engine is overkill and unnecessary. KISS(Keep It Simple and Stupid)is always the best choice. and Occam's Razor also says "Entities should not be multiplied unnecessarily"

Per my own working experience in Alibaba, most workflow/rule-engine equipped applications are putting the maintainance into nightmare, and people comes to project later will appreciate you if you use simplified impl rather than blindly choose workflow/rule engine.

So, is there a guideline telling when to use workflow or not? frankly i don't know, but what i know is it's definitely not we should use workflow whenever the biz logic is in a flow. because if you will, every biz logic can be presented in a flow chart.

Lastly, one of my most correct thing i did last year is redesign an application to replace Drools by groovy script, which makes the whole system much more straightforward, simpler and faster.

like image 22
Frank Zhang Avatar answered Sep 29 '22 19:09

Frank Zhang