liveBook · Manning

Multitenant SaaS application

As explained in Just Use Postgres!

A multitenant SaaS application is a software service that serves multiple customers from shared infrastructure while isolating their data and access.

A multitenant SaaS application serves multiple customers from shared CPUs and storage while isolating each tenant’s data and access. A merchant is one tenant; its business data remains private from other merchants. section 2.1.1

Postgres supports three common multitenancy layouts:

  • Table-level multitenancy stores all tenants in shared tables and distinguishes rows with a column such as tenant_id. section 2.1.1
  • Schema-level multitenancy gives each tenant dedicated tables within one logical database. section 2.1.1
  • Database-level multitenancy gives each tenant a dedicated database object, with access controlled through roles and permissions. section 2.1.1

Separate databases for two merchants

Treat a brewery and a coffee chain as separate tenants: CREATE DATABASE coffee_chain; CREATE DATABASE brewery; SELECT datname FROM pg_database; Connect to one tenant database with \\c coffee_chain. PostgreSQL then reports that the session is connected to coffee_chain, while the other tenant remains in its own database.

How Just Use Postgres! covers it

How deep it goes
Defines three Postgres multitenancy layouts and demonstrates database creation and connection, but defers detailed permission setup.
Examples
Uses a brewery, coffee chain, separate PostgreSQL databases, catalog output, and a tenant-specific connection prompt.
What it assumes
Assumes familiarity with Postgres and software engineering while introducing multitenancy patterns through a concrete SaaS scenario.
What you can do after
Operate/configure tenant isolation in Postgres by creating dedicated databases and connecting to a selected tenant database.
How it connects
Connects shared infrastructure with data isolation, schemas, databases, roles, and permissions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.