# Separate jdbc persistent store for each customer (Multi-tenancy)

**URL:** <https://discuss.akka.io/t/separate-jdbc-persistent-store-for-each-customer-multi-tenancy/10070>\
**Category:** Persistence / Event Sourcing\
**Tags:** akka, akka-typed, configuration\
**Created:** [November 4, 2022, 9:49am UTC](https://discuss.akka.io/t/separate-jdbc-persistent-store-for-each-customer-multi-tenancy/10070 "2022-11-04T09:49:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gantamk](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/gantamk/32/2956_2.png) [@gantamk](https://discuss.akka.io/u/gantamk)\
**Post date:** [November 4, 2022, 9:49am UTC](https://discuss.akka.io/t/separate-jdbc-persistent-store-for-each-customer-multi-tenancy/10070/1 "2022-11-04T09:49:55Z")

</div>

Hello friends,

I must create a separate jdbc persistent store for each customer (Multi-tenancy). And I need to resolve this during runtime. I am OK with embedding the customer code in **persistentId** (e.g. ABCCustomer\_orders\_actor) and using the substring to resolve the respective db connection.

One closest option seems to be Customized loading of the db connection SlickDatabaseProvider. But it does not seem to be helpful, but only **config** is available from the abstract **database** method. I think this is called only once during init, so not suitable?

```auto
class CustomDatabaseProvider extends SlickDatabaseProvider {
  override def database(config: Config): SlickDatabase = {
    //My requirement: resolve the respective database of the customer.
  }
}

```

Is there any other way I can solve this problem?

Appreciate any kind help.  
MK

---

<div class="post-metadata">

**Author:** ![johanandren](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/johanandren/32/85_2.png) [@johanandren](https://discuss.akka.io/u/johanandren)\
**Post date:** [November 8, 2022, 4:38pm UTC](https://discuss.akka.io/t/separate-jdbc-persistent-store-for-each-customer-multi-tenancy/10070/2 "2022-11-08T16:38:34Z")

</div>

I think it is tricky to make it completely dynamic, but if up front listing of each customer db in config is workable I think you could make the persistent actor decide which journal plugin id to use at startup, based on parsing that out of the persistence id.

Look at `akka.persistence.RuntimePluginConfig` for classic persistence, or `Behaviors.setup` + `EventSourcedBehavior#withJournalPluginId` in `EventSourcedBehavior`/typed persistence.
