Design a Code Injection Detection System

Hard45 min
1 / 30
System design answer

Design a Code Injection Detection System

Hard45 min30 sections
understanding•10 min read

Problem Statement: Injection Detection as a Distributed Security Plane

Frames injection detection as a cyber-physical-style security platform spanning edge, runtime, analysis, and response rather than a single validation library.

Problem statement

Design a code injection detection platform that watches user-controlled input and code execution paths across a large microservice fleet for evidence of injection attacks: SQL injection, command injection, script injection (cross-site scripting), template and expression-language injection, LDAP injection, and unsafe deserialization reaching interpreter sinks. The platform must analyze traffic in real time or near real time, combine heuristic and ML detection, optionally hook database and interpreter calls inside application runtimes, alert security analysts, and automatically block high-confidence attempts.

Injection remains durable because it exploits one fundamental mistake: attacker-controlled bytes cross from the data plane into a control plane, where a SQL engine, shell, script engine, template renderer, or directory parser executes them as instructions. Input validation alone cannot fully solve this: validation lives at one entry point, while the actual harm happens later at a sink, after transformations, caching, and reassembly across services. A serious detection system therefore observes the journey of data, not just the front door.

Why the problem is distinctive

A rate limiter can retry. A cache can be stale. A missed injection event can become a data breach. Three properties shape the entire architecture:

  1. Latency is a hard constraint. Detection sits on the request path or immediately beside it. A scanner that adds 50 ms p99 will be disabled by the platform team within a week.
  2. Accuracy is the product. A detector that blocks legitimate traffic at 0.5% causes an outage; one that misses structured attacks is decoration. False-positive and false-negative rates are first-class SLOs.
  3. The detector is itself a target. Attackers probe for the detector, attempt to blind it with floods, and benefit from stale rules. Rules, models, and agents must be signed, versioned, and tamper-evident.

The four architectural planes

  1. Perimeter plane: edge and gateway analysis of request structure before application code runs, WAF-style.
  2. Runtime plane: in-application agents that hook database drivers, interpreter calls, template engines, and process execution, observing what validation cannot see.
  3. Analysis and control plane: rule distribution, model serving, fleet management, verdict aggregation, and detection tuning.
  4. Response and governance plane: alerting, case management, automated blocking, SIEM export, audit, and compliance evidence.

A strong answer keeps these planes separate. The runtime plane must keep rendering verdicts during a control-plane outage; the response plane must never rewrite detection evidence; and model updates must not silently expand what the system enforces.

Public operating baseline versus design assumptions

Public evidence establishes that this category is operationally real. OWASP has listed injection-family flaws in every Top 10 release since 2003 and consolidated cross-site scripting into the Injection category (A03) in the 2021 edition. The OWASP ModSecurity Core Rule Set ships anomaly-scoring rules used by ModSecurity deployments worldwide. Cloudflare publicly describes an ML-based WAF attack score that complements its managed rules, and Datadog built application security management on the in-app agent technology it acquired with Sqreen in 2021. Contrast Security sells runtime instrumentation agents for the same threat class, and Baidu open-sourced OpenRASP, a runtime application self-protection project that hooks runtime functions.

For capacity planning, this answer explicitly assumes a mature internal platform: 5,000 microservices, 40,000 instrumented instances, 200,000 requests per second average, a 3x campaign peak, and 2,000 detection events per second average. Unless a number is attributed to a named company, it is a stated design assumption, target, or budget, not a claim about any vendor's private architecture.

Interview positioning

Most candidates say 'use parameterized queries and a WAF.' That is prevention advice, not a detection system design. The differentiating answer covers: inline structural scanning, driver-level hooking, taint-aware context, anomaly scoring with thresholds, per-route enforcement modes, signed rule distribution, and an analyst workflow that turns detections into closed cases. This answer is built to hit every one of those.

Key Highlights

  • •Injection happens when user-controlled bytes cross from the data plane into an interpreter's control plane.
  • •Detection spans four planes: perimeter, runtime, analysis/control, and response/governance.
  • •The runtime plane must keep rendering local verdicts during total control-plane outage.
  • •All uncited scale numbers are explicit design assumptions: 40K instances, 200K req/s average.
  • •The detector itself is a target: rules, models, and agents are signed, versioned, and tamper-evident.
Lead With the Data-to-Control Crossing
State in the first two minutes that injection is a boundary-crossing problem between data and interpreter control planes. This instantly distinguishes a detection architecture from a checklist of validation tips.
Do Not Reduce This to a WAF Box
A design where all detection happens at one edge appliance misses driver-level hooking, taint context, and per-route enforcement, which is exactly where this question asks you to go deeper than typical references.

Section Rescue Kit

Buzzwords to use:

SinkAnomaly Scoring

Safe statements:

  • "I will separate where detection happens from where decisions are enforced, because those are different failure domains."
  • "Before choosing components, let me define which verdicts must remain possible when the control plane is unreachable."
Design a Code Injection Detection System - System Design | WinJob | WinJob