Architecting a Video Safety Screening Pipeline at Scale
System DesignModel answerLast updated
Design a global, multi-modal system that screens uploaded videos for policy violations with ML, escalates uncertain cases to human reviewers, and keeps a tamper-proof decision history.
Build a Safety Screening System for a Video Platform
You are designing the backend that checks every video uploaded to a worldwide short- and long-form video service. The service receives millions of uploads per day. Each video must be judged against community rules such as graphic violence, hateful speech, and sexual content.
What the system must do
- Fast screening. A video should be assessed as soon as it is uploaded.
- Multi-modal inspection. Both the visual frames and the audio track (plus any accompanying text) must be examined.
- Human escalation. Predictions the models are unsure about must be sent to human reviewers.
- Audit trail. Every decision must be stored in a tamper-resistant, append-only record along with the model information that produced it, to satisfy compliance requests.
Quality targets
- An initial moderation signal is available within 5 seconds of upload.
- The system absorbs sudden surges, such as a viral trend, without losing or badly delaying uploads.
- Missed violations (false negatives) on prohibited content should be kept as low as possible.
What to cover in your answer
- A high-level architecture: ingestion, feature extraction, model inference, queues, and the human review path.
- The ML pipeline: how models are served and how they are refreshed with newly labeled data.
- A concise data model for content metadata and moderation decisions.
- The trade-offs between latency and throughput when classifying several modalities together.
State your assumptions about scale up front and justify them.
Hints
Hint 1
Pin down what the 5-second target actually promises. It is likely an initial signal (allow, restrict, block, or escalate), not a final verdict, which lets you split work into a fast pass and a slower deep pass.
Hint 2
Think in cascades: cheap checks first (matching against known bad media), then a lightweight analysis of early frames and audio, then an expensive full-video analysis running asynchronously. Do back-of-envelope GPU math to show why this matters.
Hint 3
Use two thresholds per policy (auto-action vs. send to review), prioritize the review queue by severity and expected reach instead of arrival order, and make the decision log append-only with model version and threshold recorded on every row.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify scope and scale
Assumptions I would state out loud:
- Volume: about 50M uploads/day, roughly 600/s on average. Plan for 5x peaks, so about 3,000/s.
- Video profile: median 30 s, long tail up to 10 minutes, about 20 MB average.
- Meaning of the 5 s target: the initial signal is one of
allow,limit distribution,block, orescalate. A deeper analysis can finish later and revise it. - Error asymmetry: missing severe content (child safety, terrorism) is far worse than a wrongly flagged video. So thresholds are per policy, not global.
- Regional rules: legality differs by country, so a decision is keyed by
(content, policy, region).
Compute check: 3,000 videos/s x about 10 sampled frames = 30k frame inferences/s. A ViT-B-class model with batching handles roughly 1-2k images/s per GPU, so vision alone needs about 20-40 GPUs, before audio and text. This justifies sampling and cascades.
2. Architecture
Upload service -> Object store
|
+-> Kafka: video.uploaded -> Orchestrator (per-video DAG, priority-aware)
| | | |
Hash match Frame/keyframe Audio: ASR + Text: title,
(known bad) vision models event model caption, OCR
+------------+------+------------+-----------+
v
Fusion model + policy engine
|
allow -------- gray zone -------- block
| | |
Staged distribution Review queue Enforcement
|
Reviewer UI
|
Append-only decision log -> Data lake -> Retraining
Key choices:
- Async decoupling. Upload returns immediately. The video stays owner-only until an initial signal exists. Kafka absorbs spikes; GPU workers autoscale on consumer lag.
- Three-stage cascade.
- Hash match (about 10 ms) against known violating media using perceptual hashes plus a vector index. A hit means instant block.
- Fast pass on keyframes from the first few seconds, the first audio chunk, and metadata text. This yields the 5 s signal.
- Deep pass on the full video at higher frame rate with full ASR and a temporal model. It runs asynchronously and can overturn the earlier verdict.
- Staged distribution. Even allowed videos ramp through reach tiers (e.g. 0, 500, 10k views). Each tier can trigger re-scoring using the deep model and user reports, which bounds damage from false negatives.
3. ML pipeline
Models
- Vision: CLIP/ViT-style frame encoder plus a light temporal model for actions such as fighting.
- Audio: ASR into a multilingual toxicity model, plus an audio-event classifier (gunshots, screaming).
- Text: title, caption, and OCR text through a text classifier.
- Late fusion combines embeddings, scores, and context (uploader history, region) into per-policy probabilities. Late fusion allows emitting a partial result if one modality is slow, which protects the SLA.
- Calibration (temperature or isotonic) per policy so that thresholds keep their meaning across model versions.
Serving
- Triton/TensorRT-style servers with dynamic batching and FP16/INT8 quantization.
- Separate GPU pools for fast and deep paths so a deep backlog cannot starve the SLA path.
- Priority queues favor live content and high-reach uploaders.
Thresholds and humans
For each policy: score >= t_block auto-actions; t_review <= score < t_block goes to humans; below t_review is allowed with staged ramp. Keep t_review low for severe policies (recall first), tuned against reviewer capacity. Rank the queue by P(violation) x severity x expected reach, not FIFO. Reviewer decisions flow back as labels.
Model updates
- Retrain daily or weekly on fresh labels.
- Each candidate runs in shadow mode (scores live traffic, takes no action), then a canary on 1-5%.
- Promotion gates: per-policy recall at fixed precision on a frozen golden set, plus per-language and per-region slices.
- Keep the previous model deployable for instant rollback.
Cold start and drift
- New policies: zero-shot CLIP prompts, few-shot linear probes, vendor data.
- Active learning samples near-threshold items, cross-modality disagreements, user reports on allowed videos, and new embedding clusters.
- Red-team for adversarial edits (crops, overlays, re-encodes) and add them as augmentation.
4. Data model
content(content_id PK, uploader_id, region, duration_s, media_uri, phash, upload_ts, status)
model_registry(model_version PK, policy_set, training_snapshot, metrics, thresholds, deployed_at)
moderation_decision(decision_id PK, content_id, stage{hash|fast|deep|human|appeal},
policy, score, action, model_version, threshold_used,
reviewer_id NULL, reason_code, ts, prev_decision_id)
review_task(task_id PK, content_id, priority, policies[], assigned_to, sla_deadline, state)
moderation_decisionis append-only; corrections add a row pointing toprev_decision_id.- Stream decisions through Kafka into a WORM (object-lock) store and an OLAP warehouse for audits.
- Persisting
model_versionandthreshold_usedmakes every decision reproducible. - A key-value store (Cassandra/DynamoDB) holds the current state per content for low-latency reads.
5. Latency vs. throughput trade-offs
- Batching: larger GPU batches raise throughput but add queueing delay. Use a small max-wait (e.g. 5-10 ms) on the fast path and larger batches on the deep path.
- Frame sampling: more frames improve recall on brief violations but cost linearly. Sample early frames densely for the fast pass, adaptively later.
- Modality parallelism: run modalities in parallel and fuse on whatever is ready by a deadline; missing modalities get a conservative default (escalate for severe policies).
- Model size: distilled/quantized models on the fast path, large models on the deep path.
- Over-provisioning vs. autoscaling: GPU cold starts are slow, so keep warm headroom for the fast pool and let the deep pool absorb delay.
6. Common mistakes
- Treating the 5 s target as a final verdict and ignoring the deep pass.
- A single global threshold across policies and regions.
- FIFO review queues, which let low-risk items delay severe ones.
- Mutable decision records, which break auditability.
- Promoting models on aggregate accuracy without per-policy and per-language slices.
- Not accounting for reviewer capacity and wellbeing (rotation, exposure limits, blurred previews).