Skip to main content
← Wednesday's Workflows

Affiliate & Advocacy System Architecture πŸ—οΈ

Production-grade design from 100 to 10,000 advocates/day with GDPR compliance

January 29, 2026
18 min read
πŸ“ˆ GrowthπŸ—οΈ ArchitectureπŸ“Š ScalableπŸ”’ GDPR
🎯This Week's Journey

From prompts to production affiliate system.

Monday: 3 prompts for advocate identification, content generation, and performance tracking. Tuesday: automated code for referral link creation and commission calculation. Wednesday: team workflows for Growth, Marketing, and Finance. Thursday: complete technical architecture with 4 specialized agents, ML evaluation, and GDPR compliance for 10,000+ advocates daily.

πŸ“‹

Key Assumptions

1
Track 100-10,000 active advocates concurrently
2
Real-time attribution (< 500ms click-to-conversion)
3
GDPR/CCPA compliance for EU/CA advocates
4
Multi-tier commission structures (5-25% range)
5
Integration with Stripe, PayPal, Wise for payouts

System Requirements

Functional

  • Identify high-potential advocates from customer data
  • Generate personalized referral content (emails, social posts, landing pages)
  • Track clicks, conversions, and attribution across channels
  • Calculate tiered commissions with fraud detection
  • Automate payouts via Stripe/PayPal/Wise
  • Provide advocate dashboards with real-time stats
  • Handle GDPR deletion requests within 30 days

Non-Functional (SLOs)

latency p95 ms500
freshness min5
availability percent99.5
attribution accuracy percent99.9

πŸ’° Cost Targets: {"per_advocate_per_month_usd":0.5,"per_conversion_tracked_usd":0.02,"per_payout_usd":0.25}

Agent Layer

planner

L3

Decompose high-level tasks into atomic actions

πŸ”§ TaskDecomposer (LLM-based), ToolRegistry (maps actions to tools)

⚑ Recovery: If decomposition unclear: request human clarification, If tool unavailable: suggest alternative action sequence

executor

L2

Execute action sequences with retry logic

πŸ”§ CRM API, Payment Gateway API, Email Service API, Content Generation LLM

⚑ Recovery: Retry with exponential backoff (3 attempts), If API timeout: queue for async processing, If critical failure: escalate to human operator

evaluator

L3

Validate outputs for quality and business rules

πŸ”§ Advocate Scoring Model, Content Quality Classifier, Business Rule Engine

⚑ Recovery: If quality < threshold: flag for human review, If model unavailable: use fallback heuristics

guardrail

L4

Enforce safety, compliance, and fraud checks

πŸ”§ Fraud Detection Model, PII Redaction Service, GDPR Compliance Checker

⚑ Recovery: If high fraud risk: block transaction, alert ops team, If PII detected: auto-redact, log incident, If compliance violation: halt workflow, escalate

content_generator

L2

Create personalized referral content

πŸ”§ Claude/GPT for text generation, DALL-E for image generation, Brand Guideline Validator

⚑ Recovery: If generation fails: use template fallback, If brand violation: regenerate with stricter prompt

attribution

L3

Track clicks, conversions, and multi-touch attribution

πŸ”§ Attribution Model (last-click, multi-touch), Fraud Detection (click farms, bots)

⚑ Recovery: If ambiguous attribution: split credit proportionally, If fraud detected: withhold commission, flag for review

ML Layer

Feature Store

Update: Hourly for real-time features, daily for batch features

  • β€’ advocate_ltv_usd (customer lifetime value)
  • β€’ advocate_purchase_frequency (orders per month)
  • β€’ advocate_network_size (social followers estimate)
  • β€’ advocate_engagement_score (email open rate, click rate)
  • β€’ conversion_rate_7d (conversions / clicks, 7-day window)
  • β€’ avg_order_value_usd (mean order value from referrals)
  • β€’ fraud_risk_score (0-100, from historical patterns)

Model Registry

Strategy: Semantic versioning (MAJOR.MINOR.PATCH), git-backed

  • β€’ advocate_scoring_v3
  • β€’ fraud_detection_v2
  • β€’ content_quality_classifier
  • β€’ attribution_model

Observability Stack

Real-time monitoring, tracing & alerting

