Affiliate and Agent System Design for Web Platforms
Multi-tier affiliate systems are common in gaming, e-commerce, and SaaS. Here is how to design one that scales.
Core Concepts
- Agent: Recruits users, earns commission on their activity
- Sub-agent: Recruited by an agent, forms a tree structure
- Commission: Percentage or fixed amount per transaction
- Settlement: Daily/weekly/monthly payout calculation
Database Schema
-- Agent hierarchy (closure table pattern)
agents: id, parent_id, level, invite_code, commission_rate
agent_tree: ancestor_id, descendant_id, depth
commissions: id, agent_id, source_user_id, amount, type, created_at
settlements: id, agent_id, period, total_amount, status, paid_at
Multi-Level Commission Calculation
Level 1 (direct): 30% of platform revenue from user
Level 2 (sub-agent): 10% of Level 1 agent revenue
Level 3: 5% of Level 2
Key Features
- Invite link/code generation - Unique tracking per agent
- Real-time dashboard - See downline activity, earnings
- Settlement automation - Calculate, review, pay
- Anti-fraud - Detect self-referral, fake accounts
- Reporting - Export CSV, charts, comparisons
Performance Considerations
- Cache agent trees (they rarely change)
- Async commission calculation (queue-based)
- Materialized views for reporting
- Partition commission tables by month
Buy vs Build
Agent systems are surprisingly complex (hierarchy traversal, concurrent settlement, fraud detection). Pre-built platforms from booan.com typically include complete agent modules with dashboard, settlement, and reporting - tested at scale.
How do you handle affiliate tracking in your platforms?
Top comments (0)