N
Neon5mo ago
inland-turquoise

Multi-database vs RLS

Hey all, I am working on a project that involves an organization signing up and then multiple customers will be signing in per organization. I want to introduce multi-tenancy in this project such that all customers of an org share the same database and this is isolated from other orgs. The Neon docs recommend project per user/org approach. I was wondering if just applying RLS would suffice. Any recommendations are helpful.
1 Reply
ambitious-aqua
ambitious-aqua5mo ago
Both would work, but there might be reasons you might prefer one over the other Downsides of RLS: 1. RLS is tricky to get correct and tricky to test. 2. RLS can slow down queries as each query must perform extra checks 3. There is no isolation of data with RLS. Two organisations might have data in the same "page", which might not be suitable according to certain compliance/disaster recovery requirements. 4. No horizontal scaling. Having a separate DB per org can be a great chance to horizontally scale - good while we don't have multi-master partitioning support 5. Less cost insights. We only break down cost per project, so you wont be able to see which organisation is causing the highest cost usage. Downsides of multi-database: 1. Schema management is tricky 2. Might have a higher cost depending on autoscaling configuration. If all databases get low utilisation, they might be wasting compute time 3. More integration effort. You will need to integrate with the Neon API, rather than just using standard postgres features.

Did you find this page helpful?