How does the process instance ID increment work?

So I’m trying to collect the most recent process instance value for a workflow that can be started and ended repeatedly for the same data values. The way I’ve tried to get the “latest” was to take the largest process instance ID. But I’m finding that flowable, while it generates unique IDs for each workflow, does not seem to increment the process instance ID by a reliable value. I can see in the Flowable database tables that the process IDs seem to have circled around, because my latest process instance has a lower process instance ID that processes that were terminated earlier.

Process termination, in the sense that I use it, occurs via the Flowable API function of the runtimeService, deleteProcessInstance().

It is not possible for the id to circle around. However, if you are running multiple engines on multiple nodes it is possible that one node has lower values than the other one. The process engine by default (when not used via Spring Boot) has a database ID generator which uses a so called HiLo sequence generator. Every engine would get some base number from the DB and then increment it with the block size for the other nodes.

For example block size is 2500. When the generator starts one node will get the start (0) and then increment it to 2500. The other node will then get the next block starting with (2500).

I would strongly advise against ordering on the ID for finding the most recent process instance. The HistoricProcessInstanceQuery has orderByProcessInstanceStartTime and the ProcessInstanceQuery has orderByStartTime so I would suggest you use that ordering to get the correct order.

I updated my code to order by the process start time in descending order, and that fixed my problem. I figured there was something to keep the IDs unique, but this does explain how I ended up with a lower-ordered ID because we have the exact situation you describe (multiple independent engines on different nodes that aren’t talking to each other).