Trigger icon
OutputValues icon
If icon
SlackIncomingWebhook icon
Log icon

SurrealDB Data Integrity Violation Sentinel

Poll SurrealDB for integrity violations in real time, alert Slack with the violating rows, and log the result for data platform teams.

Categories
Data

A business invariant encoded only in application code, a balance that should never go negative, a record that should never exist without its parent, can still slip through if a bug or a manual data fix bypasses that code path. SurrealDB itself has no built-in constraint check that pages anyone the moment such a row appears; it just sits there until a report looks wrong. This blueprint turns a single SurrealQL query encoding that invariant into a standing, real-time compliance check.

This blueprint was created by Mohit Jeswani.

How it works

  1. watch_integrity_violations (io.kestra.plugin.surrealdb.Trigger) polls query every 5 minutes and only fires an execution when it returns at least one row; a clean poll produces no execution at all, so every execution of this flow represents a real, currently-existing violation.
  2. evaluate (io.kestra.plugin.core.output.OutputValues) classifies the violation count this poll found as WIDESPREAD_INTEGRITY_VIOLATION at or above max_isolated_violation_count, otherwise INTEGRITY_VIOLATION.
  3. route (io.kestra.plugin.core.flow.If) posts to Slack either way, since both severities represent a real violation, with the widespread case worded for urgency and carrying the same real row data either way.
  4. summary logs the violation count and severity, closing the governance cycle.
  5. errors alerts Slack if the flow itself fails, for example a broker connection drop.

What you get

  • A violation check built on the database's own query engine, not a periodic report someone has to remember to read.
  • The real violating rows in the Slack alert, not just a count, so whoever responds can act without a separate lookup.
  • A trigger that produces zero noise when the data is clean: no execution, no log entry, nothing, until an actual violation exists.

Who it's for

  • Data platform and backend teams running SurrealDB who encode a business invariant in a query and want it enforced as a standing check, not a one-off script run during an incident.
  • Teams evaluating the SurrealDB plugin who want a worked example of the real-time Trigger used for data-integrity enforcement, distinct from this repo's existing SurrealDB blueprints, which use the scheduled Query task for cleanup and audit flows rather than a continuously-polling violation trigger.

Why orchestrate this with Kestra

SurrealDB answers a query on request; it does not keep polling on its own, decide what counts as a widespread versus isolated violation, or notify a Slack channel the moment one appears. Kestra keeps max_isolated_violation_count as a flow input, turns a violating query result into a Slack page carrying the real rows, and keeps a full execution history of every violation ever caught.

Prerequisites

  • A SurrealDB instance, locally testable via the official surrealdb/surrealdb Docker image, with at least one table your query can check an invariant against.
  • A SurrealDB user with read access to that table.
  • A Slack incoming webhook URL.

Secrets

  • SURREALDB_USERNAME / SURREALDB_PASSWORD: used by watch_integrity_violations. In Kestra OSS, provide them as the base64-encoded environment variables SECRET_SURREALDB_USERNAME and SECRET_SURREALDB_PASSWORD.
  • SLACK_WEBHOOK_URL: used by both Slack tasks and the errors block. In Kestra OSS, provide it as the base64-encoded environment variable SECRET_SLACK_WEBHOOK_URL.

Inputs

Input Default Purpose
max_isolated_violation_count 3 Row count at or above which a poll is classified as widespread rather than isolated

Outputs

  • {{ trigger.rows }} / .size: the violating rows this poll found and how many, as the Trigger reports them (reusing the underlying Query task's own output shape).
  • {{ outputs.evaluate.values.violation_count }} / .severity: the same count, and INTEGRITY_VIOLATION or WIDESPREAD_INTEGRITY_VIOLATION.

Pitfalls

  • query is the entire governance policy; this blueprint does not validate that it actually encodes a real invariant, a loosely-written query can match far more (or fewer) rows than intended.
  • fetchType: FETCH keeps rows in memory for the Slack payload; a query that can legitimately match a very large number of rows should lower fetchType to STORE and alert with the storage URI instead of inlining every row into one Slack message.
  • This trigger has no inputs: to override per execution; query, namespace, and database are trigger-level configuration set directly on the trigger block.

Quick start

  1. Start a local SurrealDB instance (docker run -p 8000:8000 surrealdb/surrealdb:latest start --user root --pass root) and add the SURREALDB_USERNAME, SURREALDB_PASSWORD, and SLACK_WEBHOOK_URL secrets.
  2. Set query, namespace, and database on watch_integrity_violations to a real invariant check against a real table.
  3. Insert a record that violates the invariant and enable the trigger; confirm an alert fires with that row's real data.
  4. Insert enough violating records at once to confirm WIDESPREAD_INTEGRITY_VIOLATION fires instead of the isolated case.

How to extend

  • Chain a SELECT count() FROM ... query via io.kestra.plugin.surrealdb.Query in the widespread branch to size the full scope of the violation beyond this one poll's rows.
  • Add a remediation branch that updates the violating records to a quarantine flag via io.kestra.plugin.surrealdb.Query, gated behind an explicit confirm_quarantine input.
  • Route WIDESPREAD_INTEGRITY_VIOLATION to an on-call paging channel and the isolated case to a lower-urgency channel, since the two likely have different owners.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.