New to Kestra?
Use blueprints to kickstart your first workflows.
Audit Neo4j graphs for hierarchy DAG cycle breaches, generate audit certificates, sever culprit closing edges, and alert engineering on circular references.
Hierarchical graphs modeled in Neo4j, such as role-based access control (RBAC) inheritance structures, organizational reporting lines, task dependency networks, and manufacturing bills of materials (BOM), strictly depend on the Directed Acyclic Graph (DAG) mathematical invariant. Upstream batch data syncs, asynchronous event streams, or manual admin edits frequently introduce accidental circular dependencies (e.g., node A -> node B -> node C -> node A). When downstream services or analytical pipelines execute recursive Cypher traversals (such as MATCH (r)-[:INHERITS*]->(p)), these circular references trigger unbounded iterations, transaction timeouts, thread pool starvation, and catastrophic Java Virtual Machine Out-Of-Memory (OOM) cluster crashes.
This blueprint provides an automated, production-grade integrity gate for Neo4j hierarchies. It executes variable-length Cypher cycle detection queries using path isomorphism constraints, produces an immutable audit certificate in Kestra internal storage, alerts platform teams via Slack with exact cyclic traces, and conditionally severs the culprit closing back-edge while preserving legitimate hierarchy nodes and parent branches.
io.kestra.plugin.core.trigger.Schedule, or on demand after batch ETL syncs via manual invocation or webhook.detect_cycles (io.kestra.plugin.neo4j.Query) evaluates paths of depth 1..max_search_depth where start node equals end node. An interior node constraint (WHERE all(m IN nodes(path)[1..-1] WHERE elementId(m) > elementId(n))) guarantees that each distinct directed cycle is returned exactly once anchored at its minimal node ID, preventing duplicate counting.evaluate_integrity (io.kestra.plugin.core.output.OutputValues) computes the total count of cycles detected, identifies the shortest cycle length, extracts closing relationship element IDs, and sets the routing status to either CYCLE_BREACH or DAG_VALID.route_integrity_verdict (io.kestra.plugin.core.flow.Switch) inspects the integrity verdict:generate_audit_certificate (io.kestra.plugin.core.storage.Write) persists an immutable JSON audit certificate into Kestra internal storage recording the timestamp, audited labels, cycle count, and complete path traces.check_remediation_gate (io.kestra.plugin.core.flow.If) validates whether auto_sever_cycle is set to "true" and dry_run is set to "false". If enabled, task sever_culprit_closing_edges (io.kestra.plugin.neo4j.Query) safely deletes only the closing back-edges identified in the audit certificate, leaving all entities intact. Next, verify_dag_restored re-audits the graph to confirm DAG restoration.alert_cycle_breach_slack (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) dispatches a high-priority incident notification to Slack with cycle metrics and storage URI.log_dag_healthy (io.kestra.plugin.core.log.Log) logs confirmation that zero cycles were detected across the hierarchy.errors handler captures driver connection timeouts or authentication failures and posts an urgent Slack notification to on-call data engineers.dry_run: "true", auto_sever_cycle: "false"), guaranteeing no destructive relationship mutations occur without explicit administrative authorization.Detecting and remediating graph cycles through one-off shell scripts or isolated cron jobs creates visibility blind spots: scripts fail silently on network blips, lack audit trails of severed relationships, and expose database credentials.
Orchestrating this process with Kestra delivers:
{{ secret('NAME') }}).bolt://localhost:7687).NEO4J_USERNAME: Neo4j database user with query and relationship delete privileges (e.g., neo4j).NEO4J_PASSWORD: Password for the Neo4j database user.SLACK_WEBHOOK_URL: Slack Incoming Webhook URL for posting integrity incident alerts.docker run -d --name neo4j-test \
-p 7474:7474 -p 7687:7687 \
-e NEO4J_AUTH=neo4j/testpassword123 \
neo4j:5-community
CREATE (a:OrgUnit {id: 'eng', name: 'Engineering'}),
(b:OrgUnit {id: 'dev', name: 'Development'}),
(c:OrgUnit {id: 'qa', name: 'QA'})
CREATE (a)-[:INHERITS]->(b),
(b)-[:INHERITS]->(c),
(c)-[:INHERITS]->(a);
NEO4J_USERNAME: neo4jNEO4J_PASSWORD: testpassword123SLACK_WEBHOOK_URL: https://hooks.slack.com/services/...dry_run: "true" mode to verify cycle detection without mutating edges.dry_run: "false" and auto_sever_cycle: "true" to confirm that the closing edge is severed and the hierarchy is restored to a valid DAG.[:INHERITS] and recreate it as a [:QUARANTINED_CYCLE_EDGE] with an incident_id property for manual human triage.io.kestra.plugin.core.trigger.Webhook trigger to automatically invoke this integrity gate immediately after upstream dbt or Kafka batch sync jobs finish.io.kestra.plugin.jira.issues.Create to automatically open a bug ticket assigned to the data steward owning the affected entity.io.kestra.plugin.core.flow.Loop loop across all distinct business units or tenant graph partitions.