Spam/Abuse Detection Pipeline Design
This design outlines a scalable, multi-layered pipeline for detecting and mitigating spam and abuse (e.g., in a social platform, forum, or messaging app). It balances precision, recall, user experience, and operational efficiency. The pipeline processes incoming content/actions in real-time, with offline batch processing for historical analysis.
1. Pipeline Architecture Overview
User Action (Post/Comment/Message) → Signal Extraction → Scoring (Heuristics + Models) → Risk Score → Decision Engine → Action (Allow/Warn/Block/Delete) → Logging/Monitoring → Appeals (if flagged)
↓
Rate Limits & Pre-filters
- Tech Stack Suggestion: Kafka/Redis for streaming, Spark for batch, MLflow for models, PostgreSQL/Elasticsearch for storage.
- Key Principles:
- Multi-stage: Pre-filter (fast heuristics), mid-tier (ML), post-filter (human review for edge cases).
- Adaptive: Models retrain weekly on labeled data.
- Explainable: All decisions log top contributing signals.
2. Signals
Signals are categorized into content, user, behavioral, and contextual features. Extracted in <100ms per action.
| Category | Signals | Examples/Extraction |
|---|
| Content | Textual | - Keyword density (e.g., "free money", URLs).- Repetition (n-grams >80% match).- Sentiment/ toxicity (via Detoxify).- Embeddings (BERT/SentenceTransformers for semantic similarity to known spam). |
| Media | - OCR on images for hidden text.- Hash matching (PhotoDNA for CSAM/known spam images).- EXIF metadata anomalies. |
| User | Profile | - Account age (<24h).- Reputation score (karma/decay over time).- Phone/email verification status.- Past violations (recidivism score). |
| Behavioral | Patterns | - Post velocity (posts/min).- Engagement ratio (likes/views <0.1).- Session anomalies (sudden IP/country change).- Copy-paste detection (via fuzzy matching). |
| Contextual/Network | Graph | - Referral chains (new users from spam domains).- IP/ASN clustering (Tor/VPN flags).- Device fingerprint (browser UA + canvas hash). |
- Signal Aggregation: Normalized [0-1] scores per category, weighted by platform (e.g., text-heavy = 0.4 weight).
3. Models & Heuristics
Hybrid system: Heuristics for speed/low-false-negatives, ML for precision.
Heuristics (Rule-Based, <10ms)
-
Hard Blocks (immediate reject):
| Rule | Threshold | Action |
|---|
| Blacklisted domains/keywords | Exact match | Block + IP ban (24h) |
| Excessive links (>5 in post) | >5 | Quarantine |
| All-caps/repeated chars | >70% | Soft block (require CAPTCHA) |
| Known spam fingerprints | Jaccard >0.9 | Block |
-
Soft Scoring: Fuzzy rules (e.g., if velocity >10/min AND low rep, score +=0.3).
ML Models (50-200ms)
- Primary Classifier: XGBoost/LightGBM on 50+ signals (AUC >0.95 on benchmarks).
- Train on labeled data (human + synthetic via GPT-4).
- Outputs: Binary (spam/not) + risk score [0-1].
- Advanced:
| Model | Purpose | Inputs | Output |
|---|
| Semantic Spam (RoBERTa fine-tuned) | Detect paraphrased spam | Text embeddings | Similarity to corpus (0-1) |
| User Graph (GraphSAGE/Node2Vec) | Botnet detection | Interaction graph | Anomaly score |
| Sequence (LSTM/Transformer) | Burst detection | Time-series of actions | Velocity anomaly |
- Ensemble: Weighted average (heuristics 0.3, primary 0.4, advanced 0.3). Calibrated thresholds via Platt scaling.
- Retraining: Online learning (Vowpal Wabbit) + weekly full retrain on 1M samples.
Scoring & Thresholds
Final Risk Score = 0.3*Heuristics + 0.4*Primary + 0.3*Advanced
| Score | Action | Rate |
|---|
| <0.1 | Allow | 95% traffic |
| 0.1-0.4 | Warn/Throttle (delay + CAPTCHA) | Human review queue |
| 0.4-0.7 | Quarantine/Delete (notify user) | Appeal auto-eligible |
| >0.7 | Block account (shadowban + 7d temp ban) | Appeal required |
4. Limits & Pre-Filters
Enforced via Redis (in-memory counters). Adaptive based on user rep.
| Limit Type | Default | Low-Rep User (<1d old) | High-Rep User |
|---|
| Posts/Min | 5 | 1 | 20 |
| Posts/Day | 100 | 10 | 500 |
| Links/Post | 3 | 0 | 10 |
| New Accounts | 1 post/5min post-registration | N/A | N/A |
| Global | IP: 50 posts/hr; ASN: 1k/hr | Scaled by size | - |
- Burst Protection: Exponential backoff (e.g., 2x delay per violation).
- CAPTCHA/WAF: Cloudflare/Recaptcha on anomalies.
5. Appeals Process
User-centric, low-friction to minimize false positives (<1% target).
Flagged Action → User Notification (in-app/email) → Appeal Button → Review → Resolution (24-48h SLA)
- Automated Tier (80% cases):
| Level | Reviewer | Criteria |
|---|
| Low-risk (score <0.5) | ML Re-score + Human sim (via Llama) | Approve if signals < threshold |
- Human Tier (SRE team, 5-10 reviewers):
- Queue: Priority by score/volume.
- Tools: Explainable AI (SHAP plots), full context (user history).
- Resolution: Approve (80%), Deny (15%), Escalate (5%).
- User Flow:
- Submit appeal with optional evidence (e.g., "legit promo").
- Auto-response in <1h.
- Feedback loop: Approved → Retrain models with new label.
- Abuse Prevention: 3 failed appeals → 30d cooldown; rate limit appeals (1/day).
Monitoring & Iteration
- Metrics: Precision/Recall/F1 (>0.95/0.90/0.92), false positive rate (<0.5%), appeal overturn rate (<10%).
- Dashboards: Grafana for real-time (e.g., block rate by IP), A/B tests for model updates.
- Edge Cases: Whitelists (verified partners), cultural/language adaptation (multi-lang models).
- Scalability: Horizontal scaling; cold-start for new platforms via transfer learning.
This pipeline reduces spam by 95%+ while keeping UX intact. Deploy iteratively, starting with heuristics + primary model. Let me know if you need code snippets, diagrams, or tweaks!