# Workflow history size / count exceeds limit

**URL:** <https://community.temporal.io/t/workflow-history-size-count-exceeds-limit/1999>\
**Category:** Community Support\
**Tags:** history, metrics\
**Created:** [April 24, 2021, 2:37pm UTC](https://community.temporal.io/t/workflow-history-size-count-exceeds-limit/1999 "2021-04-24T14:37:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramprasad\_Indarapu](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/ramprasad_indarapu/32/718_2.png) [@Ramprasad\_Indarapu](https://community.temporal.io/u/Ramprasad_Indarapu)\
**Post date:** [April 24, 2021, 2:37pm UTC](https://community.temporal.io/t/workflow-history-size-count-exceeds-limit/1999/1 "2021-04-24T14:37:42Z")

</div>

Hi

We are doing some performance testing, where we have a main flow calling subflow(as childflow). The subflow execution is called in the loop, when we increased loop count from 500 to 600 it is failing.  
The workflow is terminated with the message “ Workflow history size / count exceeds limit”. Attached the screenshot.

Below is from the event history

4239  
WorkflowExecutionTerminated  
4m 20s  
reason  
Workflow history size / count exceeds limit.  
identity  
history-service

 ![Screen Shot 2021-04-24 at 8.02.41 PM](https://us1.discourse-cdn.com/flex016/uploads/temporal/original/1X/b205a71b6953764886ed37d35a891f5336bd3810.png)

---

<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:** [April 24, 2021, 6:17pm UTC](https://community.temporal.io/t/workflow-history-size-count-exceeds-limit/1999/3 "2021-04-24T18:17:28Z")

</div>

> [@Querying active workflows by their history size](https://community.temporal.io/t/querying-active-workflows-by-their-history-size/1997):
>
> Hi Temporal team! We are running some Temporal workflows in production, driven by certain user-generated events. Those workflows were not supposed to be long-running, and we expected them to have at most several hundred events in their history before they terminate. However, by analyzing the workflows that have already closed I’ve noticed that some of the workflows (probably generated by “bot”-like users) have several thousand events in their histories. That made me worry if some of the active…

---

<div class="post-metadata">

**Author:** ![Ramprasad\_Indarapu](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/ramprasad_indarapu/32/718_2.png) [@Ramprasad\_Indarapu](https://community.temporal.io/u/Ramprasad_Indarapu)\
**Post date:** [April 25, 2021, 11:36am UTC](https://community.temporal.io/t/workflow-history-size-count-exceeds-limit/1999/4 "2021-04-25T11:36:11Z")

</div>

Thanks. @maxim  
And let me explain my use case.

The payload for the workflow is below

main:  
foreach

- call subflow1 100 times

subflow1:  
steps:  
step1  
step2

- call subflow2  
step3

subflow2:  
steps:  
step1

Current implementation  
Payload is sent to main flow execution  
When the subflow is invoked the complete payload is again sent to subflow, as the nested subflows are possible  
This is the main reason I guess for the history size increase.

Thinking of the below solution. Can you please validate the following solution?

Solution1  
Maintain the complete payload in the main workflow.  
Implement a query method in the main flow to return by taking a subflow name as an argument and return subflow payload and cache it as one of the flow instance variable  
When a child flow requires subflow payload, use the query method of the main workflow to get the same.  
We have a case where the subflow1 can be executed in parallel(using child flows) where the work is distributed say 10 child flows each handles 10 iterations). I am using the promise to complete the child flow as below.

JiffyWorkflow workflow = WorkFlowUtils.buildChildWorkFlowObject();  
executions.add(Async.function(workflow::execute, flowInput));  
Promise.allOf(executions).get();

One question I have is “will this work in case of child flow crashes also”?

---

<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:** [April 25, 2021, 5:07pm UTC](https://community.temporal.io/t/workflow-history-size-count-exceeds-limit/1999/5 "2021-04-25T17:07:09Z")

</div>

If the payload is large we recommend storing it in some external store (like S3) and pass only references to it through workflow and activity arguments.

> One question I have is “will this work in case of child flow crashes also”?

I’m not sure I correctly understand the question. What do you mean by “child flow crashes”? If the worker process that hosts the child workflow crashes then the recovery will be seamless and nothing should be done. If the child workflow throws an exception the parent workflow will need to handle its failure.

---

<div class="post-metadata">

**Author:** ![Ramprasad\_Indarapu](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/ramprasad_indarapu/32/718_2.png) [@Ramprasad\_Indarapu](https://community.temporal.io/u/Ramprasad_Indarapu)\
**Post date:** [April 25, 2021, 5:13pm UTC](https://community.temporal.io/t/workflow-history-size-count-exceeds-limit/1999/6 "2021-04-25T17:13:55Z")

</div>

Thanks @maxim . The payload is not more than 2mb, but as we are passing to childflows, which are executing in loop, the history size is increasingly. Just to confirm my question is is it better to pass only reference to childflows and get the subflow/childflow payload from the parentflow by query method.

---

<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:** [April 25, 2021, 6:25pm UTC](https://community.temporal.io/t/workflow-history-size-count-exceeds-limit/1999/7 "2021-04-25T18:25:10Z")

</div>

The query approach works in your case.

I filed [an issue](https://github.com/temporalio/temporal/issues/1492) to see if there is a way to optimize this use case.
