New to Kestra?
Use blueprints to kickstart your first workflows.
Audit MongoDB change streams with Debezium, track oplog backlog accumulation, commit KV resume checkpoints, and alert Slack before replication drops.
Enterprise data architectures streaming real-time mutations from MongoDB into search indexes, analytical lakehouses, or event brokers depend heavily on Change Streams and MongoDB's internal operation log (oplog). Under heavy transactional bursts or consumer stalls, replication lag accumulates rapidly. If the consumer falls behind the oplog retention window, unread events are permanently truncated, triggering fatal ChangeStreamHistoryLost exceptions that necessitate expensive, slow cluster-wide full table re-snapshots.
This blueprint provides an autonomous Day 2 operations sentinel for MongoDB Change Data Capture. Scheduled on a 2-hour cadence, it utilizes embedded Debezium to probe real-time Change Streams, drains accumulated oplog mutations into durable Kestra internal storage, tracks resume tokens atomically within Kestra KV store, evaluates lag thresholds, and posts urgent Slack alerts before oplog rollover causes data loss.
periodic_schedule trigger initiates the workflow every 2 hours with explicit default parameters, configured in a disabled state for initial verification.probe_cdc_backlog (io.kestra.plugin.debezium.mongodb.Capture) opens a Change Stream cursor against the configured MongoDB replica set with snapshotMode: NO_DATA. It samples up to max_records pending mutations within a bounded maxWait polling window, stores captured records in Kestra internal storage, and atomically commits the Debezium resume token into Kestra KV store under state_name.classify_cdc_posture (io.kestra.plugin.core.debug.Return) calculates the batch size and verifies task completion to produce a discrete operational verdict: CRITICAL_OPLOG_LAG, CDC_PROBE_FAILED, ACTIVE_STREAMING, or QUIET_HEALTHY.route_posture_action (io.kestra.plugin.core.flow.Switch) directs subsequent tasks: critical lag thresholds and connection dropouts trigger rich Slack webhook notifications with storage URIs and checkpoint keys, while nominal runs output diagnostic metrics.audit_sentinel_run (io.kestra.plugin.core.log.Log) writes an immutable summary entry capturing the execution ID, evaluated verdict, and checkpoint key for compliance auditing.errors handler catches uncaught network timeouts or MongoDB authentication errors and alerts Slack immediately.Operating standard Debezium connectors requires running Apache Kafka, Kafka Connect workers, schema registries, and external storage daemons, creating massive operational overhead and unmonitored failure points. Kestra embeds the Debezium MongoDB connector directly as a native task. It pairs change stream ingestion with declarative scheduling, native KV store state management, conditional flow-control routing, secret masking, and instant multi-channel alerting without external runtime infrastructure.
--replSet rs0).read privileges on the target databases and the local database (for oplog access).SLACK_WEBHOOK_URL: The destination Slack webhook URL for operational incident dispatching.MONGO_USER: (Optional) MongoDB authentication username if credentials are not embedded directly in the connection string.MONGO_PASSWORD: (Optional) MongoDB authentication password if credentials are not embedded directly in the connection string.SLACK_WEBHOOK_URL in your Kestra namespace secrets.docker run -d --name mongodb-sentinel -p 27017:27017 mongo:6.0 --replSet rs0
docker exec -it mongodb-sentinel mongosh --eval "rs.initiate()"
docker network connect YOUR_KESTRA_NETWORK mongodb-sentinel
QUIET_HEALTHY is logged.periodic_schedule trigger to activate autonomous background monitoring.io.kestra.plugin.serdes.parquet.IonToParquet and io.kestra.plugin.aws.s3.Upload) to archive captured change event streams to S3 or GCS data lakes.CRITICAL_OPLOG_LAG breaches occur.io.kestra.plugin.pagerduty for critical on-call incident escalation when replication lag approaches oplog window limits.