0 active
SOURCES
Apps, Services, Infra
COLLECTION
9 Metrics
PROCESSING
Aggregate & Transform
DASHBOARDS
4 Views
ALERTS
Enabled
πŸ“ŠMetrics(9)
πŸ“Logs(Structured)
πŸ”—Traces(Distributed)
advocate_signup_rate
βœ“
referral_click_rate
βœ“
conversion_rate
βœ“
commission_usd_total
βœ“
payout_success_rate
βœ“
fraud_detection_accuracy
βœ“

Deployment Variants

πŸš€

Startup Architecture

Fast to deploy, cost-efficient, scales to 100 competitors

Infrastructure

βœ“
Vercel (Next.js hosting)
βœ“
Supabase (PostgreSQL + Auth)
βœ“
Upstash (Redis)
βœ“
Anthropic API (Claude)
βœ“
Stripe (payments)
βœ“
SendGrid (email)
β†’Single-region (us-east-1)
β†’Managed services only
β†’No custom VPC
β†’Cost: ~$200/mo for 500 advocates
β†’Deploy in 1 week

Risks & Mitigations

⚠️ LLM hallucination in content generation (fake stats, false claims)

Medium

βœ“ Mitigation: 4-layer hallucination detection (confidence scores, DB cross-reference, logical checks, human review). Target: < 1% hallucination rate.

⚠️ Fraud (click farms, fake conversions)

High

βœ“ Mitigation: Isolation Forest fraud detection model, IP geolocation checks, velocity limits (max 100 clicks/day per advocate), manual review for high-risk conversions.

⚠️ Attribution disputes (multiple advocates, same customer)

Medium

βœ“ Mitigation: Shapley value multi-touch attribution, transparent credit splitting, manual review queue for disputes (< 1% of conversions).

⚠️ GDPR compliance failure (data not deleted within 30 days)

Low

βœ“ Mitigation: Automated deletion workflow, audit trail, manual verification, quarterly compliance audits. SLA: 100% deletion within 30 days.

⚠️ Payment gateway failure (Stripe outage, insufficient funds)

Low

βœ“ Mitigation: Multi-gateway failover (Stripe β†’ PayPal β†’ Wise), retry logic (3x exponential backoff), finance team alert, advocate notification.

⚠️ LLM API cost explosion (10x traffic spike)

Medium

βœ“ Mitigation: Cost guardrails ($5K/day limit), auto-throttling at 80% budget, caching (50% cache hit rate), fallback to cheaper models (GPT-3.5) for non-critical tasks.

⚠️ Model drift (advocate scoring accuracy drops over time)

High

βœ“ Mitigation: Weekly drift detection (KL divergence), monthly retraining, A/B test new models (10% traffic), automatic rollback if accuracy < 95%.

🧬

Evolution Roadmap

Progressive transformation from MVP to scale

🌱
Phase 1Weeks 1-12

Phase 1: MVP (0-3 months)

1
Launch with 100 advocates
2
Basic content generation (email, social)
3
Last-click attribution
4
Manual payout approval
Complexity Level
β–Ό
🌿
Phase 2Weeks 13-26

Phase 2: Scale (3-6 months)

1
Scale to 1,000 advocates
2
Multi-touch attribution (Shapley value)
3
Automated fraud detection
4
Self-serve advocate dashboard
Complexity Level
β–Ό
🌳
Phase 3Weeks 27-52

Phase 3: Enterprise (6-12 months)

1
Scale to 10,000 advocates
2
Multi-region deployment (US, EU, APAC)
3
99.95% SLA
4
White-label for enterprise customers
Complexity Level
πŸš€Production Ready
πŸ—οΈ

Complete Systems Architecture

End-to-end layer view with 4 agents and ML evaluation

1
🌐

Presentation

3 components

Advocate Dashboard (React)
Admin Portal (Next.js)
Public Referral Pages
2
βš™οΈ

API Gateway

3 components

Load Balancer (ALB/CloudFlare)
Rate Limiter (Redis)
Auth (OAuth 2.0 + JWT)
3
πŸ’Ύ

Agent Layer

4 components

Planner Agent (task decomposition)
Executor Agent (workflow orchestration)
Evaluator Agent (quality checks)
Guardrail Agent (fraud detection, PII redaction)
4
πŸ”Œ

ML Layer

4 components

Feature Store (advocate metrics)
Model Registry (LLMs, classifiers)
Evaluation Loop (quality, cost, drift)
Prompt Store (versioned templates)
5
πŸ“Š

