CASE STUDY 05Multi-tenant SaaSLive commercial product

NextLab

Four kinds of user, one database, and none of them may see each other

NextLab is a multi-tenant laboratory information system: a lab signs up, gets its own subdomain and branding, and runs its entire operation through it. Patient registration, test results, report generation, payments, staff permissions and analytics. It is a real product with real paying customers, not a demo.

Role
Full stack and infrastructure
Scale
1000+ active users
Model
Five subscription tiers
nextlab.com.pk
NextLab laboratory management platform landing page
The problem

A lab is not one user. There is the lab administrator who owns the account, the employees who register patients and enter results, the collection centres that take samples off site under the lab’s name, and the platform administrator above all of them. Each sees a different slice of the same data, and a leak between two labs would be a leak of patient records.

On top of that, every lab wants its own test templates, its own report layout, its own pricing and its own commission rules. Building that as configuration rather than as forks was the whole design problem.

Architecture
Four actor types resolve through one permission layer to a lab-scoped databaseLab adminowns the accountEmployeeX-Sub-TokenCollection centreX-CC-TokenPlatform adminsuper adminSubdomain tenancy + one permission layerresolves the lab, the actor and the feature gate, oncePostgreSQL, every row scoped by labrows also tagged with the employee or centre that created themLayered on topPartner labs + billingMarketing commissionsPer-employee commissionsDiscount limits + auditRolling receipt quotasBranded PDF reportsTest templates are global and read only; each lab adjusts through override layers, never copies,so a platform-wide correction still reaches every lab that has not deliberately overridden it.
What I did

Scoping enforced in one place, features layered on top

Each actor type authenticates through its own token header and resolves to the same lab through a single permission layer, so scoping is decided once instead of being re-implemented in every view. Employees gate on a permissions object, collection centres on a separate feature-permission object, and subscription tier gates the advanced features. Tenancy itself is resolved from the subdomain in middleware.

Test templates are global and read only to labs, which then adjust them through override layers rather than copies, so a platform-wide correction reaches every lab that has not deliberately overridden it.

On that base I built the commercial layer the labs actually asked for: partner-lab panels with billing and settlement statements, marketing manager commissions with an automatic ledger, per-employee commission on the receipts they create, discount authorisation with per-test and per-day ceilings and a full audit trail, and receipt limits as rolling thirty day quotas that reset themselves.

It runs as a Docker Compose stack on EC2 behind nginx, with Celery and Redis for subscription reminders, nightly database and media backups, and login throttling.

Results

What it does in production

MeasureBeforeAfterChange
Actor types, one permission layern/a4admin, staff, centre, platform
Subscription tiers soldn/a5trial through lifetime
Active usersn/a1000+paying laboratories
Backupsnonenightly, DB and mediaoffsite copy
See it
All workNext: GitOps platform