Does loopback support MySQL multi-tenancy?

138 views
Skip to first unread message

Yuri Panchenko

unread,
Jan 7, 2015, 9:56:50 PM1/7/15
to loopb...@googlegroups.com
Hi guys,

We have 40 something databases/nodes (node groups) that share the same models.  For example, tables Business/Customer are all spread out across these databases.  Upon an update or a read, we need to be able to seamlessly read/write to/from these mysql databases based on a business id.  In other words, a business id determines which database/datasource to go to.  Is there anything in Loopback that can help with this?  Maybe something out of the box?

I know we can setup multiple datasources, but is there any support to do this tenancy read/write more or less seamlessly?

Thanks!

shuck...@gmail.com

unread,
Apr 23, 2015, 10:06:49 AM4/23/15
to loopb...@googlegroups.com
Hi,

have you already found a solution for this? We are interested in a solution for this as well.

In another post I read you can use
YourModel.attachTo(ds)
to switch a model's datasource at runtime.

My questions are:
  1. Does this work on a per request basis or does it change the datasource for other (parallel) requests as well?
  2. Is there a way to easily switch datasources for all associated models of the current datasource? Process should be something like this:
    1. There are three datasources in a loopback project: dsCentral, dsClient1 and dsClient2
    2. On each API call determine which client issued the request via user's role
    3. Set the "dsClientXY" datasource accordingly for all relevant models (except that ones used by dsCentral)

Would be great if that is possible! Thanks a lot!

shuck...@gmail.com

unread,
Jun 2, 2015, 2:50:57 AM6/2/15
to loopb...@googlegroups.com
Hi,

any news on this?

Best regards,
Sebastian

shuck...@gmail.com

unread,
Jul 26, 2016, 2:56:00 AM7/26/16
to LoopbackJS
Hi all,

we found a solution ourselves. Maybe it helps more people out there:

We used Loopback's environment specific configurations:
https://docs.strongloop.com/display/public/LB/Environment-specific+configuration

So instead of trying to bring multi-tenancy into one Loopback instance, we just spawned multiple instances with environment specific configurations (i.e. using different customer databases).
You can then use a reverse proxy (Nginx, Apache or whatever) to route each customer to the correct instance.
Reply all
Reply to author
Forward
0 new messages