Build a Multimodal Content Moderation Pipeline
Machine LearningModel answerLast updated
Design an ML system to classify and filter harmful user-generated content across text, images, and video at high throughput with strict latency constraints.
You're building a content moderation system for a social platform that needs to evaluate user uploads for policy violations including hate speech, graphic violence, adult content, spam, and self-harm imagery.
Requirements
Your platform receives 100,000 uploads per second containing:
- Images with text captions (majority of traffic)
- Text-only posts
- Short-form videos (under 60 seconds)
The system must:
- Classify each upload and assign risk scores across multiple violation categories
- Prevent harmful content from reaching other users
- Complete classification within 200ms to avoid blocking the upload flow
- Handle traffic spikes up to 3x normal volume
- Maintain high precision (minimize false positives that frustrate legitimate users)
What to Cover
Design the end-to-end system including:
- Overall architecture: How you'll process different content types within the latency budget
- Model approach: How you'll handle multiple modalities (text, image, video) together
- Training pipeline: Where labels come from, how you handle edge cases, and how you ensure quality
- Production operations: Monitoring for model degradation, handling scale, and continuous improvement
Discuss trade-offs explicitly. A complete video analysis won't fit in 200ms—explain how you'd handle that constraint.
Hints
Hint 1
Most content is benign. Design a cascade where cheap filters handle the common case and expensive models only see flagged items.
Hint 2
Video processing is too slow for synchronous decisions. Consider what intermediate action you can take while deeper analysis runs in the background.
Hint 3
False positives create user friction and appeals. Think about how you'll set thresholds and measure precision across different violation types.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer
1. Requirements and Scale Analysis
Start by quantifying the problem:
- Traffic: 100k requests/second baseline, plan for 300k/second bursts during viral events
- Volume: ~8.6 billion items daily
- Content distribution (estimate): 60% image+text, 25% text-only, 15% video
- Violation rate: Assume ~1% harmful (1,000 violations/second to catch)
- Latency: p99 < 200ms for the synchronous decision path
- Precision target: ≥95% per category to minimize false positive appeals
Key insight: Video frame extraction and analysis takes several seconds. We cannot process full videos synchronously.
2. System Architecture: Multi-Stage Pipeline
Use a cascade design where each stage filters out more benign content:
Stage 0: Deterministic Rules (~5ms)
- Perceptual hash matching: Compare uploads against a database of known violations using PDQ or similar hashing
- Blocklist matching: Check URLs, domains, exact text phrases
- Velocity rules: Flag accounts uploading suspiciously fast
- Handles ~2-5% of traffic with exact matches at near-100% precision
Stage 1: Fast Lightweight Models (~30ms)
- Text classifier: Distilled multilingual model (e.g., DistilBERT-based) on captions and text posts
- Image classifier: Lightweight CNN on downsampled thumbnails (224x224)
- Context features: Account age, prior violations, reputation score
- Combiner: Gradient boosted tree merges signals into per-category risk scores
- Throughput: ~90% of traffic scores clearly safe and passes immediately
Stage 2: Full Multimodal Model (~100ms)
- Processes the ~10% flagged by Stage 1 (10k RPS)
- Fusion architecture (described below)
- For video: sample 8-10 keyframes uniformly and score along with caption
- Returns per-category scores and decision
Decision Logic
- Block threshold: Auto-block high-confidence violations
- Uncertainty zone: Mark as HOLD (invisible) or LIMITED (visible only to uploader/followers)
- Allow threshold: Publish normally
Asynchronous Deep Analysis
- Runs in parallel via message queue (Kafka)
- Full video temporal models, audio transcription (ASR), OCR on frames
- Retroactive scoring based on early engagement signals (report rate, comment toxicity)
- Can upgrade HOLD→ALLOW or downgrade ALLOW→BLOCK
- Videos start as LIMITED until cleared
3. Multimodal Fusion Strategy
Three architectural options:
Late fusion (separate models, combine scores): Cheap and modular, but misses cross-modal patterns like hateful memes where benign image + benign text = harmful.
Early fusion (single end-to-end model): Captures full interactions but expensive, requires massive joint training data, difficult to update.
Recommended: Intermediate fusion
- Pre-trained encoders per modality:
- Text: Multilingual transformer (XLM-RoBERTa)
- Image: Vision transformer from CLIP or SigLIP
- Video: Frame embeddings + temporal pooling, plus audio→text via ASR
- Small cross-attention transformer over combined embeddings
- Separate classification heads per violation category
- Benefits: Reusable encoders, captures interactions, graceful degradation
Key techniques:
- Modality dropout during training so model handles missing inputs
- OCR on images to catch text-in-image violations
- Cache embeddings for deduplication and other downstream uses
4. Training Data and Labeling
Cold Start
- Write detailed policy guidelines first—labels follow policy clarity
- Bootstrap from public datasets (Jigsaw Toxic Comments, Hateful Memes)
- Use GPT-4V or similar as weak labeler with policy-based prompts, then expert audit
- Launch conservatively with high block thresholds and heavy HOLD usage to accumulate real labels quickly
Gold Evaluation Set
- 3 expert annotators per item plus adjudication
- Track inter-annotator agreement (Fleiss' kappa or Krippendorff's alpha)
- Stratified by category, language, modality
- Never used for training, only evaluation
- Versioned with policy changes, refreshed monthly
- All production thresholds calibrated against this set
Training Data Sources (ranked by value)
- Appeal overturns: Confirmed false positives, critical for precision
- Human review decisions: Items in uncertainty band reviewed by moderators
- Active learning: Model-selected boundary cases
- User reports: High volume but noisy
- Weak labels: Synthetic or model-generated, audited samples only
Edge Cases
- Benign-looking violations: News coverage of violence, educational anatomy, reclaimed slurs, satire
- Context-dependent content: Verified news accounts get different treatment
- Low-resource languages: Dedicated slices in evaluation, multilingual models
- Maintain hard-negative collections for each edge case type
5. Infrastructure and Serving
Model Serving
- Triton Inference Server with dynamic batching (5-10ms windows)
- FP16 or INT8 quantization for 2-4x speedup
- Stage 1: ~3k items/sec/GPU → 35 GPUs at baseline, 100 at burst
- Stage 2: ~300 items/sec/GPU → 35 GPUs at baseline, 100 at burst
- Autoscale on queue depth with warm pool (GPU cold start is slow)
Overload Handling
- Fail closed: Under saturation, flag uncertain items as HOLD rather than allowing unchecked
- Shed async work first (video deep pass, retroactive scoring)
- Load shed at Stage 1 if Stage 2 queue grows too large
Data Stores
- Decision log: Immutable audit trail (content_id, scores, decision, model_version, timestamp)
- Feature store: User reputation, velocity, historical violations
- Hash database: Known-bad content fingerprints
- Label database: Training labels with provenance, confidence, policy version
6. Monitoring and Continuous Improvement
System Health Metrics
- Latency percentiles (p50, p95, p99) per stage
- Stage 2 routing rate (spike indicates drift or attack)
- GPU utilization and queue lag
- HOLD backlog size
Model Quality Metrics
- Precision/recall per category on gold set (daily)
- Precision at operating point (actual block threshold)
- False positive rate from appeals
- Coverage: violation prevalence in reported-but-allowed content
- Per-slice metrics (language, content type, violation category)
Drift Detection
- Input drift: Distribution shift in embedding space, vocabulary changes
- Prediction drift: Score distribution changes compared to baseline
- Outcome drift: Human override rate, appeal rate trending up
Release Process
- Weekly retrain on accumulated labels
- Evaluate on gold set: require no per-category regression
- Shadow deployment: run new model alongside champion for 24 hours
- Canary: 5% traffic for 48 hours monitoring precision
- Recalibrate thresholds using isotonic regression so operating points stay stable
- Full rollout if metrics hold
Common Mistakes to Avoid
- Ignoring precision: False positives create user backlash and legal risk
- No cold-start plan: Waiting for organic labels takes too long
- Treating all errors equally: Blocking educational content about suicide prevention is worse than missing a spam post
- Synchronous video processing: Physically impossible, need async path
- Single global threshold: Different categories need different precision/recall trade-offs
- No policy versioning: Labels become meaningless when policy changes
- Training on gold set: Overfits evaluation, gives false confidence
Follow-up Considerations
- Adversarial robustness: Character substitutions, image perturbations, prompt injection
- Fairness: Dialect bias, cultural context differences, demographic performance gaps
- Privacy: Cannot store raw content indefinitely, only decisions and hashes
- Regional compliance: Different legal definitions of harmful content by jurisdiction
- Human reviewer wellness: Traumatic content exposure, tooling to reduce burden