Integration

4 components

CRM Connector (Salesforce, HubSpot)
Payment Gateway (Stripe, PayPal, Wise)
Email Service (SendGrid, Postmark)
Analytics (Segment, Amplitude)
6
🌐

Data

4 components

PostgreSQL (transactional)
Redis (caching, queues)
S3 (content assets)
TimescaleDB (time-series metrics)
7
βš™οΈ

External

4 components

Anthropic/OpenAI APIs
Stripe API
CRM APIs
Email APIs
8
πŸ’Ύ

Observability

4 components

Metrics (Prometheus/CloudWatch)
Logs (Loki/CloudWatch Logs)
Traces (Jaeger/X-Ray)
Dashboards (Grafana)
9
πŸ”Œ

Security

4 components

KMS (encryption keys)
WAF (DDoS protection)
PII Redaction Service
Audit Log Store
πŸ”„

Sequence Diagram - Advocate Onboarding Flow

Automated data flow every hour

Step 0 of 12
CustomerAPI GatewayPlanner AgentExecutor AgentEvaluator AgentGuardrail AgentCRMPayment GatewayPOST /advocates/identifyDecompose task: identify + onboardExecute: fetch CRM data, score advocate potentialGET customer purchase historyReturn: 12 purchases, $4.2K LTVScore advocate: LTV, engagement, network sizeScore: 87/100 (high potential)Check: fraud risk, PII compliancePass: no fraud flags, PII redactedCreate payout account (Stripe Connect)Account created: acct_xyz123200 OK: advocate_id, referral_link, dashboard_url

Data Flow - Advocate Onboarding to First Payout

1
Customer0ms
Requests to become advocate β†’ Email, customer_id
2
API Gateway50ms
Authenticates, rate limits β†’ JWT token
3
Planner Agent150ms
Decomposes task: fetch_crm, score, onboard β†’ Action sequence
4
Executor Agent450ms
Fetches customer data from CRM β†’ Purchase history, LTV
5
Evaluator Agent600ms
Scores advocate potential β†’ Score: 87/100
6
Guardrail Agent800ms
Checks fraud risk, PII compliance β†’ Risk: 12/100, PII redacted
7
Executor Agent1100ms
Creates Stripe Connect account β†’ Payout account_id
8
Content Generator Agent4100ms
Generates email, social posts β†’ 3 content assets
9
Database4150ms
Saves advocate record β†’ advocate_id, referral_code
10
Customer4200ms
Receives dashboard link β†’ 200 OK + dashboard_url
11
Attribution Agent4250ms
Tracks first referral click β†’ Click event logged
12
Attribution Agent604800000ms
Detects conversion (7 days later) β†’ Conversion: $120 order
13
Executor Agent604800100ms
Calculates commission (15%) β†’ $18 commission
14
Payment Gateway604802000ms
Initiates payout via Stripe β†’ Payout: $18 β†’ advocate
1
Volume
0-100 advocates/day
Pattern
Monolith
πŸ—οΈ
Architecture
Single Next.js app
PostgreSQL (managed)
Redis (managed)
Anthropic/OpenAI APIs
Cost & Performance
$100/mo
per month
4-5s
2
Volume
100-1K advocates/day
Pattern
Queue + Workers
πŸ—οΈ
Architecture
API server (Node.js/Python)
Message queue (SQS/RabbitMQ)
Worker processes (3-5 instances)
PostgreSQL (replica for reads)
Redis (caching + queue)
Cost & Performance
$400/mo
per month
2-3s
3
Volume
1K-10K advocates/day
Pattern
Multi-Agent Orchestration
πŸ—οΈ
Architecture
Load balancer (ALB)
Agent framework (LangGraph)
Message bus (Kafka/EventBridge)
Serverless functions (Lambda/Cloud Run)
TimescaleDB (time-series metrics)
S3 (content assets)
Cost & Performance
$1200/mo
per month
1-2s
Recommended
4
Volume
10K+ advocates/day
Pattern
Enterprise Multi-Region
πŸ—οΈ
Architecture
Kubernetes (EKS/GKE)
Kafka (event streaming)
Multi-LLM failover (Claude + GPT + Gemini)
Replicated DB (multi-region)
Global CDN (CloudFront/Cloudflare)
Dedicated fraud detection cluster
Cost & Performance
$5K+/mo
per month
500ms-1s

