Screening Pipeline for Abusive Jobs and Memory Crashes
Machine LearningModel answerLast updated
Design an ML-backed gate for a shared compute platform that flags abusive submitted code or text and predicts memory-exhaustion crashes, with low latency, high precision, and drift monitoring.
Screening Pipeline for Abusive Jobs and Memory Crashes
You run a multi-tenant data processing platform where users submit jobs made of code, configuration, and sometimes free text. Two kinds of bad jobs need to be caught early:
- Abusive or prohibited content. Toxic text, illegal material, malware, crypto-miners, credential theft, and similar misuse hidden in submitted code or text.
- Likely memory exhaustion. Jobs that will probably crash with an out-of-memory (OOM) error and waste cluster capacity, or destabilize a shared node.
Design an ML-based screening system that handles both.
Requirements
Functional
- Low-latency inference suitable for real-time screening at submission.
- Retraining pipelines that adapt to new abuse patterns.
- Automated mitigation: reject, warn, throttle, hold for review, or adjust resources.
Non-functional
- Throughput of thousands of concurrent submissions.
- High precision, so legitimate but complex code is not blocked.
- Robustness against users who deliberately try to evade the filter.
Your answer should cover
- Taxonomy and data: how you define "harmful", and what data you use to train the memory predictor.
- Modeling: which model families you use for content classification versus resource forecasting.
- Architecture: the path from submission to decision, and where screening plugs into job execution.
- Monitoring: how you detect drift, adversarial pressure, and degradation in production.
State your assumptions about scale and latency budgets, and discuss the main trade-offs.
Hints
Hint 1
Treat the two problems differently: content safety is adversarial, memory prediction is cooperative. Share infrastructure (gateway, features, policy engine, feedback loop) but specialize the models.
Hint 2
Not every check has to block the submission. Do cheap, high-confidence checks synchronously, and run expensive or uncertain analysis asynchronously while the job runs in a restricted sandbox.
Hint 3
Memory-crash labels come for free from runtime outcomes, but early-cancelled jobs are censored, and a crash costs far more than over-provisioning. Think about quantile prediction and asymmetric costs.
Hint 4
For monitoring, think about score distributions, reviewer-confirmed precision, appeal overturn rate, and how new confirmed abuse examples can take effect before the next full retrain.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Framing
This is two different ML problems behind one serving path. Content safety is adversarial classification: attackers adapt. Memory prediction is cooperative forecasting: users do not hide their workloads. I would share the gateway, feature store, policy engine, and feedback loop, and specialize the models.
1. Assumptions and targets
- Peak around 2,000 submissions/s, roughly 50M jobs/day, average payload about 20 KB.
- Synchronous pre-screen: p99 ≤ 100 ms, since job startup already takes seconds. Deeper analysis is asynchronous.
- A hard block needs ≥ 99% precision. Lower-confidence cases get softer actions (warn, throttle, review).
- Cost asymmetry for OOM: a crash wastes the whole job and may hurt neighbors, while over-provisioning wastes only the delta. So bias toward conservative (upper-quantile) estimates.
- Default scope is code and text; scanning the processed data is sampled and asynchronous.
2. Taxonomy and data
Define harm by severity tier, each with a fixed action:
| Tier | Examples | Action |
|---|---|---|
| S0 | Illegal content, sandbox escape, credential exfiltration | Block, preserve evidence, escalate |
| S1 | Crypto-mining, outbound scanning or DoS, malware staging | Block or hold for review |
| S2 | Toxic text, policy-gray workloads | Allow, flag, sample for review |
Content data: past abuse incidents, honeypot workspaces, known miner and malware signatures, public toxicity datasets, red-team and LLM-generated adversarial variants, and reviewer labels.
Memory data: historical job telemetry joined to outcomes. Features:
- query plan: join types, shuffle partitions, broadcast sizes, stage count;
- input statistics: bytes, rows, key skew;
- code patterns:
collect(),toPandas(), Python UDFs, caching; - cluster config: executor memory and cores;
- lineage: prior peak memory for the same job or notebook.
Targets: peak memory divided by available memory (regression), plus an OOM indicator. Jobs cancelled early are right-censored, so do not label them as "no OOM".
3. Models
Content: a cheap-first cascade
- Normalize: decode base64 and hex, de-minify, parse to an AST, strip comments, resolve string concatenation. This defeats trivial obfuscation.
- Rules and hashes (under 5 ms): exact and fuzzy hashes of known-bad artifacts, mining-pool domains, egress patterns.
- Embedding model (about 20-40 ms on GPU): a distilled code-and-text encoder with a classification head, plus a kNN lookup against a bank of confirmed-bad embeddings. The kNN bank catches paraphrases and makes new incidents effective in minutes without retraining.
- Escalation (async): uncertain cases go to an LLM judge with the policy in context, then to human review.
Memory: two stages
- Static, at submission: a gradient-boosted tree quantile regressor (p50 and p95 peak memory) on plan and input features. It handles heterogeneous tabular data well and serves in under 5 ms.
- Dynamic, at runtime: stream executor memory, GC time, and spill metrics every few seconds into a light forecaster (GBDT on rolling windows, or a small temporal CNN or LSTM) that predicts time-to-OOM. This catches issues invisible beforehand, such as skew discovered during a shuffle.
4. Architecture and integration point
Submit -> Gateway -> Pre-screen (sync, parallel)
|-- content cascade (rules -> embedding/kNN)
|-- static memory model (plan + feature store)
-> Policy engine (thresholds, tiers, user risk) -> Scheduler
async: LLM judge, data sampling, review queue
Runtime: executor agents -> stream -> memory forecaster -> mitigator
Sync vs async: the synchronous gate handles only cheap, high-confidence decisions (S0/S1 blocks, gross memory risk such as collecting a multi-TB table to the driver). Everything else runs asynchronously while the job executes in a restricted sandbox: no egress, quota cap, lower priority until cleared.
Failure mode: if screening is down, fail open for established low-risk tenants and fail closed for new or low-trust accounts.
Graded mitigations: warn, auto-tune config (more memory or partitions), throttle, hold for review, block. Runtime mitigations include enabling spill, repartition hints, scaling up, or kill-and-retry with more memory.
Scale: stateless model servers behind autoscaling, batched GPU inference, and a score cache keyed by normalized-code hash. Resubmitted notebooks dominate traffic, so 60%+ cache hit rates are realistic.
5. Feedback loop and retraining
Labels come from reviewers (active learning on the uncertain band and novel clusters), appeals (false positives), runtime outcomes (automatic memory labels), and security incidents (false negatives). They go to a versioned label store. Retrain weekly or on trigger; add confirmed-bad embeddings to the kNN bank immediately.
Gate each release on a frozen golden set, a held-out red-team set, and a shadow run on live traffic.
6. Monitoring
- Content: block rate per category, reviewer-confirmed precision, appeal overturn rate, score-distribution shift (PSI or KL), embedding-space novelty, and spikes of near-threshold scores that suggest probing.
- Adversarial signals: per-user and per-workspace patterns of repeated small variations of blocked jobs, rate limits, and escalating user risk scores.
- Memory: calibration of quantiles (does p95 cover 95% of outcomes?), OOM rate by predicted bucket, over-provisioning waste, and feature drift after platform or runtime upgrades.
- Operations: latency percentiles, cache hit rate, fallback rate, and queue depth.
Trade-offs and common mistakes
- Over-blocking: using one threshold for everything. Use tiers and graded actions to protect precision.
- Single model for both tasks: the data, labels, and failure costs differ.
- Ignoring evasion: a pure text classifier without normalization is trivial to bypass.
- Ignoring censoring and asymmetric cost in memory labels.
- Putting every check on the critical path: it blows the latency budget; use the sandbox plus async escalation.
- No ground truth plan: without reviewers, appeals, and runtime outcomes there is no way to measure precision after launch.