Using Namespace for Multitenancy

We want to create a multi-tenant application, where for each tenant we want to create a namespace when the tenant is onboarded to the application.

Is it feasible to create a namespace dynamically, and use it?

If it is does it require worker restart. Is it recommended in production?

You can create a new namespace via tctl, or programmatically, see this post for examples.

Once the namespace is created you can set up you workers that listen to task queues on that new namespace. You should not have to restart your current workers if that is the question.

Namespace is unit of isolation in Temporal, and you can definitely have multiple namespaces setup in your prod environment.

Note that at this time, namespace deletion is not yet supported, follow this issue to track the progress on that.


How can we prevent resource starvation when running multiple applications on a single server across namespaces?

Say, Application 1 in namespace 1 is doing heavy processing and impacting other applications in other namespaces.
How can this be prevented?

Or are we saying, auto-scaling should deal with this problem?

Temporal frontend service has a per-namespace rate limiting knob which can be useful in this scenario.

Here is an example for a specific namespace:

      - value: 1500
          namespace: "<namespace here>"

Another thing is making sure you have the DB capacity to handle multiple apps as persistence is across namespaces, as well as making sure you set up server metrics to monitor and alert on possible issues.

1 Like

Hi @tihomir
How can we register multiple namespaces in one go.
Let’s say I need 3 namespace , how the workers would be started ?
Will it need 3 ServiceStub?

I think you would have to run tctl command for each of the namespaces you want to create

tctl --ns mynamespace1 n re
tctl --ns mynamespace2 n re
tctl --ns mynamespace3 n re

or use the RegisterNamespaceRequest as shown here for each namespace.

Will it need 3 ServiceStub?

Let me know if this is the same question as here.

1 Like

Yes @tihomir that’s the same question.
Thanks for your prompt response.

What is the max number of namespaces that can be created, I know we might not reach the limit, but wanted to know for testing purposes.

Temporal server does not enforce a max number of namespaces. Total number however will depend on the capacity of your cluster. You would need to test to reach this max on your env to know what it might be.