Short Lived or Long Lived, that is the question.

I’ve seen on a few occasions that there is some confusion on what the differences are between the short lived and long lived processes and when it’s appropriate to use one process type vs the other.  In this post I’ll talk about how the two work and some of the differences between them, and also talk a bit about when I choose to use one or the other.  In the end, you, as the developer will know your application and be in the best position to make the decision on which is right for you.  Hopefully, this post will arm you with enough knowledge to be able to make the best informed decision you can.

So what is the difference between the two?  A generic description you’ve probably already heard (or inferred from the names) is that short lived processes are for doing things that will complete quickly (or short running processes) and long lived processes are for doing things that will take a long time to complete (or long running processes).  However, there’s a lot more to it than just that.

Note: This post assumes the user has a license for Process Management.  Without this, use of long lived processes are restriction by the EULA.

Invocation Modes

The first thing to talk about is how these two process types are usually invoked.

Short Lived:  By far the most common way to invoke short lived processes is synchronously.  So in this case the caller invokes the process and waits until a response or output is returned from the process.  However, it is also possible to asynchronously invoke a short lived process.  You may have seen this termed as fire and forget in developer tooling like Workbench.  In this case the caller invokes the process and then moves on without waiting for a response.

Long Lived:  Long lived processes have only 1 method of invocation and that is asynchronously.  This is one differentiating factor, if you need a synchronous invocation of a process then you must use a short lived process.

Threading Model

The discussion of how things look at thread level actually depends on the invocation mode being used (synchronous vs asynchronous) and not strictly on short vs long lived processes.  However, since the vast majority of short lived processes are synchronously invoked and all long lived processes are asynchronously invoked you can almost draw a 1-1 relationship between thread behavior and process type.

In synchronously invoked processes what you will see is that the execution of the process will occur completely within the same thread as the invocation occurred.  This leads to a couple of interesting notes:

  1. There is more than one thread pool involved.  Since the thread where process execution occurs depends on the thread in which invocation occurred there are multiple possible pools from which the thread can come from.  For example, if you invoke the process via a SOAP request, you’ll be using a thread for process execution from the application servers web thread pool.  However, if you were to invoke the process using Workbench, the process execution would occur in a thread from within the application servers workmanager thread pool.
  2. For the entire lifecycle of the invocation the thread being used will never be released back into the pool.  What does this mean?  It means that for everything that is done prior to invocation, to the invocation, to the process execution, to everything that may occur after the invocation returns is all happening in the same thread, and that thread is not available to be used for anything else.  If you follow the general guideline that short lived processes should only be used for processing that doesn’t take much time, this isn’t likely to cause you any problems.  However, there is no technical limitation stopping you from using a short lived process for something that actually takes a long time to process.  For example, you might have a short lived process that takes 4 hours to finish.  In that case the thread you are using is unavailable for other work for that whole time.  As you might imagine, if you throw enough load at the system doing this, it would not be very difficult to exhaust the entire thread pool being used, and effectively “bring down” a portion of the application server.

For asynchronous invocations the process execution does not occur within the thread where the invocation occurs.  The process execution occurs inside another separate thread (one from the workmanager thread pool in ES2).  On top of that any asynchronous steps that are hit during execution of the process will result in the thread being released back into the pool for use.  This happens because the invocation of the asynchronous step’s operation is done asynchronously as well.

As you can see, while synchronous invocations have the advantage of not incurring any overhead of having to switch threads, asynchronous invocations provide a better capacity for sharing system resources among the entire load on the system and there are times when this would be preferable to just choosing the more efficient route.

Note: A common misconception is that each step in a long lived process runs in an asynchronous manner.  This has not been the case since version 8 where synchronous branches are used as the default for long lived processes.  This means that the execution of the process will occur in a synchronous fashion, within the same thread, until an asynchronous step is hit.  After the asynchronous step is done the process execution will again continue in a synchronous fashion until the next asynchronous step is hit.

Transactional Behavior and Database Use

The next thing to look at is the transactional differences between short lived and long lived processes and also their use of the database. 

Short lived process execution occurs entirely within one transaction.  This means that if anything goes wrong during execution of the process the entire transaction and all the steps that occurred previously will be rolled back.  Because of this, “retrying” a short lived process literally means invoking it again from scratch.

Note: There are further options for the transactional behavior of short lived processes that can be configured.  For example, whether to allow the process execution to occur within a parent transaction, or whether to force the creation of a new transaction to encompass the process execution.  I won’t go into these details as it could be a topic for a post all on it’s own, but will instead focus on the general behavior.

There is no default use of the database by short lived processes.  So unless there is a step in the process that explicitly writes to the database then nothing is written into it.

Long lived processes will have 1 transaction created and committed/rolled back per step in the process.  Unlike with short lived processes, when something goes wrong in a long lived process it is only the current step that gets rolled back and not the entire process.  When this occurs the step is then marked as stalled in the workflow engine, allowing you to go back and retry the step at a later date should you so desire.

This is made possible, because long lived processes will track the values of its process variables at each step in the process within the database.  This generally occurs within a database table named tb_pt_process_name, where process_name is the actual name of the process.  This means that there is additional overhead associated with long lived processes coming from it’s need to maintain it’s state inside the database.

