← All write-ups

Building a Multi-Tenant E-Commerce Platform with Next.js and NestJS

E-Commerce & SaaS Platform3 min read·Case study: MiniMart

Many small retailers and WhatsApp sellers need their own branded online store, a way to track stock across the shop counter and the website, and protection from Cash-on-Delivery orders that get rejected at the door. This page explains the engineering decisions behind MiniMart, a multi-vendor platform I built to solve exactly that.

1The problem: many stores, one platform

A multi-tenant platform serves many independent merchants from a single codebase and database. Each merchant expects a storefront that feels like their own, and each must never see another merchant's data.

The hard parts are keeping data strictly separated, keeping pages fast as the number of stores grows, and letting a merchant go live in minutes rather than days.

2Tenant isolation with PostgreSQL and Prisma

Every record that belongs to a store carries a store ID. Tenant-aware middleware resolves which store a request is for, and Prisma queries are scoped to that store ID so a query cannot accidentally return another tenant's rows.

Database indexes include the store ID, which keeps lookups fast even when the products and orders tables grow large.

  • Resolve the tenant once per request in middleware
  • Scope every query by store ID
  • Index on store ID for predictable query performance

3Instant storefront routing with Redis

Each store is reachable through its own slug. Looking the slug up in the database on every page view is wasteful, so slug resolution and session validation are cached in Redis. This keeps storefront pages responsive and lets a new store start serving traffic as soon as it is created.

4One inventory for the shop counter and the website

Retailers often sell in person and online at the same time. MiniMart treats the Point of Sale and the online catalog as two views of one inventory, so a sale at the counter reduces the stock a customer sees online, and the other way around.

Orders move through a clear five-stage workflow: New, Confirmed, Processing, Dispatched and Delivered. Customers can follow their order through a tracking link.

5Reducing losses from rejected Cash-on-Delivery orders

When a buyer refuses a parcel at the door, the seller pays for delivery and for the return. MiniMart scores each order using phone-number delivery history and merchant signals so likely rejections can be flagged before the parcel is dispatched.

The goal is not to block customers automatically, but to give the merchant a clear warning so they can confirm the order first.

6Making it fast on mobile networks

Streaming server rendering in the Next.js App Router can show content before external CSS has finished loading on slow cellular connections, which causes layout shifts. I inlined the critical styles for fallback states, loaded the main stylesheet from the root layout and prioritised key images, which brought the site to a 97+ desktop performance score and a 100/100 SEO score in PageSpeed.

7Tech stack

Next.js 16 and React 19 on the front end, NestJS on the back end, PostgreSQL with Prisma for data, Redis for caching, WebSockets for live updates, Tailwind CSS for styling and Docker for deployment.

Need something similar built?

I build and ship platforms like this for startups and retailers. Tell me what you are trying to launch and I will reply with how I would approach it.