Skip to content

Interview question · Detection Engineering & Incident Response

Design a detection-as-code programme: how are detections written, tested, reviewed, deployed and retired?

Detections are production code that pages people. Treating them that way means version control, tests that prove they fire, review, staged rollout and metrics that decide which ones live.

hardNewPreparation tags: CrowdStrike, Google, MicrosoftUpdated Nov 2026

TL;DR: Store every detection in a repository as code plus metadata: the query or rule, the technique it targets, severity, data sources, owner, runbook link and tests. Tests include positive samples that must match (recorded or synthesised telemetry of the technique) and negative samples of known benign activity that must not. CI validates syntax, runs the tests, checks required metadata and lints for expensive queries; changes are peer-reviewed; deployment is automated, staged (shadow mode before paging) and reversible. In production, measure each detection's volume, precision and time to triage, test the logging pipeline continuously with emulated attacks, and retire or rework rules that do not earn their cost. The outcome is a detection set you can trust and change quickly.

How to approach it

Describe the repository structure and what each detection carries, then the testing strategy (the part most teams skip), then review and deployment, then operating metrics and lifecycle. Mention portability formats such as Sigma, and how to test the data pipeline as well as the rules.

A strong answer

FIG · DETECTION AS CODE · WRITE, TEST, REVIEW, DEPLOY, RETIRE
Detections live in a repository like any software

Rule + metadata

technique, owner, runbook

Tests

positive and benign samples

Peer review

pull request

CI deploy

to the SIEM

Measure, retire

precision, value

What a detection is in the repository.

id: win-local-admin-added
title: Account added to local Administrators on a server
technique: T1136.001
severity: high
data_sources: [windows_security]
owner: detection-team-identity
runbook: runbooks/local-admin-added.md
query: |
  (vendor-specific query or a Sigma rule compiled per backend)
exceptions:
  - reason: provisioning service on config-mgmt hosts
    owner: platform-team
    expires: 2027-05-01
tests:
  positive: [tests/local-admin/net-localgroup.json, tests/local-admin/powershell.json]
  negative: [tests/local-admin/provisioning-run.json]

Sigma is a vendor-neutral rule format that compiles to many SIEM query languages, which helps portability and sharing; complex correlations may still need native queries.

Testing.

  • Unit tests: feed recorded events (positive and negative) through the rule logic and assert matches. Captured from lab reproductions, emulation runs or sanitised incidents.
  • Integration tests: run emulated techniques (adversary emulation frameworks such as Atomic Red Team or Caldera) on lab or canary hosts on a schedule, and assert that the alert appears end to end within an expected time. This catches broken log forwarding, parser changes and field renames, which silently kill detections.
  • Performance checks: flag queries that scan too much data or run too long.

Review and deployment.

  • Pull requests reviewed by another detection engineer for logic, false-positive risk and runbook quality.
  • CI gates: syntax, tests, metadata completeness, exception expiry dates.
  • Deployment pipeline pushes rules to the SIEM or data platform via API; manual console edits are disallowed or detected.
  • New or significantly changed rules run in shadow mode (logged, not paged) for a period; then promoted.
  • Rollback is a revert.

Operating it.

MetricUse
Alerts per day per ruleSpot noisy rules
Precision (true positives over triaged alerts)Decide tuning or demotion
Mean time to triageRunbook and context quality
Days since last true positiveCandidate for review or retirement
Integration test pass ratePipeline health
Technique coverage with tested rulesPlanning

Rules with persistently low precision are tuned, demoted to correlation inputs, or retired. Exceptions expire and are re-justified.

People and process. Analysts file feedback (false positive, missing context) that becomes issues in the repository; incidents produce new detections and tests as a post-incident action; threat intelligence drives the backlog.

AI systems. The same discipline applies to detections over AI telemetry: prompts flagged by injection classifiers, unusual tool-call sequences, agents accessing data outside their task, token-usage spikes. These need test fixtures too, including benign prompts that resemble attacks.

FIG · BYPASSED VS PROTECTED · DETECTION ENGINEERING
Rules edited in the console versus detections as tested, reviewed code

Console edits

Analyst changes rule live

no test

Rule silently breaks

misses attacks

Blind spot

Outcome, unsafe: No history

Noise grows

Detection as code

Rule + tests in repo

positive and benign samples

Review, CI deploy, metrics

owners, retirement

Breaks caught in CI

Outcome, safe: Changes audited

Quality measured

What interviewers probe next

  • "How do you test a detection for something you've never seen in your environment?" Reproduce it in a lab with emulation tools or hand-crafted telemetry, and keep the sample as a test fixture.
  • "A log source changes a field name. How would you notice?" Scheduled end-to-end emulation tests fail, and data-quality checks on expected fields alert before an attacker exploits the gap.
  • "Who owns a detection?" A named team for each rule, responsible for its precision, runbook and exceptions.

What if?

What if · interview follow-ups

Hold your answer as the constraints change

A detection team manages hundreds of SIEM rules edited directly in the console, and nobody knows which ones still work.

  1. Start here

    What does detection-as-code mean?

How it's scored

Weak: "Store queries in Git."

Hire: Version control with metadata, unit tests with positive and negative samples, review and automated deployment.

Strong Hire: Adds end-to-end emulation tests that catch pipeline breakage, shadow-mode rollout, performance linting, exceptions with owners and expiry, production metrics driving tuning and retirement, feedback loops from analysts and incidents, and applies it to AI telemetry.

Common mistakes

  • Testing only that a query parses.
  • Allowing console edits that bypass the repository.
  • Never retiring rules.
  • No checks that log sources still deliver the fields rules depend on.
You just read a free answer. Every topic opens its first 5 answers to anyone. Sign in and the count per topic goes to 10, and we keep track of how far you get in every topic.Google sign-in · free · no payment details
HOW DID IT GO?
0
READING SIGNED OUT

Signing in doubles your free answers, from 5 to 10 per topic, and the site starts remembering you: mastery per topic, bookmarks, and a next-focus recommendation. Free, no card.

Sign in free
UP NEXT ON YOUR JOURNEY
DISCUSSION · 0

No comments yet. Share a correction or a different way to answer it.