How do you share data between tenants?
While Nile provides a native approach to isolating data between tenants, it also supports sharing data across tenants using shared tables. For example- A corporate travel booking site like TripActions (https://www.navan.com/) or Concur helps company employees book flights and manage their trips. Every company that uses the product must see a list of available flights. The list of flights can be stored in a shared table accessible to all tenants in any location.
- A CRM product like Salesforce or Hubspot lists companies by categories that Sales reps can choose from for outreach. The list of companies and their categories is a global list that can be made available to all customers using shared tables.
- Your application is an Infrastructure SaaS product (e.g., Snowflake or Databricks) and wants to provide a list of cloud providers and regions for users to select where they want to deploy their infrastructure. The data about all the cloud providers and the available regions can be in a shared table, and all the tenants can access it.
Creating and inserting data into shared tables
To create a shared table, you must create a standard table without a tenant_id column. Nile ensures that the data in the shared table is available across all tenants.Querying data from shared tables
Since shared tables are just standard Postgres tables, all types of queries work on Shared tables. Selecting the flights that start from SFOid | name | from_location | to_location | departure_time | arrival_time |
---|---|---|---|---|---|
643 | United | SFO | NY | 2023-12-22 19:10:25 | 2016-12-23 05:10:25 |
id | name | from_location | address |
---|---|---|---|
643 | United | SFO | San Francisco, CA 94128 |
Joining data between tenant aware and shared tables
Tenant aware tables can be joined with shared tables to provide relevant information for a specific tenant. For example, let us consider a bookings table that has all the flights booked by employees of a specific company(or tenant) with id 7543a610-f068-45fa-8ba0-7bc884bd29c2. Each booking will refer to the flights id in the ‘flights’ table. It would be trivial to show detailed flight information along with every booking by joining the two tables.booking_id | employee_id | name | from_destination | to_destination | departure_time | arrival_time | total_price |
---|---|---|---|---|---|---|---|
1345 | 2 | United | SFO | NY | 2023-12-22 19:10:25 | 2016-12-23 05:10:25 | 200.00 |
2456 | 3 | Indian Airways | Mumbai | Delhi | 2024-11-23 19:10:25 | 2024-11-23 01:10:25 | 150.00 |
3240 | 4 | Indian Airways | Mumbai | Delhi | 2024-11-23 19:10:25 | 2024-11-23 01:10:25 | 250.00 |