# Working in multi thread environment with connection pool

**URL:** <https://forum.weaviate.io/t/working-in-multi-thread-environment-with-connection-pool/21054>\
**Category:** General\
**Created:** [May 15, 2025, 7:47am UTC](https://forum.weaviate.io/t/working-in-multi-thread-environment-with-connection-pool/21054 "2025-05-15T07:47:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![eilon\_shai](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/eilon_shai/32/7274_2.png) [@eilon\_shai](https://forum.weaviate.io/u/eilon_shai)\
**Post date:** [May 15, 2025, 7:47am UTC](https://forum.weaviate.io/t/working-in-multi-thread-environment-with-connection-pool/21054/1 "2025-05-15T07:47:49Z")

</div>

HI,

We are new to weaviate, we are implementing a multi threaded service and we want to integrate weaviate client in it.  
I tried to find information regarding connection pooling and connection management in the documentation but didnt find clear summary of this topic.

can you please answer the following questions:

1. what is the recommended approach when working with weaviate, should I open and close connection after each request?
2. is there a build in connection pooling mechanism in the framework?
3. does weaviate client is thread safe, can I use the same client (and connection pool, if exists) across threads?

Thanks,  
Eilon

---

<div class="post-metadata">

**Author:** ![Shahin](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/shahin/32/7944_2.png) [@Shahin](https://forum.weaviate.io/u/Shahin)\
**Post date:** [May 15, 2025, 10:25am UTC](https://forum.weaviate.io/t/working-in-multi-thread-environment-with-connection-pool/21054/2 "2025-05-15T10:25:17Z")

</div>

Good morning @eilon_shai,

It’s lovely to have you here and welcome to your community! 🥳

That’s great questions so I will use the Weaviate Python client — similarly applies to JS/TS.

We advise you working with singleton pattern. When using a singleton client, requests use connections from a pool, managed by the underlying gRPC or HTTP libraries. Each request will borrow a connection, complete the operation, and return it to the pool.

- Closing the client object (via client.close()) invalidates the entire connection pool, affecting all active requests. So you should avoid closing the client after each request when using the singleton pattern.
- Creating a new client for each request is inefficient since each request will have its own connection pool, leading to resource overhead and slower performance.

In Weaviate’s context, using the singleton pattern for the client ensures that multiple requests can efficiently share the same underlying connection pool, preventing unnecessary overhead and improving the overall performance of the application. It’s recommended to create a single client object and share it throughout your application using the singleton pattern.

The Python client does concurrent requests in the background, which can significantly speed things up if your server is beefy enough. With the Go client, you would need to build the concurrency yourself.

In summary, for optimal performance with multiple concurrent processes, it’s best to use the singleton pattern, managing client connections based on the application’s lifecycle rather than on a request-by-request basis.

Here are some examples from my own scripts/snippets in my Github of Singleton pattern which you can use as initial or reference:

> **[GitHub - Shah91n/WeaviateDB-Docs-Snippets-Python-Client: Weaviate DB Operations Code Snippets For Python...](https://github.com/Shah91n/WeaviateDB-Docs-Snippets-Python-Client)**
>
> Weaviate DB Operations Code Snippets For Python Client

> <https://github.com/Shah91n/WeaviateDB-Docs-Snippets-Python-Client/blob/main/Singleton_Pattern_Python_Weaviate_Client.ipynb>

> <https://github.com/Shah91n/WeaviateDB-Docs-Snippets-Python-Client/blob/main/Connection_Methods.ipynb>

Best regards,

Mohamed Shahin  
Weaviate Support Engineer  
(Ireland, GMT/UTC timezone)

---

<div class="post-metadata">

**Author:** ![eilon\_shai](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/eilon_shai/32/7274_2.png) [@eilon\_shai](https://forum.weaviate.io/u/eilon_shai)\
**Post date:** [May 15, 2025, 11:00am UTC](https://forum.weaviate.io/t/working-in-multi-thread-environment-with-connection-pool/21054/3 "2025-05-15T11:00:59Z")

</div>

Thank you Mohamed, I will go over the solution  
very appreciate the detailed answer

---

<div class="post-metadata">

**Author:** ![Dirk](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dirk/32/46_2.png) [@Dirk](https://forum.weaviate.io/u/Dirk)\
**Post date:** [May 15, 2025, 11:29am UTC](https://forum.weaviate.io/t/working-in-multi-thread-environment-with-connection-pool/21054/4 "2025-05-15T11:29:54Z")

</div>

Hey,

couple additional points:

> - does weaviate client is thread safe, can I use the same client (and connection pool, if exists) across threads?

Yes, but NOT for batching (eg client.batch or collection.batch) - it also would not speed up things.

We also offer an async api that we’d recommend over multi-threading: [Async API | Weaviate](https://weaviate.io/developers/weaviate/client-libraries/python/async)

> connection pool

You can set (some of) the configs of the underlying `httpx` client using the following:

```auto
with weaviate.connect_to_local(
  ... , 
  additional_config=wvc.init.AdditionalConfig(connection=wvc.init.ConnectionConfig())) as client:

```

---

<div class="post-metadata">

**Author:** ![eilon\_shai](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/eilon_shai/32/7274_2.png) [@eilon\_shai](https://forum.weaviate.io/u/eilon_shai)\
**Post date:** [May 15, 2025, 11:38am UTC](https://forum.weaviate.io/t/working-in-multi-thread-environment-with-connection-pool/21054/5 "2025-05-15T11:38:39Z")

</div>

Thank you Dirk, can you please provide a complete example of usage with the async API

---

<div class="post-metadata">

**Author:** ![Dirk](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dirk/32/46_2.png) [@Dirk](https://forum.weaviate.io/u/Dirk)\
**Post date:** [May 15, 2025, 11:43am UTC](https://forum.weaviate.io/t/working-in-multi-thread-environment-with-connection-pool/21054/6 "2025-05-15T11:43:38Z")

</div>

There are a couple of examples here: [weaviate-python-client/integration/test\_collection\_async.py at main · weaviate/weaviate-python-client · GitHub](https://github.com/weaviate/weaviate-python-client/blob/main/integration/test_collection_async.py)

---

<div class="post-metadata">

**Author:** ![eilon\_shai](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/eilon_shai/32/7274_2.png) [@eilon\_shai](https://forum.weaviate.io/u/eilon_shai)\
**Post date:** [May 15, 2025, 11:47am UTC](https://forum.weaviate.io/t/working-in-multi-thread-environment-with-connection-pool/21054/7 "2025-05-15T11:47:50Z")

</div>

👍 Thank you, will follow