Because the of the transaction behavior of these two process types there may be times when it is more desirable to use a long lived process even though it may not be strictly required.  Imagine the situation where a process loops around a dataset that is passed in as input and performs some operations on each item in the set.  Let’s say for each item the operations performed require 30 seconds of processing time, and the number of items in the dataset can be between 1 and 10000 items (numbers may be exagerated to illustrate the point :) ).  In that case the running time of this process will be between 30 seconds and 83.33 hours.  Normally the default transaction timeout value for an application server is around 5 mintues.  You can change the timeout value for the short lived process specifically, but in this case setting it to 84 hours wouldn’t be something I’d recommend.  Here it would be better to use a long lived process where you don’t have to worry about transaction timeout values.

So which should you choose?

Should you choose to design your process as a short lived process or long lived process?  In the end, it’s up to you, but when I’m faced with this decision here’s what I do:

I always design a process as short lived, unless I have to make it long lived.

Here’s some examples of times when I’d decide I have to make it long lived:

  • The process contains an asynchronous step (Wait and User services are the two that come to mind out of the box).
  • When the processes execution time is significant and you want to avoid using up threads in the thread pool used by the invoker.
  • When the process’ execution time is completely variable and unpredictable and you want to avoid setting an extremely high transaction timeout value.
  • When you want to have the granularity to to stall and retry on a step by step basis in the process.
  • When you want a data trail of the process variables to be kept in the database for tracking or reporting (this would bring up another question of whether to use the data we store for reporting or design your own reporting mechanism, which is outside the scope of this post.  In general, my recommendation would not be to use our data  for your reporting, it likely isn’t structured in a way you’ll find suitable).

Hopefully the information presented here will be helpful and provide you with the necessary background to make your decisions on process design and whether to use a short lived or long lived process.

VN:F [1.9.22_1171]
Was this helpful? Please rate the content.
Rating: 10.0/10 (5 votes cast)
Short Lived or Long Lived, that is the question., 10.0 out of 10 based on 5 ratings

About Chris Trubiani

Computer Scientist at Adobe Systems Canada
This entry was posted in Adobe LiveCycle ES2 (9.0.x), Adobe LiveCycle ES and tagged , , , . Bookmark the permalink.

7 Responses to Short Lived or Long Lived, that is the question.

  1. Hi Chris,

    interesting article. Maybe you could add that the option to use long lived processes needs a license for Process Management – at least that’s how I read the EULA.

    With kind regards


    • Chris Trubiani says:

      Hi Maruan,

      Thanks for the comment, I believe you are correct. Which is unfortunate, I hadn’t considered licensing when I wrote the post.


  2. Chris Trubiani says:

    I received a question internally via email about this post. I’ll copy and paste the question and answer here to benefit the wider group:

    Question on this :
    “There is no default use of the database by short lived processes. So unless there is a step in the process that explicitly writes to the database then nothing is written into it.”

    If you have configured to have your GDS in the database, is there also no activity to the db?


    The best answer I can give you is in most cases the answer is still no even if the GDS is in the DB. Any Document process variables in a short lived process will not be persistent Document objects. Non-persistent Document objects that are larger than the max inline size have their bytes stored in a local store and not the GDS. Even if the GDS is in the DB the local store is always on the file system, and is located under the LC_Temp folder.

    If your short lived process had some custom code in it that creates its own Document object and explicitly sets it to be persistent, and the size was greater than the max inline size, then this would be a case where bytes would be stored in the GDS and therefor in the DB.

    There is an edge case where non-persistent Document objects that are not inline can have their bytes stored in the GDS. It has something to do with when it needs to transfer bytes between different JVM’s for some reason. Unfortunately, I can’t say I understand much more about this edge case to better describe when this would occur. But this would be outside the norm, so shouldn’t happen very often.

  3. Harun Hasdal says:

    Hi Chris,

    You mentioned that, it is possible to invoke short-lived processes asynchronously. In the process orchestrations in workbench, you have the option to do so, by selecting ‘Invocation Policy’ as ‘Do not wait for response’. But this results in a runtime exception as follows

    com.adobe.workflow.WorkflowRuntimeException: Cannot invoke actions using Fire and Forget semantics on a shortlived process

    I work around that by using an event start-point in the short-lived process that i need to call; and fire the event to invoke it asynchronously, but of course this requires an event and a schema for carrying over the parameters.

    Is there any other way to invoke a short-lived process from a short-lived process asynchronously without using events or custom components?


  4. Chris Trubiani says:

    Hi Harun,

    This is a good point, I’m not sure why this is enforced on users when using Workbench. In fact, I believe I’m going to open a bug on this. You can do this perfectly fine using the API, so it doesn’t make sense to me. My suggestion would be to use the script service and a few lines of code to do it. Something like this, where in this case I’m invoking a process named Sub, in an application named ShortFromShort, with no input parameters, and doing so asycnhronously:

    import java.util.*;
    import com.adobe.idp.dsc.*;
    import com.adobe.idp.dsc.clientsdk.*;

    ServiceClientFactory fact = ServiceClientFactory.createInstance();
    ServiceClient client = fact.getServiceClient();
    Map m = new HashMap();
    InvocationRequest req = fact.createInvocationRequest(“ShortFromShort/Sub”, “invoke”, m, false);

    It’s not as nice as being as to just drag and drop the sub process, but it’s likely easier than needing an event. Hope that helps somewhat.


  5. Pingback: How to call a long-lived process from a short-lived process | LiveCycle Product Blog

  6. Harun Hasdal says:

    Hi Chris,

    Sorry about my late feedback. We are now using the executeScript approach having the same beanshell code, and I can confirm it works perfectly.
    Though i am with you that; not being able to do this in an orchestration is a bug.