# Async executor and multitenancy

**URL:** <https://forum.flowable.org/t/async-executor-and-multitenancy/12281>\
**Category:** Flowable Engine\
**Created:** [June 10, 2025, 7:46am UTC](https://forum.flowable.org/t/async-executor-and-multitenancy/12281 "2025-06-10T07:46:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![desp.kaz](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@desp.kaz](https://forum.flowable.org/u/desp.kaz)\
**Post date:** [June 10, 2025, 7:46am UTC](https://forum.flowable.org/t/async-executor-and-multitenancy/12281/1 "2025-06-10T07:46:47Z")

</div>

Hello,  
in my spring boot app I use MultiSchemaMultiTenantProcessEngineConfiguration to implement multitenancy.  
I have some rabbit listener which listens when a new tenant exists and registers it with registerTenant method of MultiSchemaMultiTenantProcessEngineConfiguration.class.  
I was wondering if there we any sequences if registerTenant runs twice (e.g. by different threads) for the same tenant and datasource.  
I use

```auto
config.setDatabaseSchemaUpdate(AbstractEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);

```

so I guess the schema will be ok, but how about the async executor (I have ExecutorPerTenantAsyncExecutor)?  
I tried to reproduce the case and it seems that only one is created per tenant.

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [June 10, 2025, 8:56am UTC](https://forum.flowable.org/t/async-executor-and-multitenancy/12281/2 "2025-06-10T08:56:29Z")

</div>

Hey @desp.kaz,

You’ll need to implement your own logic to avoid registering an already registered tenant. I would say that it is not advisable to call the `registerTenant` twice from different threads in the same time.

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![desp.kaz](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@desp.kaz](https://forum.flowable.org/u/desp.kaz)\
**Post date:** [June 10, 2025, 9:00am UTC](https://forum.flowable.org/t/async-executor-and-multitenancy/12281/3 "2025-06-10T09:00:53Z")

</div>

Thanks for the answer Filip!  
My initial problem was that I may have many kubernetes pods(instances of the app) that should all be aware of the tenants. If only one pod calls the registerTenant method at my listener then I guess that tenantAwareDataSource won’t be updated for the others, right?

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [June 10, 2025, 9:26am UTC](https://forum.flowable.org/t/async-executor-and-multitenancy/12281/4 "2025-06-10T09:26:34Z")

</div>

> [@desp.kaz](#):
>
> If only one pod calls the registerTenant method at my listener then I guess that tenantAwareDataSource won’t be updated for the others, right?

Yes indeed, the `tenantAwareDataSource` is a based on a single node implementation. If you have a multi node scenario with a dynamic configuration of those tenants then you should implement something on your own.

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![desp.kaz](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@desp.kaz](https://forum.flowable.org/u/desp.kaz)\
**Post date:** [June 10, 2025, 11:00am UTC](https://forum.flowable.org/t/async-executor-and-multitenancy/12281/5 "2025-06-10T11:00:31Z")

</div>

Thanks!  
Just one last question, at my custom implementation the async executor must be created once? Or does it make sense to have one per instance-pod?  
I am not entirely sure how this works exactly.

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [June 10, 2025, 1:23pm UTC](https://forum.flowable.org/t/async-executor-and-multitenancy/12281/6 "2025-06-10T13:23:25Z")

</div>

It should be one per instance / pod. Otherwise, only one pod will be able to handle async jobs for that particular tenant.

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![dragan\_torbica](https://avatars.discourse-cdn.com/v4/letter/d/47e85d/32.png) [@dragan\_torbica](https://forum.flowable.org/u/dragan_torbica)\
**Post date:** [June 20, 2025, 7:38am UTC](https://forum.flowable.org/t/async-executor-and-multitenancy/12281/7 "2025-06-20T07:38:20Z")

</div>

you may consider using hazelcast  
it does many things and they are pushing it towards ML-AI as all companies do (that part I have no experience with),

we use the open-source version for data-synch between kubernetes pods and that works great: [Distributed Map | Hazelcast Documentation](https://docs.hazelcast.com/hazelcast/latest/data-structures/map)

in our experience, it is way easier than making your own fault-tollerant synch with redis (something i saw in quite a few of projects, and it always caused issues since people building it cover the happy-path but do not know how to build fault-tolerant distributed systems..)

---

<div class="post-metadata">

**Author:** ![desp.kaz](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@desp.kaz](https://forum.flowable.org/u/desp.kaz)\
**Post date:** [June 20, 2025, 8:33am UTC](https://forum.flowable.org/t/async-executor-and-multitenancy/12281/8 "2025-06-20T08:33:55Z")

</div>

Thanks! I’ll have a look
