# How does the process instance ID increment work?

**URL:** <https://forum.flowable.org/t/how-does-the-process-instance-id-increment-work/5450>\
**Category:** Flowable Engine\
**Created:** [February 14, 2020, 11:14pm UTC](https://forum.flowable.org/t/how-does-the-process-instance-id-increment-work/5450 "2020-02-14T23:14:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff.gehly](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@jeff.gehly](https://forum.flowable.org/u/jeff.gehly)\
**Post date:** [February 14, 2020, 11:14pm UTC](https://forum.flowable.org/t/how-does-the-process-instance-id-increment-work/5450/1 "2020-02-14T23:14:26Z")

</div>

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().

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [February 16, 2020, 7:11am UTC](https://forum.flowable.org/t/how-does-the-process-instance-id-increment-work/5450/2 "2020-02-16T07:11:30Z")

</div>

> [@jeff.gehly](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![jeff.gehly](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@jeff.gehly](https://forum.flowable.org/u/jeff.gehly)\
**Post date:** [February 19, 2020, 11:23pm UTC](https://forum.flowable.org/t/how-does-the-process-instance-id-increment-work/5450/4 "2020-02-19T23:23:46Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![ayush\_gaurav](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@ayush\_gaurav](https://forum.flowable.org/u/ayush_gaurav)\
**Post date:** [March 17, 2022, 8:49am UTC](https://forum.flowable.org/t/how-does-the-process-instance-id-increment-work/5450/5 "2022-03-17T08:49:58Z")

</div>

> [@filiphr](#):
>
> HiLo

Where you able to figure out why we are getting lower Instance id ?

process Instance Id e6f407a7-a5c7-11ec-973b-bee536b2e51c is created successfully  
process Instance Id 241bb340-a5c8-11ec-973b-bee536b2e51c is created successfully  
process Instance Id 7cc4b0f9-a5c8-11ec-973b-bee536b2e51c is created successfully
