Stackr
ActiveFeatured

Stackr

B2C and B2B multi-vendor wholesale marketplace with automated vendor payouts

Technologies

Next.js 15v15TypeScriptTanStack QueryHonoBunBetter AuthPostgreSQLv16Drizzle ORM+5 more

Overview

Stackr is a multi-vendor wholesale marketplace built for three personas: customers buying at retail, store owners purchasing in bulk under MOQ rules, and wholesalers managing their catalog and receiving automated daily payouts. The platform covers the full commerce funnel: product discovery via Typesense full-text search, B2C and B2B cart flows with minimum order enforcement, atomic stock reservation at checkout, multi-vendor commission tracking, daily Stripe Connect payout batches, and EasyPost shipment tracking with webhook-driven status updates. Product embeddings via pgvector power similarity search, personalized recommendations, and frequently-bought-together calculations. The full stack runs in production: Hono API on Fly.io with a separate BullMQ worker process, Next.js frontend on Vercel, and Neon PostgreSQL with Drizzle ORM.

Key Highlights

  • Full multi-vendor marketplace live at stackr-nine.vercel.app with B2C, B2B, and wholesaler portals
  • Atomic stock reservation at checkout without database transactions (Neon HTTP driver constraint)
  • Daily Stripe Connect payout batch: aggregates commissions per wholesaler, executes transfers, sends email receipts
  • Typesense full-text and faceted search with real-time indexing via IPv6 Flycast networking on Fly.io
  • pgvector product embeddings (1536-dim, Voyage AI) for similarity search and personalized recommendations
  • EasyPost shipping integration with webhook-driven tracking status updates
  • Dual-channel cart (B2C and B2B) with MOQ enforcement and wholesale pricing tiers
  • Separate BullMQ worker process on Fly.io covering payout cron, search sync, email, and PDF

The Challenge

Problem Statement

Multi-vendor marketplaces carry compounding complexity: each order may span multiple wholesalers, each with their own pricing tiers, MOQ rules, commission rates, and payout schedules. Add to that a dual-channel cart (B2C vs B2B), atomic stock reservation without database transactions due to Neon's HTTP driver limitation, cross-domain auth cookies, and faceted search, all while keeping the frontend fast and the payout pipeline reliable.

This challenge required a solution that could scale to handle enterprise-level traffic while maintaining accuracy and providing a seamless user experience. The system needed to be production-ready from day one, with robust error handling and monitoring capabilities.

The Solution

Our Approach

Concerns are separated cleanly: a Hono API handles synchronous requests, a dedicated BullMQ worker handles async jobs (payouts, indexing, emails), and Typesense runs as a Fly.io sidecar for search. Atomic checkout uses SQL WHERE clauses (WHERE stock minus reserved_stock >= qty) instead of transactions. A daily cron at 02:00 UTC aggregates commissions per wholesaler and executes single Stripe Transfers for clean reconciliation. Cross-domain auth is fixed via a Next.js API rewrite that proxies all requests through the Vercel domain.

Architecture Overview

Loading diagram...

The Next.js frontend on Vercel serves all four user personas. All API calls are proxied through a Next.js rewrite to handle cross-domain auth cookies. The Hono API on Fly.io handles synchronous requests: catalog, search, cart, checkout, and dashboards. A separate BullMQ worker process consumes jobs from Upstash Redis for all async work: daily payout batches, Typesense re-indexing, email notifications, and shipment tracking polls via EasyPost.

Key Technical Decisions

1

Atomic checkout without DB transactions

Neon's HTTP driver doesn't support transactions. Stock reservation uses atomic SQL WHERE clauses to prevent overselling with no transaction boundary needed.

Alternatives Considered:

  • Drizzle transactions (incompatible with neon-http)
  • Optimistic locking with retries
2

Dedicated BullMQ worker process

Keeping async work (payout batches, Typesense sync, emails, shipment polling) in a separate Fly.io machine keeps the API low-latency and lets jobs survive API restarts independently.

Alternatives Considered:

  • In-process async handlers
  • Serverless cron functions
3

Daily batch Stripe Connect payouts

Batching all commissions per wholesaler into a single daily Stripe Transfer reduces API calls, simplifies reconciliation, and gives wholesalers a predictable payout cadence.

Alternatives Considered:

  • Real-time per-order transfers
  • Manual payout triggers
4

Next.js API rewrite for cross-domain auth

Frontend (Vercel) and API (Fly.io) are on different domains. Better Auth session cookies break cross-domain. A next.config.ts rewrite proxies /api/* through Vercel, keeping cookies on the same origin.

Alternatives Considered:

  • Custom domain with CNAME
  • JWT-only auth without cookies
5

Typesense over Elasticsearch for search

Typesense is lighter, faster to self-host on Fly.io, and has a simpler filter syntax. Real-time indexing with facets, sorting, and prefix search without Elasticsearch overhead.

Alternatives Considered:

  • Elasticsearch
  • Postgres full-text search

Technologies Used

Results & Achievements

User Roles

4

Admin, wholesaler, store owner, and customer, each with a dedicated dashboard

🗄️

DB Tables

30+

13 schema groups covering auth, catalog, commerce, AI, analytics, payments, and shipping

🔌

API Routes

40+

Catalog, search, cart, checkout, wholesaler, admin, AI, and webhooks

🤖

AI Features

4

Product embeddings, similar products, recommendations, and frequently-bought-together

🔗

Integrations

6

Stripe Connect, EasyPost, Typesense, Cloudflare R2, Resend, and Upstash Redis

Key Achievements

  • Full multi-vendor marketplace live at stackr-nine.vercel.app with B2C, B2B, and wholesaler portals

  • Atomic stock reservation at checkout without database transactions (Neon HTTP driver constraint)

  • Daily Stripe Connect payout batch: aggregates commissions per wholesaler, executes transfers, sends email receipts

  • Typesense full-text and faceted search with real-time indexing via IPv6 Flycast networking on Fly.io

  • pgvector product embeddings (1536-dim, Voyage AI) for similarity search and personalized recommendations

  • EasyPost shipping integration with webhook-driven tracking status updates

  • Dual-channel cart (B2C and B2B) with MOQ enforcement and wholesale pricing tiers

  • Separate BullMQ worker process on Fly.io covering payout cron, search sync, email, and PDF

Want to Build Something Similar?

I specialize in building production-ready AI systems that scale. Let's discuss your project.