What is a tenant?
A tenant is primarily a company, an organization, or a workspace in your product that contains a group of users. A SaaS application provides services to multiple tenants. Tenant is the basic building block of all SaaS applications. Every SaaS feature and experience is built on top of tenants. Nile has built-in tenant virtualization, which makes it easy, reliable, and cost-effective to develop and support SaaS use cases across the globe.Creating a tenant
Tenant is the basic building block for SaaS and Nile. Nile’s Postgres comes with a built-in tenant table. This table has built-in columns to support common use cases out of the box but can also be extended to add more application-specific columns.id | name | created | updated | deleted |
---|
id | name | created | updated | deleted |
---|---|---|---|---|
018ac98e-b37a-731b-b03a-6617e8fd5266 | customer1 | 2023-09-24 23:38:07.097633 | 2023-09-24 23:38:07.097633 |
Adding data for each tenant
Once you have a tenant created, you can insert rows into different tables for a specific tenant. You can create a tenant aware table in Nile by creating a table with a ‘tenant_id’ column of type uuid. tenant_id is a reserved keyword. This is all it takes to ensure you get all the benefits of tenant virtualization in Nile’s Postgres. For example, if you were building an employee management software that helps with managing employee information, benefits and payroll, it would have an ‘employees’ table to track employees data.id | name | created | updated | deleted |
---|---|---|---|---|
018ac98e-b37a-731b-b03a-6617e8fd5266 | customer1 | 2023-09-24 23:38:07.097633 | 2023-09-24 23:38:07.097633 | |
018aca35-b8c4-7674-882c-30ae56d7b479 | customer2 | 2023-09-25 02:40:32.964067 | 2023-09-25 02:40:32.964067 |
tenant_id | id | name | age | address | start_date | title |
---|---|---|---|---|---|---|
018ac98e-b37a-731b-b03a-6617e8fd5266 | 1345 | Jason | 30 | Sunnyvale,California | 2016-12-22 19:10:25 | software engineer |
018ac98e-b37a-731b-b03a-6617e8fd5266 | 2423 | Minnie | 24 | Seattle,Washington | 2018-11-11 12:09:22 | sales engineer |
018ac98e-b37a-731b-b03a-6617e8fd5266 | 4532 | Shiva | 32 | Fremont, California | 2019-09-05 04:03:12 | product manager |
018aca35-b8c4-7674-882c-30ae56d7b479 | 5643 | John | 36 | London,UK | 2017-12-12 19:10:25 | senior software engineer |
018aca35-b8c4-7674-882c-30ae56d7b479 | 1532 | Mark | 27 | Manchester,UK | 2022-10-10 12:09:22 | support engineer |
018aca35-b8c4-7674-882c-30ae56d7b479 | 8645 | Sam | 42 | Liverpool,UK | 2015-08-04 04:03:12 | product manager |
Querying tenant data
SaaS applications only query a specific tenant data at any given of time. This requires isolating data to ensure user of one tenant does not read the data of another tenant. You can do this in Nile’s Postgres by simply using the nile.tenant_id session parameter in SQL or directly using our SDK. A good way to think about this is that setting the session context to a tenant is equivalent to pointing to a specific tenant DB. This ensures that all queries are directed to that specific tenant DB. At the same time, you still have access to shared tables (see shared table section).tenant_id | id | name | age | address | start_date | title |
---|---|---|---|---|---|---|
018ac98e-b37a-731b-b03a-6617e8fd5266 | 1345 | Jason | 30 | Sunnyvale,California | 2016-12-22 19:10:25 | software engineer |
018ac98e-b37a-731b-b03a-6617e8fd5266 | 2423 | Minnie | 24 | Seattle,Washington | 2018-11-11 12:09:22 | sales engineer |
018ac98e-b37a-731b-b03a-6617e8fd5266 | 4532 | Shiva | 32 | Fremont, California | 2019-09-05 04:03:12 | product manager |