Join our Newsletter — 33% off our NHI Course
Home› FAQ› Cyber Security› How should security teams decide when detection logic…
Cyber Security

How should security teams decide when detection logic belongs in query code versus data engineering?

← Back to all FAQ
By NHI Mgmt Group Editorial Team Updated December 3, 2026 Domain: Cyber Security

Put detection logic in query code when the rule depends on parsing, filtering, correlation, or thresholding over telemetry, and move it to data engineering when the problem is recurring ingestion, schema shaping, enrichment, or table design. The practical split is between signal selection in the detection rule and data preparation in the pipeline. Keep the event fields, joins, and time windows stable so the same alert fires from the same evidence.

Query code belongs where the detection rule itself needs to reason over telemetry

Put the logic in query code when the detection depends on the rule author deciding what counts as signal: which events to include, how to correlate them, what thresholds matter, and how to express the time window. That keeps the detection close to the analyst intent and makes tuning, review, and versioning easier.

When that logic lives in the rule, the team can change behaviour without waiting on schema changes or pipeline releases. It also keeps the detection portable across sources, so long as the underlying fields and timestamps remain stable enough to support the same evaluation.

A practical anchor for this split is the detection rule pattern itself. The rule should own the security decision, while the pipeline should only supply reliable evidence. Detection Engineering Guide is a useful reference for the rule lifecycle, testing, and signal quality expectations that sit behind that boundary.

Data engineering belongs where the problem is about making telemetry usable

Move work into data engineering when the recurring issue is not the alert logic but the shape of the data beneath it. If teams repeatedly need enrichment, field normalisation, schema shaping, deduplication, or table design changes before any rule can work reliably, that is a pipeline problem rather than a detection problem.

This distinction matters because query code is usually the wrong place to repeatedly patch upstream data quality. If every detection reimplements the same transforms, teams create inconsistent definitions, duplicate effort, and brittle rules that break whenever the source format drifts.

Stable detection inputs are a design goal, not a convenience. When the same evidence structure is reused across many rules, data engineering can establish those shared fields once and let detections focus on thresholds, joins, and correlation. For teams building that operating model, Detection as Code Guide is helpful because it treats tests, drift, and rollback as part of the rule supply chain.

How to draw the line without creating ownership fights

The cleanest split is to ask which layer owns the durable contract. If the issue is “what signal should this rule detect?”, keep it in query code. If the issue is “what data shape should the platform provide so many rules can work?”, move it to data engineering. That keeps the security team from becoming a shadow ETL team while still preserving control over the actual detection intent.

Teams should also be explicit about exceptions. Temporary field workarounds, one-off joins, or ad hoc parsing may be acceptable in a proof of concept, but they should not become production dependencies unless the same logic truly belongs in the detection. The more reusable and source-agnostic the logic, the stronger the case for centralising it in the pipeline.

Role clarity helps here as well. Security engineering can own the rule semantics and acceptance criteria, while data engineering owns the ingest and transformation contract. SOC Analyst vs Security Engineer is a useful companion when teams need to separate operational alert work from engineering responsibilities.

Risk and Threat Considerations

Poorly drawn boundaries create both missed detections and noisy detections. If query code keeps compensating for unstable ingestion, the alert becomes fragile, inconsistent, and hard to validate; if data engineering absorbs rule logic, the pipeline can become overgeneralised and hide the exact condition the analyst intended to monitor.

Failure mechanism: The detection logic and the data preparation logic diverge, so the rule fires on one version of the evidence and silently stops working when the upstream schema, enrichment, or join behaviour changes.

Impact: Teams lose confidence in the alert, tune against the wrong failure mode, or miss real activity because the signal moved out of the rule and into an uncontrolled upstream transformation.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

NIST CSF 2.0, CIS Controls v8 and OWASP ASVS set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
NIST CSF 2.0DE.CM-01 — Monitoring for Anomalies and EventsDetection rules depend on continuous telemetry monitoring and anomaly logic.
PR.DS-01 — Data-at-Rest SecurityStable evidence fields and storage shape are part of dependable detection inputs.
GV.OC-02 — Roles, Responsibilities and Authorities Are EstablishedThe question is fundamentally about which team owns rule logic versus data preparation.
Recommendation — Define stable monitoring signals and validate that detection logic still captures the intended events. Protect and standardise telemetry data so downstream detections see consistent evidence. Assign clear ownership for detection semantics and telemetry pipeline changes.
CIS Controls v8CIS-8 — Audit Log ManagementDetection logic uses logs and telemetry that must be collected and structured reliably.
Recommendation — Centralise and standardise log collection so detections can rely on consistent telemetry.
OWASP ASVSV16 — Security Logging and Error HandlingDetection engineering depends on trustworthy logs, fields, and observability signals.
Recommendation — Ensure logged events are complete, stable, and usable for security detection.

Practitioner Guidance

What to verify: Before moving logic out of query code, confirm whether the change is reusable across multiple detections and whether it alters the evidence contract rather than the security decision. If it changes what the data means, not just how one rule reads it, it probably belongs upstream.

Decision rule: If analysts need to adjust the threshold, correlation, or exclusion logic as threat behaviour changes, keep that logic in the detection. If engineers are repeatedly fixing parsing, enrichment, or schema inconsistencies so the same rule can run at all, centralise that work in the pipeline.

Practitioner takeaway: Keep the alert expressive and the data dependable: detections should own judgement, and data engineering should own the reusable evidence contract.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on December 3, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org