For my multi tenant application i am trying to work out how i can make connection pools per tenant. While stil using
one rails app.
Advantages of making it possible to connect with different usernames/credentials per request.
With supplying a per-request user. We can force database level security (for instance schema based isolation)
With supplying per request user connection. we can force the postgres 9.5**. row level security.**
This boils down to being able to have a connection pool per user/tenant/connectionspec in active record.
Unfortunately this is extremely difficult thing to do:
Right now i’ve monkey patched connection handler in order to create separate connection pools per tenant. But of course
this is really sup optimal. I see a couple of things that could be done to make this extensible for once and for all:
Make it possible to make connection handler pluggable. I’ve tried to do this, but documentation is lacking and i can’t seem to get it work.
Make it possible to create connection pools based on specs.
There are a couple of gems like apartment, multidb and other which are just bunch of difficult monkey patches in order to get
this desired behavior.
I hope i made myself clear a bit,