Delivered remotely for a business based in Montreal, Canada. Names withheld by agreement.
Project Overview
Merchant teams launching specialty retail storefronts face an uncomfortable divide: monolithic SaaS templates restrict layout expression and checkout flexibility, while fully custom headless builds demand dedicated frontend engineers for routine seasonal campaign pages. For a commerce platform team operating out of Montreal, we engineered a multi-tenant e-commerce website builder that unifies a schema-driven visual storefront studio with a resilient headless commerce backend.
Built on Next.js, Node.js, and PostgreSQL, the platform enables brands and digital agencies to compose responsive storefronts using modular merchandising blocks, connect live variant catalogs, map custom domains with automated TLS certificates, and process localized payments through a single web studio and API layer.
Storefront & Platform Bottlenecks
Prior attempts by merchant aggregators to offer customizable web builders routinely ran into structural limits across rendering, isolation, and catalog integrity:
- Fragile HTML blob storage: Saving raw WYSIWYG markup directly in the database caused layout breakage whenever design tokens or responsive grid rules updated.
- Cold SSR latency spikes: Rendering personalized hero banners, currency selectors, and variant availability dynamically on every page view overwhelmed origin databases during promotional drops.
- Custom domain provisioning delays: Manual certificate issuance and DNS verification queues stalled merchant launches and generated repetitive support tickets.
- Noisy-neighbor checkout contention: High-volume flash sales on one storefront risked exhausting shared database connections and delaying carts for unrelated tenants.
Architectural Strategy
We decoupled presentation composition from transactional commerce execution. Inside the studio, every page section—hero carousels, faceted collection grids, bundle builders, and editorial lookbooks—is represented as a strongly typed JSON node governed by a versioned component registry. Merchants manipulate props and responsive breakpoints visually, while Next.js renders pre-validated React Server Components without executing arbitrary untrusted scripts.
Transactional state—SKU inventory locks, tiered tax calculation, discount stacking, and order settlement—runs through dedicated Node.js Fastify services backed by PostgreSQL. Row-Level Security guarantees tenant boundaries at the storage engine level, while Redis coordinates distributed cart locks and targeted cache-tag invalidation whenever a merchant edits prices or hits publish.
Core Capabilities
- Schema-Validated Visual Page Studio: Drag-and-drop Next.js editor supporting draft previews, rollback snapshots, reusable global headers/footers, and desktop/mobile breakpoint overrides.
- Multi-Tenant Domain & Edge Routing: Automated CNAME verification via Cloudflare for SaaS, issuing edge SSL certificates and resolving vanity hostnames to tenant configurations in sub-millisecond middleware lookups.
- Variant-Aware Catalog & Pricing Engine: Supports multi-option SKUs, digital and physical fulfillment rules, regional currency rounding, and scheduled promotional price lists.
- Composable Checkout & Tax Orchestration: Server-side cart validation, Stripe Connect split payouts, shipping rate aggregation, and idempotent payment webhook reconciliation.
- Extensible Storefront Webhook & App APIs: Signed outbound event streams notifying merchant ERP, email marketing, and warehouse tools on order creation, refund, or stock depletion.
Technical Architecture
Incoming shopper traffic hits Cloudflare edge routing, passes through Next.js host-resolution middleware, and serves cached Server Component payloads whenever presentation and catalog tags remain fresh. Mutating operations—cart updates, promo code validation, and payment intents—bypass static caches and hit Node.js APIs backed by Redis and PostgreSQL.
Flow: Custom Domain Traffic → Cloudflare TLS Edge → Next.js Host Middleware & ISR Cache → Node.js Fastify Commerce API → Redis Cart/Rate Bus & PostgreSQL RLS Ledger → BullMQ Webhook & Search Workers
Separating read-heavy storefront rendering from write-heavy checkout services lets edge nodes absorb traffic surges effortlessly while keeping PostgreSQL focused on strict ACID inventory decrements and financial records.
Technology Stack
| Category | Technology detail |
|---|---|
| Storefront Runtime | Next.js App Router delivering multi-tenant SSR and on-demand ISR across custom domains |
| Visual Studio UI | Next.js and TypeScript drag-and-drop block canvas with live responsive viewport previews |
| Commerce API Core | Node.js Fastify services handling catalogs, pricing rules, carts, and checkout sessions |
| Primary Database | PostgreSQL with row-level tenant isolation for products, layout ASTs, and order ledgers |
| Edge & Cache Bus | Redis storing active cart state, rate-limit counters, and cache-tag invalidation events |
| Domain & Edge Routing | Cloudflare for SaaS automating custom hostname DNS verification and edge TLS certificates |
| Payment Processing | Stripe Connect managing merchant onboarding, tokenized checkouts, and webhook settlement |
| Media Pipeline | Object storage with on-the-fly WebP/AVIF resizing and CDN edge caching for product galleries |
| Async Workers | Node.js BullMQ workers processing webhook deliveries, catalog imports, and search indexing |
Engineering Trade-offs & Solutions
| Engineering Challenge | Solution & Trade-off |
|---|---|
| Allowing arbitrary third-party HTML/JS embeds introduces XSS and layout corruption risks | Replaced raw HTML blobs with a versioned JSON AST and sandboxed React block registry; limits arbitrary code injection while keeping extensibility controlled through approved webhook and script slots. |
| Publishing a single price update could invalidate an entire tenant's edge cache | Implemented granular Next.js cache tags (tenant:page, tenant:product:id) triggered by PostgreSQL outbox events, trading slight invalidation orchestration complexity for targeted sub-second updates. |
| Concurrent shoppers buying the final unit of a limited SKU risk overselling | Added Redis short-lived checkout reservation keys paired with atomic UPDATE ... WHERE stock >= qty guards in PostgreSQL, avoiding long-lived pessimistic table locks. |
| Running one database per merchant complicates migrations and connection pooling | Selected shared PostgreSQL schemas with mandatory tenant_id Row-Level Security and PgBouncer transaction pooling, preserving operational simplicity with clear enterprise sharding paths. |
Security & Tenant Isolation
Operating a shared commerce builder demands strict boundaries between merchant configurations, shopper PII, and payment credentials. PostgreSQL Row-Level Security policies enforce tenant scoping at the database session layer so even an unguarded query cannot cross tenant borders.
Payment card data never touches Node.js servers; Stripe Elements tokenizes card inputs directly in the browser while Connect webhooks verify cryptographic signatures before transitioning order states. Merchant admin sessions rely on HTTP-only signed cookies, CSRF checks, and role-scoped permissions separating store designers from finance administrators.
Performance & Rendering Scale
Catalog browsing traffic spikes unpredictably during influencer campaigns and seasonal retail weekends. By compiling published layout ASTs into Next.js App Router Server Components cached via on-demand ISR, anonymous storefront requests resolve at edge POPs without invoking Node.js checkout containers or PostgreSQL read replicas.
Product imagery routes through automated responsive optimization pipelines producing AVIF and WebP variants sized to each viewport container, while BullMQ background workers absorb bursty tasks—such as CSV catalog imports, search index refreshes, and merchant webhook retries—without adding latency to live shopper checkouts.
Operational Outcomes
Consolidating visual page authoring, custom domain automation, and isolated checkout APIs onto one cohesive architecture reshaped how merchants and platform operators work:
- Faster storefront launches: Brand teams assemble, preview, and publish custom-branded storefronts with live TLS domains through self-service workflows rather than multi-week engineering sprints.
- Resilient campaign traffic handling: Edge-cached ISR storefronts absorb promotional bursts smoothly while protecting transactional checkout pools from read-query saturation.
- Safe iterative upgrades: Versioned JSON layout schemas allow platform engineers to ship new merchandising blocks and accessibility improvements globally without breaking existing merchant themes.
- Predictable multi-tenant governance: Database-enforced tenant isolation and automated webhook observability give operations teams clear auditability across thousands of independent storefronts.