This case study is for founders and CTOs building a product that many customers will use, each in their own branded space. The platform lets creators open an online store, sell digital products and get paid, with every store running on one codebase. It runs on Node.js and PostgreSQL and takes payments through Razorpay, Cashfree and Stripe.
The product at a glance
A creator signs up and gets a store at their own link, or on their own domain. They add digital products such as files, courses and memberships, set a price and share the link. A buyer opens the store, pays and gets access straight away. The platform handles checkout, delivery and the creator’s earnings.
Each creator is a customer who expects the store to look like theirs, and who expects that no other creator will ever see their buyers or their sales. The business wants to run one product instead of a separate copy for every creator. So the system has 3 jobs: keep every store separate, take payment and deliver instantly, and keep the money records exact.
The first decision: how to separate tenants
In a multi-tenant product, a tenant is one customer account, here one creator’s store. There are 3 common ways to keep tenants apart in the database.
| Model | How it works | Suits | Cost |
|---|---|---|---|
| Database per tenant | Every store gets its own database | A few large customers with strict data rules | Migrations, backups and monitoring multiply with every tenant |
| Schema per tenant | One database, one set of tables per store | A middle ground | The same problem at a smaller size, and migrations still run once per tenant |
| Shared schema | One set of tables, with a tenant ID on every row | Many small tenants | One missed filter can leak data, so isolation must be enforced in code |
We chose the shared schema on PostgreSQL. Creator stores are small and numerous, and opening a new store should be an insert, not an infrastructure job. A migration runs once for everyone.
The trade-off is that isolation relies on every query being scoped correctly. Most of the rest of the design exists to make that automatic. The tenant ID also keeps an exit open: if one customer later needs a database of their own, their rows can be moved out.
The architecture

The parts are split by who uses them and how long they can wait.
- Tenant resolver. Runs first on every request and decides which store this is.
- Storefront. Serves public store pages. These are cached per tenant, because most visits only read.
- Dashboard and API. Where creators manage products, orders and settings.
- Checkout. Creates orders, starts payments and grants access.
- Cache and queues. Hold what must be fast: cached pages, rate limits and the job queue.
- Background workers. Do whatever can happen after the response: payment webhooks, emails, delivery and payouts.
- Database and file storage. PostgreSQL is the source of truth. Uploaded files sit in private AWS S3 storage, never at a public address.
The technology
| Layer | What we used | What it does here |
|---|---|---|
| Application | Node.js | The API, webhook handlers and background workers |
| Database | PostgreSQL | One shared schema, row-level security, and transactions for orders and the ledger |
| Payments | Razorpay, Cashfree and Stripe | Taking payments and sending signed webhooks |
| File storage | AWS S3 | Private product files, served through signed links |
| AWS SES and a second email service | Order emails and download links | |
| Hosting | DigitalOcean servers | The application and the workers |
| Error tracking | Sentry | Exceptions and alerts, tagged with the tenant ID |
| Monitoring | Uptime and alert checks | Outside checks on the store and checkout pages |
Finding the tenant on every request

A request arrives on a store link or a custom domain. The first step maps that host to a tenant ID, from cache first and from the database on a miss. An unknown host gets a not-found page, which is also cached briefly so guessed domains can’t hammer the database.
Once the tenant is known, the ID is set once for the whole request, and the data layer adds the filter itself. Developers don’t write WHERE tenant_id = ... by hand, so they can’t forget it. A query that runs without a tenant scope fails instead of returning every store’s rows.
Custom domains follow the same path. The creator adds a domain, the platform checks the DNS record and issues a certificate, and from then on the host resolves to their tenant like any other.
Keeping tenants apart in the places people forget
Data can leak from more than the database. Cache keys, file paths and background jobs need the same scoping, and tests check all of it.
- Cache keys. Every key starts with the tenant ID. A shared key is the classic leak: one store’s page served to another store’s visitors.
- File paths. One folder per tenant. Downloads go through signed, expiring links, never public URLs.
- Background jobs. Each job carries its tenant ID and sets the scope before it runs. A job that forgets it fails.
- Tests. We write tests that sign in as one tenant and try to read another’s data through every endpoint. Those tests fail whenever someone adds an endpoint and forgets the scope.
PostgreSQL row-level security adds a second lock underneath the application. Each request sets its tenant ID on the database connection, and the database refuses rows that belong to anyone else, so a bug in the application layer doesn’t expose data.
From payment to access

