Skip to main content

Sourcing Architecture

Switchyard uses a multi-channel sourcing model that combines warehouse inventory, retail sweeps, and partner brand consignment to fulfill customer orders.

Sourcing Channels

RFC Inventory

Overview

The RFC (Rapid Fulfillment Center) is our warehouse where we pre-stock high-velocity and perishable items for immediate fulfillment.

Inventory Structure

Picking Strategy

FEFO/FIFO (First Expiring First Out / First In First Out):
  1. Items with earliest expiration date picked first
  2. For non-perishables, oldest received date picked first
  3. Reserved quantities tracked to prevent over-allocation

Key Tables

Retail Sweeps

Overview

Sweeps are shopping trips to partner retailers (HEB, Target, Walmart, Central Market, Whole Foods, Costco, Trader Joe’s) to source items not stocked in the RFC.

Sweep Economics

The system optimizes sweeps based on profitability:

Sweep Optimization

The Sweep Optimizer consolidates under-threshold sweeps:
  1. Identifies sweeps below breakeven threshold
  2. Finds alternative sweeps at same location with capacity
  3. Moves items to maximize efficiency
  4. Cancels empty sweeps

Sweep Flow

Key Tables

Partner Brand Consignment

Overview

Partner brands ship their own products to our RFC for consignment sale. We handle fulfillment and take a commission on sales.

Partner Lifecycle

Commission Model

Commission can be overridden at the product level via sellable_products.commission_rate.

Manifest Flow

Partner manifests use TYPE 27 taxonomy IDs for QR code scanning:
  1. Admin creates reorder request with items and quantities
  2. Partner has 7 days to accept/reject
  3. On acceptance, manifest auto-created with QR code
  4. Partner ships to RFC with tracking info
  5. Staff scans manifest QR at receiving
  6. Items scanned into consignment inventory

Consignment Sales Tracking

When consignment inventory is sold:
  1. record_consignment_sale() function triggered
  2. Captures commission rate at time of sale
  3. Records commission_amount and net_to_partner
  4. Assigns to payout_period (YYYY-MM format)
  5. Partner views via portal, admin settles monthly

Shopify Integration

Partners can sync products from their Shopify store:

Key Tables

Partner-Specific Fields

On scraped_products:
  • partner_brand_id - Links product to partner
On sellable_products:
  • is_partner_brand - Flag for partner products
  • commission_rate - Product-level commission override
On inventory_items:
  • partner_brand_id - Tracks consignment ownership
  • is_consignment - Flags consignment inventory
  • manifest_item_id - Links to receiving manifest

Allocation Engine

Decision Flow

When an order arrives, the allocation engine analyzes each line item:

Sourcing Priority

  1. RFC Inventory - Check available stock (FEFO/FIFO)
  2. Best Retailer - Compare prices across retailers
  3. Bulk vs Individual - Consider bulk SKU breakdowns
  4. Route Optimization - Prefer existing routes when possible

Key Functions

Database Views

Prebuilt views for common queries:

Background Jobs

Scraper Scheduling

Retailer scrapers run on pg_cron schedules:
  • Updates retailer_pricing with current costs
  • Updates retailer_mappings with availability
  • Wakes scraper workers via pg_net HTTP calls

Shopify Sync

Daily sync at 6am CST via pg_cron:
  • Triggers trigger_shopify_sync() function
  • Calls internal API endpoint
  • Updates products based on sync configuration

Reorder Request Expiry

Requests expire after 7 days:
  • expire_old_reorder_requests() function
  • Marks status as expired
  • Partner notified of expiry

API Endpoints

Admin APIs

Partner Portal APIs

Scanner APIs

Integration Points