# What is the best way to count the number of workflow running instances?

**URL:** <https://community.temporal.io/t/what-is-the-best-way-to-count-the-number-of-workflow-running-instances/3349>\
**Category:** Community Support\
**Tags:** workflow-config\
**Created:** [November 9, 2021, 10:50am UTC](https://community.temporal.io/t/what-is-the-best-way-to-count-the-number-of-workflow-running-instances/3349 "2021-11-09T10:50:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Newbie\_Sr](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/newbie_sr/32/589_2.png) [@Newbie\_Sr](https://community.temporal.io/u/Newbie_Sr)\
**Post date:** [November 9, 2021, 10:50am UTC](https://community.temporal.io/t/what-is-the-best-way-to-count-the-number-of-workflow-running-instances/3349/1 "2021-11-09T10:50:53Z")

</div>

Hi,  
I want to count the number of running instances of a workflow definition. What is the best way to do it? Can I run a workflow multiple times with the same workflow id but different run ids? So that I can query the count of workflow instances with the same workflow id. (tried seems not working)

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [November 9, 2021, 1:56pm UTC](https://community.temporal.io/t/what-is-the-best-way-to-count-the-number-of-workflow-running-instances/3349/2 "2021-11-09T13:56:04Z")

</div>

> I want to count the number of running instances of a workflow definition. What is the best way to do it?

Each workflow has a specific type. Workflow executions that you create inherit that type and have a status associated with them. If you have enhanced visibility enabled (Elasticsearch) you could use ListWorkflowExecutions  
api to query workflows of a specific type and its status for a specific namespace. A sample query could be for example:

`WorkflowType="MyWorkflowType" AND ExecutionStatus="Running"`

(you can try this query inside the web-ui as well (click on the “Advanced” button on the top-right corner).  
Don’t know which Temporal SDK you are using to provide an example.

> Can I run a workflow multiple times with the same workflow id but different run ids?

You cannot have two workflow executions running at the same time that have the same workflow id.  
Specific details on this can be set via WorkflowIdReusePolicy (via WorkflowOptions), with default behavior being that you can start a new execution with the same id only if previous one with that id completed (is no longer running).

> So that I can query the count of workflow instances with the same workflow id. (tried seems not working)

You should be able to use ListWorkflowExecutions to query for specific workflow id, regardless of the execution status. Sample query:

`WorkflowId="myWorkflowId"`

---

<div class="post-metadata">

**Author:** ![Newbie\_Sr](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/newbie_sr/32/589_2.png) [@Newbie\_Sr](https://community.temporal.io/u/Newbie_Sr)\
**Post date:** [November 9, 2021, 3:43pm UTC](https://community.temporal.io/t/what-is-the-best-way-to-count-the-number-of-workflow-running-instances/3349/3 "2021-11-09T15:43:46Z")

</div>

Thanks for the reply Is the WorkflowType the workflow name? I registered the workflow with a given name

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [November 9, 2021, 3:53pm UTC](https://community.temporal.io/t/what-is-the-best-way-to-count-the-number-of-workflow-running-instances/3349/4 "2021-11-09T15:53:08Z")

</div>

For Java SDK, its by default the short class name of your workflow interface, and can be specifically set via @WorkflowMethod annotation (name param).

For Go SDK, its by default the name of your workflow function, and can be specifically set via RegisterWorkflowOptions-\>Name.

You can see the workflow type also in the “NAME” column of the web ui.

---

<div class="post-metadata">

**Author:** ![Newbie\_Sr](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/newbie_sr/32/589_2.png) [@Newbie\_Sr](https://community.temporal.io/u/Newbie_Sr)\
**Post date:** [November 9, 2021, 3:55pm UTC](https://community.temporal.io/t/what-is-the-best-way-to-count-the-number-of-workflow-running-instances/3349/5 "2021-11-09T15:55:26Z")

</div>

Yep, that is what i meant.  
but this seems not to work for me, since i am using this [GitHub - checkr/states-language-cadence: States Language on Cadence](https://github.com/checkr/states-language-cadence) so I only have one workflow to be registered. All my workflow are written in ASL. Is there any other options that i can pass in like a tag or something to be able to identify the different workflows?

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [November 9, 2021, 4:00pm UTC](https://community.temporal.io/t/what-is-the-best-way-to-count-the-number-of-workflow-running-instances/3349/6 "2021-11-09T16:00:58Z")

</div>

You can create multiple executions for the same workflow type.  
The original question was about the workflow id.  
In your case, you should set each workflow id to some unique value that can be based on really anything that you want, some unique business value (like customer id for example). If you don’t specifically set the workflow id when you start a new execution, Temporal will set it to an uuid that should be unique for your namespace used.

---

<div class="post-metadata">

**Author:** ![Newbie\_Sr](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/newbie_sr/32/589_2.png) [@Newbie\_Sr](https://community.temporal.io/u/Newbie_Sr)\
**Post date:** [November 9, 2021, 4:28pm UTC](https://community.temporal.io/t/what-is-the-best-way-to-count-the-number-of-workflow-running-instances/3349/7 "2021-11-09T16:28:35Z")

</div>

specify unique workflow id seems not to work, since i will run multiple workflow instance at the same time. Here is my configuration: I have a ASL workflow (a state machine in [GitHub - checkr/states-language-cadence: States Language on Cadence](https://github.com/checkr/states-language-cadence)) registered in Temporal, and I have a workflow written in ASL say “hello-asl”, this workflow can be triggered to run in many places, each running instance should have a unique workflow id, right?

So I want to list all workflows instances (all status) associated with “hello-asl”, is it doable?

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [November 9, 2021, 5:03pm UTC](https://community.temporal.io/t/what-is-the-best-way-to-count-the-number-of-workflow-running-instances/3349/8 "2021-11-09T17:03:00Z")

</div>

I am not familiar with that particular project, but assume that you have a Temporal workflow that is executing the instructions in your DSL.  
You can set that workflow type to be “hello-asl” and then if you cannot set a business-level id for each execution, either set you own unique id, or don’t set the workflow id so Temporal assigns one for you.

> So I want to list all workflows instances (all status) associated with “hello-asl”, is it doable?

Yes, if you set “hello-asl” as the workflow type, you can use a search query, for example:

`WorkflowType="hello-asl" AND ExecutionStatus="Running"`

---

<div class="post-metadata">

**Author:** ![Newbie\_Sr](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/newbie_sr/32/589_2.png) [@Newbie\_Sr](https://community.temporal.io/u/Newbie_Sr)\
**Post date:** [November 10, 2021, 2:30am UTC](https://community.temporal.io/t/what-is-the-best-way-to-count-the-number-of-workflow-running-instances/3349/9 "2021-11-10T02:30:32Z")

</div>

we are not only having “hello-asl”, we have 10s of workflows defined in ASL. So set the workflow type as hello-asl will not work

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [November 10, 2021, 5:03am UTC](https://community.temporal.io/t/what-is-the-best-way-to-count-the-number-of-workflow-running-instances/3349/10 "2021-11-10T05:03:35Z")

</div>

You can add a [custom search attribute](https://docs.temporal.io/docs/temporal-explained/visibility/#custom-search-attributes) that contains your DSL workflow type.