A common mistake in a store like this is treating the redirect back to the site as proof of payment. Buyers close tabs and lose connections, and a redirect can be faked. So the order is marked paid only when the payment provider’s signed webhook arrives.
We support 3 gateways: Razorpay, Cashfree and Stripe. Each one sits behind the same small interface (create a payment, verify a webhook, refund), so the checkout and order code don’t know which gateway they are talking to. Signature checking is written per gateway, because each one signs its webhooks differently.
The webhook handler does 3 things before it changes anything. It checks the signature, confirms that the amount and currency match the order, and checks the order hasn’t already been paid. Gateways retry webhooks, so the handler is safe to run twice. We store every event ID, which makes the duplicate check a single lookup, and the same event gives the same result and one access grant.
Delivery then goes through a worker. The buyer gets an email with a signed S3 link that expires, and the file itself stays private. If any check fails, the order stays unpaid and an alert is raised, so a person can look at it.
Keeping the money records exact
Every paid order writes entries to a ledger: one for the creator’s earning and one for the platform’s fee. Entries are never edited. A refund is a new entry that reverses the original. A creator’s balance is the sum of their own ledger, so any balance can be rebuilt and checked.
Fee changes apply to new orders only, so past earnings never move. A ledger takes a little more storage than a balance column, but it turns “why is my balance this number?” from an investigation into a query.
When something fails
Payments, emails and file delivery all depend on outside services, so failures will happen. We handle them in 4 layers.
- One exception handler. Every error in the Node.js application ends up in a single handler. It returns a clean response to the user without internal details, and writes a structured log entry with the tenant ID and a request ID, so one failed purchase can be traced from the log to the store.
- Sentry. Exceptions are sent to Sentry with the tenant ID attached, so an alert says which store is affected and how many others are.
- Retries and a dead-letter queue. A failed job, such as an email or a webhook that couldn’t be processed, is retried with a growing delay. After the last attempt it moves to a dead-letter queue, where it waits for review and can be replayed once the cause is fixed. Nothing is dropped silently.
- Uptime and alert checks. Outside checks request the store and checkout pages and alert a person when they fail, so we hear about an outage from a monitor and not from a creator.
One busy creator shouldn’t slow everyone else
On a shared platform, one creator can share their link with a large audience and every other store feels it. We contain this in 3 ways.
- Store pages are cached per tenant, so a spike mostly reads from memory.
- Checkout and sign-in are rate limited per tenant and per buyer.
- Heavy work such as emails, delivery and exports goes to queues, with limits per tenant, so one store’s backlog can’t starve everyone else’s jobs.
Customising stores without custom code
Each store’s look and behaviour is data: logo, colours, layout choices, domain and plan limits. There are no per-customer branches in the code. Features that depend on a plan are switched by flags read from the tenant’s settings.
Our rule is that if a request needs code only one customer will use, we either add a setting for it or decline. Per-customer code means every release has to be tested against it.
What founders can take from this
- Choose the tenancy model before the first table. Changing it later means migrating every customer’s data.
- Make isolation automatic. Anything that relies on every developer remembering a filter will fail eventually.
- Scope everything, not only the database. Cache keys, file paths and background jobs leak as easily as queries.
- Treat the payment webhook as the truth. Make the handler safe to run twice, and keep every gateway behind one interface.
- Plan for failure. Decide what happens to a failed job before the first one fails, and send errors somewhere a person will see them.
- Plan for the loud tenant. Limits and caching per tenant are cheap to add early and painful to add during an incident.
If you’re building a platform where many customers share one product, see Custom Software & Web Apps. If you’re deciding whether version 1 needs multi-tenancy at all, see MVP Development.