Posts

Showing posts with the label Multi-Tenancy

Writing Multi-Tenant Data Isolation Code With LLMs in November 2026: Put a Tenant ID on Every Row, Take It From the Session, and Back It Up With Row-Level Security

Image
If your app has "workspaces," "organizations," "teams," or "accounts," you are running a multi-tenant system. Many customers share one database, and the most important promise you make is that one customer never sees another customer's data. An LLM will happily write you a projects table and a GET /projects endpoint in seconds. What it will not do unless you ask is make that endpoint impossible to point at somebody else's projects. This guide covers the shared-database, shared-schema model, where every tenant's rows live in the same tables and a tenant_id column tells them apart. It is the most common setup for small SaaS products, and it is where generated code most often leaks. The examples use PostgreSQL and plain SQL so they translate to any stack. One building, many residents, and each mailbox opens with only its owner's key. A multi-tenant database should work the same way. Image: Mailboxes, France by Philippe Alès, ...