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
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)
π° Cost Targets: {"per_advocate_per_month_usd":0.5,"per_conversion_tracked_usd":0.02,"per_payout_usd":0.25}
Agent Layer
planner
L3Decompose 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
L2Execute 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
L3Validate 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
L4Enforce 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
L2Create 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
L3Track 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 activeDeployment Variants
Startup Architecture
Fast to deploy, cost-efficient, scales to 100 competitors
Infrastructure
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 1: MVP (0-3 months)
Phase 2: Scale (3-6 months)
Phase 3: Enterprise (6-12 months)
Complete Systems Architecture
End-to-end layer view with 4 agents and ML evaluation
Presentation
3 components
API Gateway
3 components
Agent Layer
4 components
ML Layer
4 components
Integration
4 components
Data
4 components
External
4 components
Observability
4 components
Security
4 components
Sequence Diagram - Advocate Onboarding Flow
Automated data flow every hour
Data Flow - Advocate Onboarding to First Payout
Key Integrations
CRM (Salesforce, HubSpot)
Payment Gateway (Stripe Connect)
Email Service (SendGrid, Postmark)
Analytics (Segment, Amplitude)
PII Redaction (AWS Comprehend)
Security & Compliance
Failure Modes & Fallbacks
| Failure | Fallback | Impact | SLA |
|---|---|---|---|
| LLM API down (Anthropic outage) | Switch to GPT-4 (multi-LLM failover), queue for retry if both down | Degraded (slower response), not broken | 99.5% |
| Content generation low quality (< 0.7 score) | Use template fallback, flag for human review | Quality maintained, manual review queue grows | 99.0% |
| Fraud detection false positive | Manual review by ops team, temporary hold on payout | Delayed payout (24-48h), advocate notified | < 2% false positive rate |
| Stripe payout fails (insufficient funds) | Retry 3x with exponential backoff, escalate to finance team | Delayed payout, advocate notified via email | 99.9% payout success |
| Database unavailable (RDS failover) | Switch to read replica (read-only mode), queue writes | Read-only for 2-5 min, writes queued | 99.95% availability |
| Attribution ambiguous (multiple advocates, same customer) | Split credit proportionally (Shapley value), log for review | Fair attribution, potential disputes | < 1% disputed conversions |
| GDPR deletion request fails (data in 3rd-party CRM) | Delete from primary DB, log CRM deletion task, escalate | Partial deletion, compliance risk | 100% deletion within 30 days |
ββββββββββββββββ
β Orchestrator β β Coordinates all agents
ββββββββ¬ββββββββ
β
βββββ΄ββββ¬βββββββββ¬βββββββββββ¬ββββββββββ¬βββββββββ
β β β β β β
ββββΌβββ βββΌβββ ββββΌββββ ββββΌβββββ ββββΌββββ βββΌβββββ
βPlan β βExecβ βEval β βGuard β βContentβ βAttribβ
βAgentβ βAgentβ βAgent β βAgent β βAgent β βAgent β
ββββ¬βββ βββ¬βββ ββββ¬ββββ ββββ¬βββββ ββββ¬ββββ βββ¬βββββ
β β β β β β
ββββββββ΄βββββββββ΄βββββββββββ΄ββββββββββ΄ββββββββ
β
ββββΌββββββ
β DB β
β CRM β
βPaymentsβ
ββββββββββπAgent Collaboration Flow
πAgent Types
Reactive Agent
LowAttribution Agent - Responds to click events, logs conversions
Reflexive Agent
MediumEvaluator Agent - Uses rules + context (advocate score > 70)
Deliberative Agent
HighContent Generator Agent - Plans content strategy, retrieves examples via RAG
Orchestrator Agent
HighestCoordinator - Routes tasks, handles failures, retries
πLevels of Autonomy
RAG vs Fine-Tuning
Hallucination Detection
Evaluation Framework
Dataset Curation
Agentic RAG
Multi-Touch Attribution
Tech Stack Summary
2026 Randeep Bhatia. All Rights Reserved.
No part of this content may be reproduced, distributed, or transmitted in any form without prior written permission.