How to intercept Weaviate client requests at a low level to implement circuit breaker pattern?

I’m using the Weaviate TypeScript client library and want to implement a circuit breaker pattern. Instead of wrapping each individual function that calls weaviate.client, I’d like to intercept the requests at a lower level - possibly at the client/connection level.

My current approach looks something like this:

const weaviateClient = weaviate.client({
  scheme: 'http',
  host: 'localhost:8080',
});

// Currently I would need to wrap each function like this
const searchWithCircuitBreaker = circuitBreaker.wrap(async () => {
  const result = await weaviateClient.graphql
    .get()
    .withClassName('Class')
    .withFields('field1 field2')
    .do();
  return result;
});

Is there a way to intercept all requests at the client level?
For example:

  • Intercepting the underlying HTTP client/requests
  • Wrapping the client initialization
  • Using some middleware functionality if available
  • Any other approach that would allow implementing circuit breaker at a lower level

The goal is to have a single point where all requests go through the circuit breaker without having to wrap each individual function call.

Any suggestions on how to achieve this with the JS/TS client v2?
Thank you!

hi @Petar_Ivanov !!

Welcome to our community!!

Do you know that our typescript v2 is on route to being deprecated, right?

So I believe it will be best to try this approach on v3, as any potential change we could do in client to allow that would only be implemented on v3 and forward.

I would need to escalate this with our client team, but wanted to run this version concern with your first.

Thanks!

1 Like

Hi @Petar_Ivanov! There is no way to achieve this at the lower-level wrapping the connection methods themselves directly. The best available to you is to wrap each method exposed by the client individually as you show in your code snippet.

However, I think this is an interesting feature request that would improve the usability of the client. If you post a description of this feature on the Github issue board for the JS/TS client then we will be able to look into it and assign resource to it. Thanks :grin:

3 Likes