accesspatterns.dev
← All models

saas

SaaS Multi-Tenant

Organisations and their members in one table, isolated by partition.

A single-table design where every item for an organisation shares the partition key ORG#<orgId>. Members live beside the org record, so the whole tenant reads in one Query.

The model

Organisation

A tenant.

pk
ORG#<orgId>
sk
ORG#<orgId>

Attributes: orgId (S), name (S), plan (S)

Membership

A user's membership of an organisation, with a role.

pk
ORG#<orgId>
sk
MEMBER#<userId>

Attributes: orgId (S), userId (S), role (S)

Access patterns

  • QueryGet organisation members

    List every member of an organisation.

  • GetItemGet an organisation

    Fetch a single organisation record.

Design notes

Isolation by partition keywhy

Every item for a tenant shares ORG#<orgId>, so a tenant's data never leaks into another's reads and the whole tenant is one Query away.

Org record beside its memberstrade-off

Storing the organisation under SK = ORG#<orgId> keeps it in the same partition as its members, so one Query can fetch the org and its people together.

Taught in the course

saas-multi-tenant

These rows are real and already here. Running an operation against them downloads a DynamoDB-compatible engine, about 850 KB, and executes it in this tab.

Try an example

List every member of an organisation.

PK(pk)
SK(sk)
name
plan
role
ORG#acme
MEMBER#u-adaS
ownerS
ORG#acme
MEMBER#u-bobS
adminS
ORG#acme
MEMBER#u-cleoS
memberS
ORG#acme
ORG#acmeS
Acme IncS
enterpriseS
ORG#globex
ORG#globexS
GlobexS
teamS

Run an operation to see the raw engine response.

table saas-multi-tenantkeys PK / SKitems 5

Transactions, streams, tags and TTL are among the operations the in-browser engine doesn't implement yet.