# Managing Client

**URL:** https://community.temporal.io/t/managing-client/1972
**Category:** Community Support
**Tags:** go-sdk
**Created:** [April 21, 2021, 12:07am UTC](https://community.temporal.io/t/managing-client/1972 "2021-04-21T00:07:42Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Shannon\_Tan](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/shannon_tan/32/131_2.png) [@Shannon\_Tan](https://community.temporal.io/u/Shannon_Tan)
#### Post date: [April 21, 2021, 12:07am UTC](https://community.temporal.io/t/managing-client/1972/1 "2021-04-21T00:07:42Z")

</div>

I was working on writing tests using the mock.Client, but then I saw this thread discouraging global variables. How do large codebases manage the Client instance given that the Client instance is “heavy” and shouldn’t be instantiated more than once?

I’m aware this is a bit outside of the purview of Temporal, but it would be good to get community feedback on what’s worked for them. I’d also be curious on what “golang” advice the Temporal team has about it too.

> [@Creating a client after creating a worker](https://community.temporal.io/t/creating-a-client-after-creating-a-worker/1895):
>
> In the Go SDK, a client must be created before the worker can be created. This has the perhaps unintended side effect of forcing the client and worker to be created in the same function in order to defer closing the client. Is there any logical reason why the step of creating the worker, and then setting its client couldn’t be teased apart? Another way to ask the question is, does a Worker actually use the Client between being created and being run? Here’s something like what I’d like to be able…

---

<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 21, 2021, 7:33pm UTC](https://community.temporal.io/t/managing-client/1972/2 "2021-04-21T19:33:47Z")

</div>

I don’t see a problem with using a global variable in this case. Alternatives are either the use of some sort of IoC solution or manually pass a client instance to all the dependencies.
