The short version

124K attribution rows. Tenant boundaries tested across 18 tables.

Key decision

Enforce tenant scope and column-level write permissions in the database. Preserve human-entered data during sync.

Verification

Automated cross-tenant read and write tests; client economics reconciled within 0.7% across platforms.

director view · tenant A
Leads · tenant A · this weeksigned in as director-a
LeadSourceKeywordDispositionStartWk hrsWk rev
L-1041Google Ads[service] near meclient06/0224$•••
L-1042Google Ads[service] costconsult set–––
L-1043Organic–contacted–––
L-1044Google Ads[brand] reviewsclient05/2816$•••
L-1045Google Ads[service] agencyno answer–––
row-level security: 1 of N tenants visible · attribution columns read-only
Rendering of the director view. Keywords and revenue are masked; the real dashboard is client-confidential.

Problem

Cost per lead ends at the lead. Finance wanted lifetime value and acquisition cost by location and by digital source, and that required the people who actually close leads to record what happened afterward: whether the lead became a client, when they started, weekly hours, weekly revenue. Directors at each location needed a tool that showed them only their own leads, and finance needed the roll-up. The first version shipped to production in one day. The hardening took longer, on purpose.

Architecture

tenant isolation · request path
Director Atenant A
Director Btenant B
Director Ctenant C
Supabase Auth → Cloudflare Workers → React
Row-level security policiestenant scope enforced in Postgres, not app code
18 tablescolumn-level write boundaries · cross-tenant tests

Architecture model. Scroll horizontally on smaller screens →

Tenant scope is enforced in the database, not in application code.
cross-tenant test matrix
Director A tenant A Director B tenant B Director C tenant C Auth → Workers → React app Row-level security policies scoped in Postgres, not in app code 18 tables · column-level write boundaries AUTOMATED CROSS-TENANT TESTS ✓ A reads own leads ✓ A reads B leads → denied ✓ A writes B row → denied ✓ A edits attribution → denied ✓ A lists tenants → sees only A ✓ reporting layer bypass → closed ✓ provisioning never overwrites …repeated across all 18 tables
Every combination that must fail, run against all 18 tables.
client economics pipeline
Ads engine nightly sync Dispositions 1,000+ leads Client rows 1,130 · 7 locations Reconcile within 0.7% LTV / CAC VP of Finance replaces a 4.5-hour per-client scrape with report pulls that finish in minutes
From qualified lead to LTV/CAC by location and source, reconciled across platforms.
  1. Nightly syncQualified leads and their attribution flow from the ads engine into Postgres, with idempotent user provisioning that can never overwrite human-entered data.
  2. Row-level securityEvery query is scoped to the director's tenant by Postgres policy, not by application code. A defense-in-depth tenant firewall means no client-facing user can see that another portfolio company exists.
  3. Edge deliveryCloudflare Workers serve the React app and its API. Supabase Auth handles identity.
  4. Disposition workflowDirectors work each lead through a field-sales flow and record start dates, weekly hours, and weekly revenue.
  5. Client economics pipelineReplaces a 4.5-hour per-client scrape with report pulls that finish in minutes: 1,130 client rows across 7 locations, validated within 0.7% across platforms.
  6. Finance outputThe digitally sourced share of $15.9M in lifetime client revenue, and LTV/CAC by location and by source, presented to the VP of Finance as the top-of-funnel half of an acquisition-cost ceiling.

Hardening after day one

  • Closed a row-level-security bypass in the reporting layer.
  • Column-level write boundaries so directors can edit dispositions but not attribution facts.
  • Automated cross-tenant tests across all 18 tables that attempt to read and write another tenant's rows and must fail.
  • Fixed RLS policy recursion with a SECURITY DEFINER function, fixed an auth deadlock, and added a boot watchdog.
  • Provisioning is idempotent and never overwrites data a human entered.

Numbers

Attribution rows124K
Offline conversions uploaded to Google4,449
Tables under enforced tenant isolation18
Leads dispositioned by directors1,000+
Client economics rows1,130 across 7 locations
Cross-platform validationwithin 0.7%
Per-client report time4.5 hours to minutes
Lifetime client revenue analyzed$15.9M
Time from design to productionone day
All figures appear on my resume.

Why it matters for the ads engine

The ads engine optimizes on qualified leads. This platform is what turns a qualified lead into a known client with known revenue, which is the only way to say what a lead is worth by location and by source. The two together are one closed loop from ad click to lifetime value.

Explore the portfolio

Selected workFour systems and their outcomesAds optimization engineClassification, evaluation, verified mutationsAI sales engineRetrieval, claim validation, human approvalAttribution platformTenant isolation and client economicsAgent orchestration platformIsolated worktrees, guardian policy, durable jobsWebsite re-platformMigration, visual verification, rollbackHow I workBackground and engineering principlesStart a conversationandreasengelbertson@gmail.com
↑↓ navigate ↵ openSearch stays in your browser