Data partitioning and retention
Prerequisite: node-tenant-isolation. Objective: Compare fictional tenant models. Each example is independent. Tested with Node.js 22.16.0 on Linux. Save as main.mjs in a fresh disposable directory and run node main.mjs. These are static code blocks; external system behavior is not established by a local model.
How it works
Pooled tables simplify fleet migrations but share resources. Database-per-tenant can improve recovery granularity and reduce certain blast radii, while increasing connection, provisioning and update complexity. Define retention by data class, tenant agreement and legal hold; deletion from primary storage does not necessarily remove backups or audit records. Use bounded batches and verify each tenant scope. A retention date is a policy input, not a universal legal rule.
Select eligible retention candidates
import assert from 'node:assert/strict';const rows=[{id:'a',tenant:'t1',day:2,hold:false},{id:'b',tenant:'t1',day:1,hold:true},{id:'c',tenant:'t2',day:1,hold:false}];const eligible=rows.filter(r=>r.tenant==='t1'&&r.day<5&&!r.hold).map(r=>r.id);assert.deepEqual(eligible,['a']);console.log(eligible.join(','));Expected output:
aOnly one scoped record is eligible; no deletion occurs.
Calculate a connection budget
import assert from 'node:assert/strict';const tenants=20,poolPerTenant=4,replicas=3,limit=120;const upperBound=tenants*poolPerTenant*replicas;assert.equal(upperBound,240);console.log(upperBound,upperBound<=limit);Expected output:
240 falseSeparate pools can exceed database capacity before traffic peaks.
Common mistake
Do not delete all old records without checking holds, ownership and recovery requirements.
Practice
Given a fixed cutoff, identify records eligible for deletion and record excluded legal-hold items.
Reference candidate: node-data-partitioning-and-retention-lookup (route unverified). Documentation anchors: https://www.postgresql.org/docs/18/ddl-rowsecurity.html. External versions and full integration are pending.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Data partitioning and retention — knowledge check
Apply the lesson to a fresh scenario and explain the evidence boundary.
What trade-off can separate databases introduce?
Which record must be excluded from a normal purge?
Does deleting a primary row erase all copies?