Multi-tenant with multiple databases?

63 views
Skip to first unread message

Steve P

unread,
Jun 9, 2015, 12:32:42 AM6/9/15
to nod...@googlegroups.com
I'm working on a multi-tenant app in which each client will have their own database, each having the identical schemas and I need to be able to swap out the database I'm connecting to on a per request basis. I've been able to find nothing regarding this ability as near as I can tell the db connection is set at boot time.

This is surely possible with Node, right?

Aria Stewart

unread,
Jun 9, 2015, 12:57:08 AM6/9/15
to nod...@googlegroups.com

> On 8 Jun 2015, at 23:38, Steve P <stevea...@gmail.com> wrote:
>
> I'm working on a multi-tenant app in which each client will have their own database, each having the identical schemas and I need to be able to swap out the database I'm connecting to on a per request basis. I've been able to find nothing regarding this ability as near as I can tell the db connection is set at boot time.
>
> This is surely possible with Node, right?

Yes!

You're probably overthinking it: the simplest increment from 'connect at boot time to one database' is 'connect at boot time to all the databases, and pick the right connection at request time'.

From there it's a small step to make that lazily connect -- if there's a connection, use it. If not, create it and use it.

You may want to look at connection pooling libraries in the registry. They may help this.

Aria

Steve P

unread,
Jun 10, 2015, 2:10:04 PM6/10/15
to nod...@googlegroups.com
Thank you very much Aria!! Coming from a PHP background Node is a complete change of pace! 

Gustavo Machado

unread,
Jun 22, 2015, 10:22:23 AM6/22/15
to nod...@googlegroups.com
Not sure how many tenants you plan to have in memory, but you should probably check out some (memory) caching libraries.

Cheers,
Gus


--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/F61C93AE-BF6E-4544-9AEA-EDD37D9C7032%40dinhe.net.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages