Thursday, April 23, 2009

Workflow vs. Server Script

There's a lot of advice out there that says to use declarative solutions whenever possible and turn to scripting as a last resort only.  Hell, it's the basis of Siebel's technical document "Declarative Alternatives to Siebel Scripting".  I believe in using straight Tools configuration as much as possible, but there's one thing I'm not yet sold on: Using workflow processes in lieu of scripted business services for complex actions.

I used to believe what I heard, that workflow processes were superior to scripted business services - but then I decided to evaluate it for myself.  There are advantages and disadvantages to each approach, and I'll get to those later.

What originally sold me was the argument that workflow processes performed more strongly than server script because they did not have the overhead of a script interpreter.  The argument usually goes something like this, "Workflow processes run the compiled C++ code directly, so are faster than scripted processes that must be interpreted."  Well newsflash: Workflow processes also need to be interpreted.  Siebel did not build your workflow into their product, did they?  You described it using a tool, and that description must be interpreted at runtime.  Yes, compiled C++ is used to interpret your workflow processes.  And compiled C++ is also used to interpret your scripts.

Which interpreter is faster?  Which engine loads faster?  I ran some tests to find out.  The results show that the two were very comparible when performing the exact same operations.  If there were any differences, they were negligible.  My test updated the amount of a single revenue record.  Each process (scripted and workflow) did one query and one update.  After warming up the OM, each process completed in 57 milliseconds on average (which included the time to invoke each via a driver script).

What I did notice was that because workflow processes were not as descriptive as script, and you sometimes needed to do more work to accomplish the same task.  For instance, when I extended the test to update multiple revenue records, it took the scripted version 1 query and 21 writes to update 21 records, while the workflow processes needed 22 queries and 21 writes.  How did that affect the results?  The scripted process averaged a reasonable 500 milliseconds while the workflow process chugged along at 865 milliseconds on average.

So the results seem to say that workflows are just as fast as scripts when the performing the same operations, but the inflexibility of workflow processes can lead to algorithms that are less than ideal performance-wise.

Other reasons to like business services are that the development times are faster for various reasons.  The script debugging tools are more sophisticated, and starting your script debugger is typically faster than starting the workflow simulator - particularly if you need to deploy and activate a workflow subprocess before simulating.  And I don't think anyone would disagree when I say that scripts are far more flexible and powerful than workflow processes.

So what reasons are there to like workflow processes?  For one, they can be deployed without an SRF.  I'm guessing that benefit has not nor will ever be realized by a large portion of Siebel customers.  One reason that I like is that their level of instrumentation is far superior to script.  The workflow monitor and logging events are far more useful in a production environment than any script built-in instrumentation for script (there is almost none).  That can be invaluable in getting a production issue resolved quickly, for a problem that would normally be hard to reproduce and research.

In the end, I'm somewhere in the middle - but I'd have to say a bit closer to the script (read: dark) side.  What do you all think?

9 comments:

  1. Good article.

    There are projects out there, that ban scripting in their repository, and completely exhaust all declarative means before scripting, even if it means creating monster or ineffecient workflows to do the same thing a few line of code can do. The result? Painful developement, but nice WFs that quickly explain the business process.

    Then there are projects, that resort to scripting as the first choice, because it is easy to develop, predictable, and powerful. This could be a very good thing, especially if its implemented using a framework, but more often than not, producing consistent quality, maintainable code is more of a dream than a reality.

    ReplyDelete
  2. I agree with all that you've said.
    I have now given up writing core-logic in workflow processes. I use them only for Orchestrating well-written business services.
    I call it Siebel BPM :)

    Also, I find WFs very useful when the number of parameters to a OOTB service runs into the dozens like in the case of the Row Set Transformation Toolkit business service.

    In 8.0, NextRecord and PreviousRecord are available as Siebel Operations so that might help with the multiple Query problem that you've mentioned.

    Btw, I have read and enjoyed all your posts; Please continue the good work.

    ReplyDelete
  3. BPM = Business Process Management? I like it. I think there is a benefit to representing a business process with some well-defined business services in flow diagram with simple decision steps. I like that level of granularity. It keeps the business process easy to understand at a glance, but reserves the nuts and bolts of the process to easy-to-tweak business services.

    ReplyDelete
  4. I agree that there are applications for both, and the decision isn't entirely based on only scripting something that cannot be accomplished with a declarative alternative. Efficiency is a consideration, as is developing a re-usable, maintainable configuration.

    There are usually so many ways to use workflow to accomplish one task that the decision to use a declarative option is really only one of many design options to take.

    Thank you for running those time tests. I have often wondered about that. Any thoughts on running server-side business services against client-side business services?

    ReplyDelete
  5. Do you mean business services written entirely in browser script as opposed to written in server script?

    Or do you mean business services written in the Administration - Business Service screens vs business services compiled into the SRF?

    ReplyDelete
  6. Hello, well... My approach to deciding which algorithms goes to script or workflow was more pragmatic then JUST performance:
    1) Scripts are less expensive from creation and maintenance PoV then workflows (given there are no huge scripts and you tend to use as much declarative power as possible). For example, you cannot use OnUpdateFieldSet and BCFieldReadOnlyField on the same field in a BC, because read-only rule executes first, update rule executes second (don't execute in this example)
    2) Scripts are indefinitely more expensive in terms of SRF change when in comes to 24/7/365 mission critical operations (for example, large telecom call-center).
    3) Don't forget the endless mess with Runtime Events etc. which is required of you need to use Workflows IN PLACE of scripts.
    4) There are things which are unique to scripting and you just can't do that with Workflows at all (such as browser-side scripting or TheApplication().GotoView(), though they MUST be rare)
    5) Complex data validation typically cannot be implemented using Workflows
    6) Scripts support caching (I mean Business Services) without using Profile Attributes or Application Globals, which is sometimes VERY
    useful from performance PoV.
    7) If you read how Oracle treats Scripts and Workflows from upgrade PoV you will file Workflows to be MUCH MORE a disaster to upgrade then script (well, I don't agree with that, but this is official PoV)
    8) Also Runtime Scripts need to be remembered about. This is the thing which also has its own valid use cases. Some SIMPLE algorithms that are just accept some parameters and return some result which need to be changed from time to time, without Business Objects, Objects Ids and all that stuff. For example, some on-line customer auto-classification algorithms.
    etc. etc. etc.

    So my resume would be the following:
    General considerations are ok when you have not so large data sets (2-3 mln. records in biggest table), not so customized solution, etc. And even then the choice between Workflows and Scripts would be not in PERFORMANCE choice, but rather a functional choice (Is it going to be changed from time to time? Should we allow customer to change those algorithms themselves? etc. etc. etc.)

    In general, I would advice to not have universal concept in mind, just have as much diversity as possible at hand and use it to suite exact project requirements with future changes in mind.

    ReplyDelete
  7. Hi
    Workflow executes in Siebel as part of Workflow process manager and the server script will be executed will be the Application object manager.As you can see most of the User interface is rendered by AOM you can always lower the load on AOM by redestributing your business processes to Workflow/Assignment Manager etc.More over workflow is more robust than the server scripting as mentioned in the comments already
    Thanks

    ReplyDelete
  8. Hi,

    For those of us that have to deal with massive remote users, declarative alternatives in the SRF are probably a less preferred option. Just the very thought of deploying an SRF out to 4000+ remote users with varying levels of connectivity makes me shudder. We prefer using client-side business services extensively as part of a framework - easy to maintain, and because they are interpreted, syntax errors in one function / method do not impact the rest of the business service.

    ReplyDelete
  9. Mark - thanks for sharing!

    Gr8 work.

    ReplyDelete