StackBlueprint

EP02 ARCHITECTURE · ZERO-SCRAPER N8N + APIFY MCP WATERFALL

Zero-Scraper B2B Lead Enrichment with n8n + Apify MCP

Replace $495/mo Clay Growth ($5,940/yr) without maintaining brittle Puppeteer containers. Combine self-hosted n8n, Apify MCP ($19/mo), PostgreSQL 17 idempotency, DLQ replay, and a hard spend circuit-breaker for $27.79–$33.99/mo — saving $5,606.52/yr.

Clay Growth (2026 Rate) $495.00/mo $5,940/yr · dual-meter Actions + Credits (BYOK taxed)
Self-Hosted n8n + Apify MCP $27.79–$33.99/mo $333.48/yr promo · $407.88/yr renewal · 0 local Chrome
Annual Savings & Payback $5,606.52/yr Kit v2 ($49) pays back in 4 days

1. Four-Stage Zero-Scraper Pipeline Architecture

Instead of cramming HTTP requests, scraping, LLM scoring, and CRM writes into one fragile n8n canvas, B2B Enrichment Kit v2 isolates four deterministic workflows backed by four PostgreSQL 17 tables on the same EP01 host (zero new public ports):

Stage Workflow & Responsibility Cost & Reliability Guardrail
01 · Intake 01-lead-intake-dns-gate.json Normalizes domain, checks MX/DNS before spending $0.01, deduplicates via UNIQUE(domain)
02 · Waterfall 02-apify-mcp-enrichment-waterfall.json Checks daily USD budget cap first, then calls https://mcp.apify.com + LLM ICP scoring
03 · Rate Guard 03-retry-rate-limit-subworkflow.json Shared PostgreSQL enrichment_rate_state cooldown across queue-mode workers on HTTP 429/5xx
04 · Recovery 04-dlq-alerter-and-replay.json Persists failed payloads in lead_enrichment_dlq for one-click replay after outage recovery

2. Idempotent PostgreSQL 17 Schema & Spend Circuit-Breaker (EP02 Kit)

This exact SQL excerpt from 001-init-enrichment.sql in B2B Enrichment Kit v2 eliminates duplicate CRM records, isolates dead-letter payloads, and gives every worker a single atomic source of truth for daily spend and provider 429 backoff:

-- 1. Core enrichment state machine (idempotent per domain)
CREATE TABLE IF NOT EXISTS lead_enrichment_jobs (
    id              BIGSERIAL PRIMARY KEY,
    domain          TEXT NOT NULL UNIQUE,
    idempotency_key TEXT NOT NULL UNIQUE,
    status          TEXT NOT NULL DEFAULT 'queued'
                    CHECK (status IN ('queued', 'dns_failed', 'enriched', 'scored', 'synced', 'dlq')),
    dns_mx_valid    BOOLEAN NOT NULL DEFAULT FALSE,
    signals_json    JSONB,
    icp_score       INTEGER CHECK (icp_score BETWEEN 0 AND 100),
    crm_record_id   TEXT,
    attempt_count   INTEGER NOT NULL DEFAULT 0 CHECK (attempt_count >= 0),
    updated_at      TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- 2. Persistent Dead-Letter Queue (DLQ) with replay audit timestamp
CREATE TABLE IF NOT EXISTS lead_enrichment_dlq (
    id            BIGSERIAL PRIMARY KEY,
    job_id        BIGINT REFERENCES lead_enrichment_jobs(id) ON DELETE CASCADE,
    domain        TEXT NOT NULL,
    failed_stage  TEXT NOT NULL,
    http_status   INTEGER,
    error_message TEXT NOT NULL,
    raw_payload   JSONB,
    replayed_at   TIMESTAMPTZ,
    created_at    TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- 3. Daily cost ledger for hard spend circuit breaker
CREATE TABLE IF NOT EXISTS enrichment_cost_ledger (
    id            BIGSERIAL PRIMARY KEY,
    job_id        BIGINT REFERENCES lead_enrichment_jobs(id) ON DELETE SET NULL,
    provider      TEXT NOT NULL,
    estimated_usd NUMERIC(10,5) NOT NULL CHECK (estimated_usd >= 0),
    created_at    TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- Budget guard executed before every Apify MCP / LLM call:
SELECT COALESCE(SUM(estimated_usd), 0) AS spent_today
FROM enrichment_cost_ledger
WHERE created_at >= CURRENT_DATE;

-- 4. Shared per-provider cooldown state across queue-mode workers
CREATE TABLE IF NOT EXISTS enrichment_rate_state (
    provider        TEXT PRIMARY KEY,
    next_allowed_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    consecutive_429 INTEGER NOT NULL DEFAULT 0 CHECK (consecutive_429 >= 0)
);

Drop-In Docker Compose Overlay (Zero New Public Ports)

Layer Kit v2 directly on top of your EP01 Compose stack with an idempotent init container—preserving Caddy-only ingress and 127.0.0.1 firewall isolation:

# Apply EP02 overlay on top of EP01 without opening a single new host port:
docker compose -f docker-compose.yml -f docker-compose.enrichment.override.yml up -d

# Key environment guardrails inside .env.enrichment:
# APIFY_MCP_URL=https://mcp.apify.com
# DAILY_CREDIT_CAP_USD=5.00
# ICP_MIN_SCORE=65
# RATE_LIMIT_RPS=2
# NODE_FUNCTION_ALLOW_BUILTIN=dns,crypto

3. Audit MCP & Workflow Security Before Going Live

Connecting MCP servers and CRM private app tokens to n8n expands your credential blast radius. Run StackGuard Security Audit locally on your exported workflows and MCP configurations before deploying to flag leaked bearer tokens, unsafe webhook auth, or unconstrained SSRF targets.

Affiliate disclosure: Apify and Hostinger links are affiliate links; we may earn a commission at no extra cost to you. See Affiliate Disclosure. Published by Oriancy.

Frequently Asked Questions

Why use Apify MCP instead of running Puppeteer or Playwright inside self-hosted n8n?
Headless Chromium consumes 500–900 MB RAM per tab, crashes 4–8 GB VPS nodes under concurrent webhook bursts, and requires constant proxy maintenance. Offloading extraction to Apify MCP ($19/mo Starter) keeps n8n fast and predictable.
How much does n8n + Apify MCP save compared to Clay Growth in 2026?
Clay Growth is $495/mo ($5,940/yr) and still charges Actions on BYOK calls. Hostinger KVM 2 ($8.79/mo promo or $14.99/mo renewal) plus Apify Starter ($19/mo) totals $27.79–$33.99/mo ($333.48–$407.88/yr), saving up to $5,606.52/yr.
How does PostgreSQL prevent runaway scraping spend and duplicate CRM writes?
lead_enrichment_jobs enforces unique domains and idempotency keys, enrichment_cost_ledger enforces DAILY_CREDIT_CAP_USD before each paid call, and lead_enrichment_dlq captures 429/5xx failures for clean replay.