# Activity restarts from beginning of the processs on HeartBeatTimeout and on AcitivityNotExistsExcpetion

**URL:** <https://community.temporal.io/t/activity-restarts-from-beginning-of-the-processs-on-heartbeattimeout-and-on-acitivitynotexistsexcpetion/8225>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [May 11, 2023, 3:53pm UTC](https://community.temporal.io/t/activity-restarts-from-beginning-of-the-processs-on-heartbeattimeout-and-on-acitivitynotexistsexcpetion/8225 "2023-05-11T15:53:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajesh\_NA](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/rajesh_na/32/3624_2.png) [@Rajesh\_NA](https://community.temporal.io/u/Rajesh_NA)\
**Post date:** [May 11, 2023, 3:53pm UTC](https://community.temporal.io/t/activity-restarts-from-beginning-of-the-processs-on-heartbeattimeout-and-on-acitivitynotexistsexcpetion/8225/1 "2023-05-11T15:53:32Z")

</div>

I triggered a long running activity with say 10 records. During the 3rd record if for some reason, it takes more time and the heartbeat failed. The whole activity is retried from the 1st record which results in duplicate processing. From the youtube video, understood this is the expected behaviour. However, this results in duplicate downstream activites. (Say intead of lauching 10 workflows for 10 records, it launches, 3(first attempt) + 10 (On retry) = 13 child workflows for each record. How to avoid this kind of behaviour and only launch the child workflows according to the original number of records(say 10) ?

---

<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:** [May 13, 2023, 4:37pm UTC](https://community.temporal.io/t/activity-restarts-from-beginning-of-the-processs-on-heartbeattimeout-and-on-acitivitynotexistsexcpetion/8225/2 "2023-05-13T16:37:36Z")

</div>

There are two separate issues here:

### Activity Losing Progress After Heartbeat Timeout

You can include the record id in the heartbeat as details. The latest recorded value is available when an activity is retried. See the [heartbeatingactivity](https://github.com/temporalio/samples-java/blob/d1b2f8c34051e785eeff5f28128e90220eceff7e/src/main/java/io/temporal/samples/batch/heartbeatingactivity/RecordProcessorActivityImpl.java#L77) sample.

Note that heartbeat calls are throttled. So it is OK to call heartbeat on every record, but the frequency of actual calls to the service will depend on the heartbeat timeout. So it is still possible to process the same record multiple times.

### Starting Duplicated Workflows

This should be solved by assigning business-level id as _WorkflowId_. Temporal guarantees the uniqueness of workflow executions by its id. So if the duplicated start is issued for the same _WorkflowId_, the call will fail with the _AlreadyStarted_ error.

Also, familiarize yourself with [WorkflowIdReusePolicy](https://docs.temporal.io/workflows#workflow-id-reuse-policy), which defines the start behavior if the previously started workflow with the same id already completed.
