I found various libraries in C#, PHP, Python, etc. for workflows. By workflow I mean something like an employee wants personal time and that request starts with the employee and finishes in some repository after approved/disapproved. (Very small example. In reality it is much larger.)

In my question I know I can enter data and steps only in the database, if I like. My question is if I do, what are these libraries doing that I can't do by querying the database without them?

BI am not understanding why I would need something other than the database to hold the steps and my current location in the steps. If I need to engineer my system, why use these libraries?

Please note, I am not asking if I need a workflow, only which design choice I should make and why.

Example in C#, https://github.com/danielgerlag/workflow-core/tree/master/src/samples/WorkflowCore.Sample03

            .StartWith(context =>
                Console.WriteLine("Starting workflow...");
                return ExecutionResult.Next();
                .Input(step => step.Input1, data => data.Value1)
                .Input(step => step.Input2, data => data.Value2)
                .Output(data => data.Value3, step => step.Output)
                .Name("Print custom message")
                .Input(step => step.Message, data => "The answer is " + data.Value3.ToString())
            .Then(context =>
                    Console.WriteLine("Workflow comeplete");
                    return ExecutionResult.Next();

Or a state machine in C#, https://github.com/dotnet-state-machine/stateless

    .OnEntry(() => StartCallTimer())
    .OnExit(() => StopCallTimer())
    .Permit(Trigger.LeftMessage, State.OffHook)
    .Permit(Trigger.PlacedOnHold, State.OnHold);

Or PHP Symfony, https://symfony.com/doc/current/components/workflow.html

$definition = $definitionBuilder->addPlaces(['draft', 'review', 'rejected', 'published'])
    // Transitions are defined with a unique name, an origin place and a destination place
    ->addTransition(new Transition('to_review', 'draft', 'review'))
    ->addTransition(new Transition('publish', 'review', 'published'))
    ->addTransition(new Transition('reject', 'review', 'rejected'))

I don't see why I need this instead of querying the database? Sooner or later I have to hit the database, as even these libraries have persistence libraries.

I have looked here,

Should I use a workflow engine?

Is there such a thing as a workflow pattern? or how to do a workflow properly?

More than likely I'd be using C# if that matters, ASP.NET Core. But I don't think it matters for this question.

In my comments I mentioned SQL. I was not trying to imply one use SQL and nothing else. It was in the context of a programming language. You could use EF with Linq. It doesn't matter. My point was I could query the state in the database, so why the special state machines and workflows. Sorry for confusion.

  • I don't see why I need this instead of querying the database -- You don't. That's just the way those folks decided to do it. – Robert Harvey Sep 5 '18 at 18:35
  • But why? I'd like to be efficient, but the existence of the libraries make me think I'm missing something. – johnny Sep 5 '18 at 19:00
  • How do you define efficient? I once worked for a company that had a workflow engine driven entirely from a database. The task code for each workflow step was also stored in the database. It was executed by dynamically compiling the code using CSScript and standing up a new process. Was that efficient? Maybe not. But it had the characteristics that we wanted: hot patch capability and rock solid stability. Essentially, the requirement was that the workflow server never went down, and we achieved that. As usual, it comes down to your specific needs and requirements. – Robert Harvey Sep 5 '18 at 19:06
  • What advantage do the libraries give me instead of regular SQL? – johnny Sep 5 '18 at 19:33
  • 2
    SQL is a query language, not a general-purpose programming language. I've seen folks try to do general-purpose things in SQL; it never ends well. – Robert Harvey Sep 5 '18 at 19:42

The real benefit of a 'workflow' is the declarative modelling of control flow.

In your example, an absence request might go through branching logic, leading to different outcomes. A workflow chains together the logical steps.

enter image description here

'Workflow Applications', from .NET, are another alternative for visualizing a workflow. (It includes state machines as well as flowcharts.) Although the .NET Core port is still a work-in-progress.

With that said, sure, you can chain a process together however you'd like. A pure SQL approach might be rough, but you could probably even work out something clever with T-SQL 'triggers'.

What these libraries have in common is a top-level, easily readable configuration of the process.

A good workflow can be shared with non-technical business partners. Instead of just coding to a given specification, the workflow itself is the spec.

  • Thanks. Why wouldn't I have the branching in the database and the possibilities of that branch in the database? I would query and make a decision. Somewhere the decision has to be made. – johnny Sep 6 '18 at 15:10
  • You could. That's how the workflow engine I described in my comment below your question worked. – Robert Harvey Sep 6 '18 at 15:11
  • Actually, that's not true. The decisions were made in code. The code that ran in each node of the workflow returned a boolean value that governed which way the workflow went. But the workflow graph itself was represented in SQL records. – Robert Harvey Sep 6 '18 at 15:13

SQL on its own, is not a touring complete language. You can certainly implement a workflow engine entirely within most modern databases (T-SQL, PL/SQL, etc), but you wind up with a user interface that's only useful to folks who can read and understand those languages, plus the tooling is not designed to support your application, it's designed to interact with the database.

Some of the existing work-flow engines also have an ecosystem of supporting code, including customer facing UI's and web friendly (as-in REST-full) API's. If you roll your own, your customers will demand that you also forge those other elements.

  • It's probably not worth comparing SQL to Turing-complete languages, since Turing-complete languages aren't necessarily generally useful. E.g. you can technically build a Turing machine in Microsoft Powerpoint, which makes Powerpoint technically Turing-complete. But for actual computation and usefulness as a programming tool... Powerpoint is completely useless. Turing Complete != Useful. – Delioth Sep 5 '18 at 21:35
  • 1
    @Delioth, true, but !(Turing complete) != useful either, so what exactly is your point? Perhaps I should place more stress on the difficulties involved in creating customer facing UI's with a non-Turing system? – jwdonahue Sep 5 '18 at 21:39
  • I think powerpoint actually includes multiple .NET compatible scripting options btw. Probably easy enough to add a REST API to your powerpoint ;). – jwdonahue Sep 5 '18 at 21:41
  • I did not mean to imply I would use SQL absent a programming language like C#. I only meant I can query the database for the present state, so why use the libraries. – johnny Sep 6 '18 at 15:06
  • I think the ecosystem of inter-operating tools around each of the engines is the primary reason you would choose one of them. Like I said, either you write the components or you shop around for them. How much time will you spend developing vs integrating? What is the probability your customers will be happy with the result? – jwdonahue Sep 6 '18 at 15:13

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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