# Communication between Workflow and request handler

**URL:** https://community.temporal.io/t/communication-between-workflow-and-request-handler/12605
**Category:** Community Support
**Tags:** go-sdk
**Created:** [June 21, 2024, 2:27pm UTC](https://community.temporal.io/t/communication-between-workflow-and-request-handler/12605 "2024-06-21T14:27:29Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Roman\_Gorkovets](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/roman_gorkovets/32/5502_2.png) [@Roman\_Gorkovets](https://community.temporal.io/u/Roman_Gorkovets)
#### Post date: [June 21, 2024, 2:27pm UTC](https://community.temporal.io/t/communication-between-workflow-and-request-handler/12605/1 "2024-06-21T14:27:29Z")

</div>

Hello. I am new to temporal and currently i’m working on creating a grpc request-handler in which I create a long workflow and trying to retrieve an information from there in order to respond to user’s grpc request whilst workflow execution continues. To be short, here is the usecase:

1. User sends a GRPC request
2. Send request to service A
3. Get response from service A
4. Some business logic
5. Save information in Database
6. Respond to user’s GRPC request
7. Await an http callback from service A

I see the solution of this problem like following:

| GRPC Handler | Workflow |
| --- | --- |
| Accept GRPC request | |
| ExecuteWorkflow() | |
| QueryWorkflow(“getGRPCResponse”) in loop until retrieve a response | ExecuteActivity(SendRequestToServiceA) |
| | some business logic |
| | ExecuteActivity(SaveToDatabase) |
| | SetQueryHandler(“getGRPCResponse”, myResponse) |
| encoder.Get(&response) | AwaitSignal() // waiting for callback |
| Respond to GRPC request | ExecuteActivity(AnotherActivity1) |
| | ExecuteActivity(AnotherActivity2) |
| | ExecuteActivity(AnotherActivity3) |
| | Finish execution |

Are there more idiomatic approaches to do so?

---

<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: [June 21, 2024, 2:49pm UTC](https://community.temporal.io/t/communication-between-workflow-and-request-handler/12605/2 "2024-06-21T14:49:45Z")

</div>

Instead of polling using a query, you can use an [Update](https://docs.temporal.io/develop/go/message-passing#updates) to wait for the workflow to reach some state.

---

<div class="post-metadata">

### Author: ![Roman\_Gorkovets](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/roman_gorkovets/32/5502_2.png) [@Roman\_Gorkovets](https://community.temporal.io/u/Roman_Gorkovets)
#### Post date: [June 21, 2024, 4:39pm UTC](https://community.temporal.io/t/communication-between-workflow-and-request-handler/12605/3 "2024-06-21T16:39:05Z")

</div>

Thank you for your response. This is the way I do it now:

| GRPC handler | MyWorkflow |
| --- | --- |
| Accept Request | |
| ExecuteWorkflow(MyWorkflow) | ExecuteActivity(SendToServiceA) |
| handle = UpdateWorkflow(“myIntermediateResponse”) | Some buiseness logic |
| handle.Get(&ret) | ExecuteActivity(SaveInDB) |
| Respond with ret | SetUpdateHandler(“myIntermediateResponse”, func() {return intermediateRet}) |
| | ExecuteActivity(OtherActivity1) |
| | ExecuteActivity(OtherActivity2) |
| | ExecuteActivity(OtherActivity3) |

This way on step handle = UpdateWorkflow(“myIntermediateResponse”) i am getting into an error:  
unknown update myIntermediateResponse. KnownUpdates=

, since at the moment of UpdateWorkflow request there was no handler matched to “myIntermediateResponse”. I guess I did not fully understand you.

The version of SDK Im currently using is [go.temporal.io/sdk](http://go.temporal.io/sdk) v1.27.0

---

<div class="post-metadata">

### Author: ![Roman\_Gorkovets](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/roman_gorkovets/32/5502_2.png) [@Roman\_Gorkovets](https://community.temporal.io/u/Roman_Gorkovets)
#### Post date: [June 21, 2024, 4:49pm UTC](https://community.temporal.io/t/communication-between-workflow-and-request-handler/12605/4 "2024-06-21T16:49:38Z")

</div>

The desired behaviour in this case is that `handle = UpdateWorkflow(...)` blocks until the update is handled by the workflow or the workflow fails.

---

<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: [June 24, 2024, 12:13am UTC](https://community.temporal.io/t/communication-between-workflow-and-request-handler/12605/5 "2024-06-24T00:13:35Z")

</div>

You have to register the handler before it is called. So, register it at the beginning of the workflow function.

---

<div class="post-metadata">

### Author: ![Roman\_Gorkovets](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/roman_gorkovets/32/5502_2.png) [@Roman\_Gorkovets](https://community.temporal.io/u/Roman_Gorkovets)
#### Post date: [June 24, 2024, 3:43am UTC](https://community.temporal.io/t/communication-between-workflow-and-request-handler/12605/6 "2024-06-24T03:43:41Z")

</div>

So how is this approach different from queries? Because I register the update handler at the beginning of the workflow, the UpdateWorkflow method returns the result immediately. The only way to achieve “blocking” behavior is to use a go channel to write response to, when the response is ready. But, if I’m right, this is considered as non-deterministic.

---

<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: [June 24, 2024, 2:06pm UTC](https://community.temporal.io/t/communication-between-workflow-and-request-handler/12605/7 "2024-06-24T14:06:14Z")

</div>

Queries cannot block and cannot mutate the workflow state.

Update handler can block and can mutate workflow state. You can achieve blocking semantic using Temporal equivalent of Go channel as well as Future or Await condition.

---

<div class="post-metadata">

### Author: ![Roman\_Gorkovets](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/roman_gorkovets/32/5502_2.png) [@Roman\_Gorkovets](https://community.temporal.io/u/Roman_Gorkovets)
#### Post date: [June 24, 2024, 3:19pm UTC](https://community.temporal.io/t/communication-between-workflow-and-request-handler/12605/8 "2024-06-24T15:19:15Z")

</div>

Thank you for your response!
