Delivered remotely for a business based in Madrid, Spain. Names withheld by agreement.
Project Overview
Industry: B2B Multi-Vendor Commerce
Solution scope: A B2B multi-vendor procurement marketplace, quote negotiation hub, and split-settlement backend engineered with Next.js, NestJS, TypeScript, PostgreSQL, Elasticsearch, Redis, and Stripe Connect.
Context: Commercial buyers sourcing packaging, MRO supplies, electronics, and hospitality goods across fragmented wholesale distributors face severe procurement friction: separate supplier logins, inconsistent minimum order quantities (MOQs), emailed Excel price sheets, and manual invoice reconciliation across every vendor. Meanwhile, marketplace operators need tight control over vendor onboarding, commission rules, split shipping logic, and escrow-style payouts. We built a unified B2B commerce platform pairing a fast Next.js App Router storefront with a modular NestJS and PostgreSQL core capable of routing a single buyer requisition across multiple independent suppliers seamlessly.
B2B Marketplace Bottlenecks
Public B2C cart patterns failed under commercial buying rules. Standard single-price catalogs could not express buyer-specific contract discounts, pallet volume breaks, or minimum order thresholds per vendor.
Cross-vendor checkouts created fulfillment deadlocks. Coupling multiple suppliers into one monolithic order state meant a delay or partial stockout at one warehouse stalled invoicing and payout tracking for every other vendor on the cart.
Unstructured supplier feeds corrupted catalog search. Vendors uploading inconsistent CSV spreadsheets introduced duplicate SKUs, broken category mappings, and stale stock counts that eroded buyer trust.
Manual commission splits slowed marketplace finance. Reconciling platform fees, shipping subsidies, and partial refunds across dozens of vendor bank transfers required error-prone end-of-month spreadsheets.
Architectural Strategy
Separate parent buyer orders from vendor sub-orders. Buyers experience one consolidated cart, approval flow, and order summary, while NestJS decomposes checkout into independent child VendorOrder lifecycles that ship, invoice, and settle autonomously.
Keep search indexing decoupled from dynamic contract pricing. Elasticsearch handles full-text queries, technical attribute faceting, and catalog sorting across tens of thousands of SKUs, while NestJS overlays personalized organization price books via Redis and PostgreSQL at read time.
Enforce strict TypeScript contracts end to end. Sharing clean schema definitions across Next.js server components and NestJS controllers eliminates payload drift across complex RFQ forms, multi-tier price tables, and sub-order transitions.
Track commissions and payouts through an internal double-entry ledger. Rather than relying solely on payment-gateway metadata, PostgreSQL records every gross charge, platform fee, refund adjustment, and Stripe Connect transfer as auditable ledger entries.
Core Capabilities
- Faceted B2B catalog & SKU matrix: Parametric search across technical specs, supplier ratings, lead times, MOQs, and tiered volume pricing tables.
- Contract pricing & buyer organizations: Multi-user corporate buyer accounts supporting role-based spend limits, internal cart approval queues, and negotiated catalog overrides.
- Structured RFQ & quote-to-cart flow: Buyers request custom pricing on bulk quantities directly from vendors, negotiate counter-offers inside tracked threads, and convert accepted quotes into locked orders.
- Split-vendor cart & shipping engine: Calculates per-supplier freight rules, pallet thresholds, and delivery windows inside a unified checkout view.
- Self-serve vendor portal: Dedicated Next.js workspace for suppliers to upload catalog feeds, manage stock buffers, confirm sub-orders, print packing slips, and track payout statements.
- Escrow-aware commission settlement: Automated fee calculation, holdback periods for delivery confirmation, and partial-refund reversals via Stripe Connect.
Technical Architecture
Next.js App Router storefront & portals. Next.js renders public and authenticated catalog pages on the server for fast initial paint and clean search engine indexing, while client components handle interactive cart splits, bulk SKU quick-order uploads, and live RFQ chat panels.
NestJS modular API core. Built in TypeScript, NestJS separates Catalog Ingestion, Pricing Resolution, Cart & Checkout, RFQ Workflow, Sub-Order Fulfillment, and Ledger Settlement into isolated modules communicating through typed domain services and background queues.
Elasticsearch & Redis acceleration. Elasticsearch indexes canonical products and vendor offers with synonym rules for part numbers and technical units. Redis caches resolved (buyer_org_id, offer_id) contract prices and guards inventory reservations during active checkouts.
PostgreSQL ledger & Stripe Connect. PostgreSQL anchors relational integrity across buyer hierarchies, sub-order state transitions, and commission ledgers. Stripe Connect executes split payment captures and controlled transfers to verified vendor connected accounts.
Flow: Buyer (Next.js SSR / Cart) → NestJS API & pricing resolver → Elasticsearch catalog + Redis cache → PostgreSQL parent/sub-order ledger → Vendor portal & Stripe Connect payouts
Technology Stack
| Category | Technology |
|---|---|
| Storefront & portals | Next.js (App Router) and TypeScript rendering SEO-friendly SSR catalogs, buyer carts, and vendor dashboards |
| Backend API platform | NestJS modular architecture governing auth, RFQ negotiations, split-order state machines, and payout ledgers |
| Primary database | PostgreSQL storing multi-tenant buyer organizations, vendor profiles, contract price books, and order ledgers |
| Search & faceting | Elasticsearch indexing multi-attribute SKU catalogs, supplier stock flags, and compatibility filters |
| Cache & rate control | Redis caching buyer contract-price lookups, active cart locks, and vendor feed ingestion queues |
| Marketplace payouts | Stripe Connect orchestrating split charges, platform commission holds, and post-delivery vendor transfers |
| Bulk catalog ingestion | Async CSV/XML feed workers validating supplier SKU updates, volume breaks, and minimum order quantities |
| Document generation | Automated multi-vendor consolidated buyer proformas and per-supplier VAT settlement statements |
| Observability | OpenTelemetry request tracing across Next.js SSR, NestJS modules, and Elasticsearch query latency |
Engineering Trade-offs & Solutions
| Challenge | Solution |
|---|---|
| Indexing buyer-specific contract prices inside Elasticsearch would cause massive index fan-out | Kept Elasticsearch buyer-agnostic on base catalog data and resolved negotiated contract discounts in NestJS via batched Redis lookups. |
| One delayed vendor shipment risked blocking payouts or status updates for other suppliers in the same checkout | Modeled a ParentOrder → VendorSubOrder hierarchy in PostgreSQL so each supplier fulfills, invoices, and triggers settlement independently. |
| Large vendor CSV price updates occasionally stalled storefront APIs | Routed bulk feed parsing into asynchronous validation workers that verify SKUs and volume tiers in staging tables before atomic Elasticsearch bulk swaps. |
| Mid-checkout price changes or stockouts across multiple vendors confused corporate buyers | Added short-lived checkout price snapshots and atomic stock validation per sub-order before Stripe payment capture executes. |
| Partial cancellations by one supplier distorted flat platform commission math | Computed commissions per sub-order line item inside an append-only ledger so partial refunds automatically recalculate proportional fee reversals. |
| Corporate buyers needed internal manager sign-off without losing negotiated quote locks | Built a PENDING_APPROVAL cart state that preserves accepted RFQ pricing and stock reservations while notifying designated organization approvers. |
Security & Governance
Tenant-scoped authorization guards. NestJS guards enforce strict isolation between competing vendor portals and separate corporate buyer organizations so no supplier can inspect rival pricing or another buyer's contract terms.
KYC verification & payout holdbacks. Vendors complete Stripe Connect identity onboarding before listings go live, and marketplace payout releases enforce configurable delivery confirmation and dispute windows to protect buyers against non-delivery.
Audited quote & order mutations. Every RFQ counter-offer, contract price edit, manager cart approval, and commission override writes an immutable audit trail recording actor, timestamp, and payload diff.
Performance & Scale
Fast SSR catalog browsing. Combining Next.js server rendering with Elasticsearch aggregations and short-TTL Redis pricing caches keeps category browsing and technical attribute filtering snappy even across deep multi-vendor catalogs.
Independent scaling of ingestion and checkout. Isolating supplier feed workers from NestJS checkout nodes ensures heavy overnight catalog refreshes never contend with live buyer orders.
Operational Outcomes
- Consolidated multi-supplier procurement: Corporate buyers search, compare, approve, and check out across dozens of vetted vendors inside one unified portal.
- Autonomous vendor fulfillment: Suppliers manage their own stock feeds, sub-order dispatches, and shipping SLAs without manual marketplace operator mediation.
- Transparent, automated commission accounting: Double-entry PostgreSQL ledgers and Stripe Connect settlement rules remove manual month-end payout reconciliation.
- Higher quote conversion on bulk orders: Structured RFQ threads and instant quote-to-cart handoffs replace slow email spreadsheets for high-value wholesale deals.