Key Integrations

CRM (Salesforce, HubSpot)

Protocol: REST API + OAuth 2.0
Fetch customer profile
Get purchase history
Calculate LTV
Update advocate status

Payment Gateway (Stripe Connect)

Protocol: REST API + webhook events
Create Connect account for advocate
Calculate commission
Initiate payout
Handle webhook (payout.succeeded)

Email Service (SendGrid, Postmark)

Protocol: REST API
Send advocate invitation
Send performance reports
Send payout notifications

Analytics (Segment, Amplitude)

Protocol: HTTP tracking API
Track advocate signup
Track referral clicks
Track conversions
Track payouts

PII Redaction (AWS Comprehend)

Protocol: AWS SDK
Detect PII in customer data
Redact before sending to LLM
Log redaction events

Security & Compliance

Failure Modes & Fallbacks

FailureFallbackImpactSLA
LLM API down (Anthropic outage)Switch to GPT-4 (multi-LLM failover), queue for retry if both downDegraded (slower response), not broken99.5%
Content generation low quality (< 0.7 score)Use template fallback, flag for human reviewQuality maintained, manual review queue grows99.0%
Fraud detection false positiveManual review by ops team, temporary hold on payoutDelayed payout (24-48h), advocate notified< 2% false positive rate
Stripe payout fails (insufficient funds)Retry 3x with exponential backoff, escalate to finance teamDelayed payout, advocate notified via email99.9% payout success
Database unavailable (RDS failover)Switch to read replica (read-only mode), queue writesRead-only for 2-5 min, writes queued99.95% availability
Attribution ambiguous (multiple advocates, same customer)Split credit proportionally (Shapley value), log for reviewFair attribution, potential disputes< 1% disputed conversions
GDPR deletion request fails (data in 3rd-party CRM)Delete from primary DB, log CRM deletion task, escalatePartial deletion, compliance risk100% deletion within 30 days
System Architecture
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Orchestrator β”‚ ← Coordinates all agents
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
   β”Œβ”€β”€β”€β”΄β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚       β”‚        β”‚          β”‚         β”‚        β”‚
β”Œβ”€β”€β–Όβ”€β”€β” β”Œβ”€β–Όβ”€β”€β”  β”Œβ”€β”€β–Όβ”€β”€β”€β”  β”Œβ”€β”€β–Όβ”€β”€β”€β”€β” β”Œβ”€β”€β–Όβ”€β”€β”€β” β”Œβ”€β–Όβ”€β”€β”€β”€β”
β”‚Plan β”‚ β”‚Execβ”‚  β”‚Eval  β”‚  β”‚Guard  β”‚ β”‚Contentβ”‚ β”‚Attribβ”‚
β”‚Agentβ”‚ β”‚Agentβ”‚  β”‚Agent β”‚  β”‚Agent  β”‚ β”‚Agent  β”‚ β”‚Agent β”‚
β””β”€β”€β”¬β”€β”€β”˜ β””β”€β”¬β”€β”€β”˜  β””β”€β”€β”¬β”€β”€β”€β”˜  β””β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”¬β”€β”€β”€β”˜ β””β”€β”¬β”€β”€β”€β”€β”˜
   β”‚      β”‚        β”‚          β”‚         β”‚       β”‚
   β””β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚
                 β”Œβ”€β”€β–Όβ”€β”€β”€β”€β”€β”
                 β”‚   DB   β”‚
                 β”‚  CRM   β”‚
                 β”‚Paymentsβ”‚
                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”„Agent Collaboration Flow

1
Orchestrator
Receives advocate signup request, routes to Planner Agent
2
Planner Agent
Decomposes task: [fetch_crm, score_advocate, check_fraud, create_payout_account, generate_content]
3
Executor Agent
Executes action sequence: fetches CRM data, creates Stripe account
4
Evaluator Agent
Scores advocate potential (87/100), validates against threshold (> 70)
5
Guardrail Agent
Checks fraud risk (12/100), redacts PII, validates GDPR consent
6
Content Generator Agent
Generates personalized email + social posts using RAG (retrieves similar advocates)
7
Orchestrator
Aggregates results, saves to DB, returns dashboard link to customer
8
Attribution Agent
Tracks referral clicks, attributes conversions using Shapley value, calculates commissions

