# Return workflow response with activities running in background

**URL:** <https://community.temporal.io/t/return-workflow-response-with-activities-running-in-background/3646>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [December 22, 2021, 1:46pm UTC](https://community.temporal.io/t/return-workflow-response-with-activities-running-in-background/3646 "2021-12-22T13:46:26Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![poojabhutada](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/poojabhutada/32/3372_2.png) [@poojabhutada](https://community.temporal.io/u/poojabhutada)\
**Post date:** [December 22, 2021, 1:46pm UTC](https://community.temporal.io/t/return-workflow-response-with-activities-running-in-background/3646/1 "2021-12-22T13:46:27Z")

</div>

Hi,

I have a scenario where my workflow consists of 4 activity calls (A,B,C,D) where A is sync while other three are async calls. I want the client to get the sync response of A immediately while the rest three activities can run in background.  
Is there any way to achieve this? As per my understanding, if a workflow returns a response, it gets marked as completed even when the rest of the activities are still in scheduled/running state.  
My requirement is to return the sync response of A, but rest of the activities should be executed and then only workflow to be marked as completed.

---

<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:** [December 22, 2021, 4:54pm UTC](https://community.temporal.io/t/return-workflow-response-with-activities-running-in-background/3646/2 "2021-12-22T16:54:20Z")

</div>

We plan to add direct support for this use case. Currently the following workaround is recommended:

1. Invoke a workflow synchronously.
2. This workflow executes activity A and then starts a child workflow [asynchronously in the abandoned mode](https://community.temporal.io/t/best-way-to-create-an-async-child-workflow/114/2).
3. Initial workflow completes unblocking the caller.
4. The child workflow executes activities B, C , D asynchronously.

---

<div class="post-metadata">

**Author:** ![poojabhutada](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/poojabhutada/32/3372_2.png) [@poojabhutada](https://community.temporal.io/u/poojabhutada)\
**Post date:** [December 22, 2021, 5:06pm UTC](https://community.temporal.io/t/return-workflow-response-with-activities-running-in-background/3646/3 "2021-12-22T17:06:47Z")

</div>

Yeah, i get your point. But my requirement is to compensate activity A if in case any of the rest 3 calls fail. Can that be handled?

---

<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:** [December 22, 2021, 5:49pm UTC](https://community.temporal.io/t/return-workflow-response-with-activities-running-in-background/3646/4 "2021-12-22T17:49:15Z")

</div>

The child workflow can compensate the activity A if any of the B, C, D fail.

---

<div class="post-metadata">

**Author:** ![poojabhutada](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/poojabhutada/32/3372_2.png) [@poojabhutada](https://community.temporal.io/u/poojabhutada)\
**Post date:** [December 23, 2021, 11:16am UTC](https://community.temporal.io/t/return-workflow-response-with-activities-running-in-background/3646/5 "2021-12-23T11:16:55Z")

</div>

@maxim Thanks for the response.  
Followup queries :

1. To compensate Activity A call, that needs to be handled in child workflow definition as part of failure handling? Because the parent workflow must have got completed, so there would be no point in defining the compensation in parent workflow. Is my understanding correct?
2. How can we get the response being returned from the activity being executed as part of compensating SAGA transaction ?
3. Does the SAGA compensating transaction get logged in workflow execution history?

---

<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:** [December 24, 2021, 2:38am UTC](https://community.temporal.io/t/return-workflow-response-with-activities-running-in-background/3646/6 "2021-12-24T02:38:18Z")

</div>

1. Yes, you would do the compensation in the child workflow (if any of B,C,D fail as you mentioned)
2. One way you could do it is have the parent return the WorkflowExecution of the async child back to the client, see the [async child](https://github.com/temporalio/samples-java/tree/main/src/main/java/io/temporal/samples/asyncchild) sample, specifically:  
[samples-java/Starter.java at main · temporalio/samples-java · GitHub](https://github.com/temporalio/samples-java/blob/main/src/main/java/io/temporal/samples/asyncchild/Starter.java#L52)  
With that, you can reconnect to the child workflow in the client code and wait for its results (or query it if you want) via:

```auto
// connect to the async child wf execution after parent returned
WorkflowStub childStub =
        client.newUntypedWorkflowStub(
            childWorkflowExecution.getWorkflowId(),
            Optional.of(childWorkflowExecution.getRunId()),
            Optional.empty());

    // wait for the child workflow to complete
    String childResult = childStub.getResult(String.class); // you can use childStub.query(...) to query as well

```

1. Yes, if your compensation defines invocations of child workflows or activities, they will be recorded in history.

---

<div class="post-metadata">

**Author:** ![poojabhutada](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/poojabhutada/32/3372_2.png) [@poojabhutada](https://community.temporal.io/u/poojabhutada)\
**Post date:** [December 24, 2021, 3:01am UTC](https://community.temporal.io/t/return-workflow-response-with-activities-running-in-background/3646/7 "2021-12-24T03:01:44Z")

</div>

Thanks @tihomir for the explanation.  
But point 2, let me clarify my question. If any activity call is being made, using saga.compensate() function, is there any way to fetch the result of that activity call. Because the compensate() call returns void, so trying to understand that.

---

<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:** [December 24, 2021, 3:23am UTC](https://community.temporal.io/t/return-workflow-response-with-activities-running-in-background/3646/8 "2021-12-24T03:23:31Z")

</div>

> [@poojabhutada](#):
>
> is there any way to fetch the result of that activity call. Because the compensate() call returns void, so trying to understand that.

` saga.compensate()` triggers compensation which can include multiple activity invocations.  
You can get results of each in `saga.addCompensation`, for example:

```auto
saga.addCompensation(
        () -> {
          sagaCompensateResult = activity.compensate(myCompensateActivityInput);
        });

```

---

<div class="post-metadata">

**Author:** ![poojabhutada](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/poojabhutada/32/3372_2.png) [@poojabhutada](https://community.temporal.io/u/poojabhutada)\
**Post date:** [February 27, 2023, 12:47pm UTC](https://community.temporal.io/t/return-workflow-response-with-activities-running-in-background/3646/9 "2023-02-27T12:47:09Z")

</div>

> [@maxim](#):
>
> We plan to add direct support for this use case.

@maxim Any updates on this feature to be developed in near future?

---

<div class="post-metadata">

**Author:** ![Burak\_Akca](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/burak_akca/32/4242_2.png) [@Burak\_Akca](https://community.temporal.io/u/Burak_Akca)\
**Post date:** [September 7, 2023, 8:24am UTC](https://community.temporal.io/t/return-workflow-response-with-activities-running-in-background/3646/10 "2023-09-07T08:24:58Z")

</div>

> [@maxim](#):
>
> We plan to add direct support for this use case.

@maxim Any updates on this feature?

---

<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:** [September 7, 2023, 3:02pm UTC](https://community.temporal.io/t/return-workflow-response-with-activities-running-in-background/3646/11 "2023-09-07T15:02:46Z")

</div>

We are finishing the first part of this work in the form of the synchronous update feature. The “updateWithStart” will be the next.

---

<div class="post-metadata">

**Author:** ![Ilya](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@Ilya](https://community.temporal.io/u/Ilya)\
**Post date:** [June 9, 2024, 12:45pm UTC](https://community.temporal.io/t/return-workflow-response-with-activities-running-in-background/3646/12 "2024-06-09T12:45:14Z")

</div>

Hello!  
Is there any updates for the feature “updateWithStart”?

The last thing I found about it was this question, half a year ago:

> [@Would "updateWithStart" make sense?](https://community.temporal.io/t/would-updatewithstart-make-sense/10444):
>
> Now that Workflow Updates are landing in TS SDK (and Core!), I was thinking about supporting updateWithStart. I’m thinking specifically about TS SDK since it’s the one I use the most but I’d say other SDKs would follow the same idea. The client calls updateWithStart for a given workflow ID and, if one is running, it registers the update. If not, it starts the workflow with that given update request, and waits for the update to return. So, basically the same idea behind signalWithStart. I can …

---

<div class="post-metadata">

**Author:** ![bnpnt](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/bnpnt/32/3689_2.png) [@bnpnt](https://community.temporal.io/u/bnpnt)\
**Post date:** [June 10, 2024, 6:47pm UTC](https://community.temporal.io/t/return-workflow-response-with-activities-running-in-background/3646/13 "2024-06-10T18:47:37Z")

</div>

it would indeed be very nice to have, and for me personally would open up workflow updates for more “serious” use cases
