librelist archives

« back to archive

multi tenancy with Flask / SQL Alchemy

multi tenancy with Flask / SQL Alchemy

From:
Sjoerd Huisman | Congressus
Date:
2012-12-17 @ 10:58
Hi,

 

What are the best practises to implement a multi tenancy environment in
Flask? Flask-SQLAlchemy does not provide any service for this. We have a set
of models where some needs to be synchronised with one (our own) database
and other models need to be synchronised with the client database.
Multi-bind does not work, as the client is not yet known the first time as
the App launches.

 

-          One Flask App, One SqlAlchemy, One Session, Multiple Connections

-          One Flask App, One SqlAlchemy, Multiple Session, One Connection
each

-          One Flask App, Multiple SqlAlchemy, One Session each, Multiple
Connections

-          Multiple Flask Allps, One SqlAlchemy each, One Session each, One
Connection each

-          Or look into multi-threading and use one thread per tenant?

 

Hope you can shed some light on my issue!

 

Thanks

 

Sjoerd Huisman

Re: [flask] multi tenancy with Flask / SQL Alchemy

From:
Audrius Kažukauskas
Date:
2012-12-17 @ 14:06
On Mon, 2012-12-17 at 11:58:17 +0100, Sjoerd Huisman | Congressus wrote:
> What are the best practises to implement a multi tenancy environment in
> Flask? Flask-SQLAlchemy does not provide any service for this. We have a set
> of models where some needs to be synchronised with one (our own) database
> and other models need to be synchronised with the client database.
> Multi-bind does not work, as the client is not yet known the first time as
> the App launches.
> 
> - One Flask App, One SqlAlchemy, One Session, Multiple Connections
> - One Flask App, One SqlAlchemy, Multiple Session, One Connection each
> - One Flask App, Multiple SqlAlchemy, One Session each, Multiple
>   Connections
> - Multiple Flask Allps, One SqlAlchemy each, One Session each, One
>   Connection each
> - Or look into multi-threading and use one thread per tenant?

Haven't done this myself, so can only point you at this blog post[0],
which seems to be relevant.  You may also want to check SQLAlchemy usage
recipes[1] and mailing list archives[2].

[0] 
http://techspot.zzzeek.org/2012/01/11/django-style-database-routers-in-sqlalchemy/
[1] http://www.sqlalchemy.org/trac/wiki/UsageRecipes
[2] https://groups.google.com/forum/?fromgroups=#!forum/sqlalchemy

-- 
Audrius Kažukauskas
http://neutrino.lt/