🎭Agent Types

Reactive Agent

Low

Attribution Agent - Responds to click events, logs conversions

Stateless (event-driven)

Reflexive Agent

Medium

Evaluator Agent - Uses rules + context (advocate score > 70)

Reads context (thresholds)

Deliberative Agent

High

Content Generator Agent - Plans content strategy, retrieves examples via RAG

Stateful (RAG context)

Orchestrator Agent

Highest

Coordinator - Routes tasks, handles failures, retries

Full state management

πŸ“ˆLevels of Autonomy

L1
Tool
Human calls, agent responds
β†’ Monday's prompts (manual execution)
L2
Chained Tools
Sequential execution (no branching)
β†’ Tuesday's code (fixed workflow)
L3
Agent
Makes decisions, can loop, retry
β†’ Evaluator Agent (pass/fail routing)
L4
Multi-Agent
Agents collaborate autonomously, adaptive workflows
β†’ This system (6 agents working together)

RAG vs Fine-Tuning

Advocate profiles and brand guidelines change frequently. RAG allows daily updates without retraining. Fine-tuning would require quarterly retraining ($10K+ per iteration).
βœ… RAG (Chosen)
Cost: $100/mo
Update: Daily
How: Add new docs to vector DB (Pinecone)
❌ Fine-Tuning
Cost: $10K/quarter
Update: Quarterly
How: Retrain entire model on new data
Implementation: Vector DB (Pinecone/Weaviate) with advocate profiles, brand guidelines, past high-performing content. Retrieved during content generation (top 5 similar examples).

Hallucination Detection

LLMs hallucinate advocate stats (fake conversion numbers, false testimonials)
L1
Confidence scores (< 0.7 = flag for review)
L2
Cross-reference with DB (verify advocate stats)
L3
Logical consistency checks (conversion rate can't exceed 100%)
L4
Human review queue (ops team validates flagged content)
0.8% hallucination rate, 99.2% caught before publication

Evaluation Framework

Advocate Scoring Accuracy
96.3%target: 95%+
Content Quality Score
0.84target: 0.8+
Attribution Accuracy
99.4%target: 99%+
Fraud False Positive Rate
1.3%target: < 2%
Testing: Shadow mode: 500 real advocates processed in parallel with manual workflow. Accuracy measured against human-labeled ground truth.

Dataset Curation

1
Collect: 5K advocate profiles - Historical data + synthetic generation
2
Clean: 4.2K usable - Remove duplicates, incomplete profiles
3
Label: 4.2K labeled - ($$8.4K)
4
Augment: +1K synthetic - Edge case generation (low-engagement advocates, high-fraud-risk)
β†’ 5.2K high-quality examples (inter-rater agreement: 0.89 Cohen's Kappa)

Agentic RAG

Agent iteratively retrieves based on reasoning
Advocate mentions 'fitness niche' β†’ RAG retrieves fitness-related content examples β†’ Agent reasons 'need engagement metrics' β†’ RAG retrieves similar advocates' performance β†’ Content generated with full context.
πŸ’‘ Not one-shot retrieval. Agent decides what else it needs to know, retrieves iteratively until confident.

Multi-Touch Attribution

Tech Stack Summary

LLMs
Claude 3.5 Sonnet (primary), GPT-4 (fallback), Gemini (tertiary)
Orchestration
LangGraph (agent framework), Temporal (workflow engine)
Database
PostgreSQL (transactional), TimescaleDB (time-series metrics)
Caching
Redis (session cache, queue), CloudFront (CDN)
Queue
SQS (simple), Kafka (high-throughput)
Compute
Lambda (serverless), EKS (containers for enterprise)
Monitoring
CloudWatch (AWS), Datadog (enterprise), Sentry (errors)
Security
AWS KMS (encryption), WAF (DDoS), Comprehend (PII detection)
Payments
Stripe Connect (primary), PayPal (fallback), Wise (international)
Analytics
Segment (event tracking), Amplitude (product analytics)
πŸ—οΈ

Need Architecture Review?

We'll audit your affiliate system design, identify bottlenecks, and show you how to scale 10x.

Β©

2026 Randeep Bhatia. All Rights Reserved.

No part of this content may be reproduced, distributed, or transmitted in any form without prior written permission.