1/ Some of the challenges with postgres-schema multitenancy stem from its *statefullness*.

In most solutions tenant switching relies on search_path and basically looks like this:
2/ More precisely: the challenges stem from the fact that the state lives in the current postgres session.

Example challenges: PgBouncer transaction mode, multiple threads, additional db connections.
3/ It's all solvable, but perhaps it could be more robust if we went for a little crazy idea to change ActiveRecord table names on the fly?
Of course it's just a PoC, perhaps it'd be an overkill to do on each request. Also, thread safety. Maybe we could monkey patch ActiveRecord's table name getter to to consult a variable.

Anyways, this wouldn't be fully stateless, but at least the state would now live in the app.
For more multitenancy ideas tune in today at 20:00 UTC: https://railsarchitects.com/conference/ 
An example of aformentioned "challenge":
You can follow @tomasz_wro.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.