Welcome to the Kinde community

Updated 2 months ago

Can KindeClient be a singleton in TS SDK?

At a glance
DO I need to create a KindeClient every time I need it? Or can I create it once and reuse it? Is it cheap to create it? Ill be using it for Management API purposes (like create Users and Orgs)
S
m
B
4 comments
It may depend on your SDK. I imagine the different implementations may have different performance tradeoffs and concurrency considerations.


Using .NET as an example...

Because I wasn't sure about how thread-safe the client was I went with creating an instance each time as the client didn't look too expensive to create.

However, one problem with creating an instance each is if you also call Authenticate() each time as it will issue a new access token chewing into the 500 machine tokens per month you have (across all environments).

The .NET SDK will cache your access token, but in memory. So if you need to restart the process regularly through regular dev activities (or running CI / CD pipelines) you will quickly burn those access tokens as each time it can't find a cache hit in memory it will use up a new monthly token.

I was lucky given the way the Kinde team implemented the SDK that I could modify their implementation (without having to fork their repo) to allow me to create some code which would modify the authentication behaviour so that I could persist this token somewhere more perminently (i.e. not in memory) and re-use it.
Good point Stephen! My question is regarding the Typescript SDK
Hi Maustache,

There should be no issues with creating and reusing a single Kinde client instance. I've used this pattern before - I create it and export it from the file it's created in, and just import the client instance wherever I need to use it πŸ™‚
Add a reply
Sign up and join the conversation on Discord