Query icon
Script icon
Process icon
If icon
Fail icon
Log icon
Schedule icon

RisingWave Streaming Lag Quarantine and Source Rebalance Gate

Audits RisingWave streaming lag, pausing sources, auto-scaling worker parallelism, and failing downstream runs to prevent stale reads.

Categories
DataInfrastructure

Modern real-time analytics platforms rely on RisingWave to maintain continuously updated materialized views directly over high-velocity Kafka, Pulsar, and Kinesis event streams. However, upstream event volume surges, complex multi-way stream joins, or state store compaction latency can cause streaming workers to suffer backpressure. When this happens, streaming barrier latency spikes, materialized view freshness degrades, and downstream analytical dashboards show stale data. This blueprint provides a complete closed-loop operational workflow that actively resolves streaming lag: it interrogates RisingWave's native system catalog (rw_catalog.rw_streaming_jobs), evaluates lag severity in Python, temporarily pauses the upstream ingestion source to stop backpressure floods, scales materialized view worker parallelism in flight, resumes ingestion, verifies worker recovery, and halts downstream pipelines if lag cannot be resolved within SLA tolerance.

How it works

  1. A schedule trigger initiates the streaming audit every 15 minutes.
  2. A native PostgreSQL JDBC query task connects to RisingWave's frontend port and interrogates rw_catalog.rw_streaming_jobs.
  3. A Python script evaluates current worker allocation against target throughput thresholds with strict loud failure on invalid catalog payloads.
  4. When backpressure or worker under-provisioning is detected, an If conditional task executes active multi-step remediation.
  5. A query task pauses the upstream streaming ingestion source (ALTER SOURCE ... PAUSE) to halt incoming records during rebalancing.
  6. A secondary query task issues an ALTER MATERIALIZED VIEW ... SET PARALLELISM DDL command to expand worker compute capacity.
  7. A third query task resumes the upstream source (ALTER SOURCE ... RESUME) to re-enable continuous stream processing.
  8. A post-remediation query verifies that RisingWave applied the target parallelism and that streaming jobs are in RUNNING state.
  9. If streaming jobs remain degraded, a downstream gate fails the workflow to quarantine downstream batch consumers from reading stale data.
  10. A final log task captures the operational outcome in Kestra's execution history.

Architecture diagram

graph TD
    Trigger[Schedule Trigger: 15m] --> ProbeTelemetry[Postgres Query: Probe Streaming Jobs]
    ProbeTelemetry --> EvalLag[Python Script: Evaluate Lag Severity]
    EvalLag --> CheckLag{Remediation Required?}
    CheckLag -- Yes --> PauseSource[Postgres Query: ALTER SOURCE PAUSE]
    PauseSource --> ScaleMV[Postgres Query: ALTER MATERIALIZED VIEW SET PARALLELISM]
    ScaleMV --> ResumeSource[Postgres Query: ALTER SOURCE RESUME]
    ResumeSource --> VerifyDrain[Postgres Query: Verify Drained Latency]
    VerifyDrain --> CheckState{State RUNNING?}
    CheckState -- No --> FailDownstream[Fail: Abort Downstream Runs]
    CheckState -- Yes --> FinalLog[Log: Record Verified Capacity]
    CheckLag -- No --> NominalLog[Log: Throughput Optimal]
    NominalLog --> FinalLog

What you get

  • Active streaming backpressure resolution that halts ingestion surges, scales worker capacity, and re-engages processing.
  • Native PostgreSQL wire protocol integration using Kestra's official JDBC PostgreSQL plugin without third-party agents.
  • Downstream data protection through automated failure gates preventing analytics jobs from reading stale aggregations.
  • Full DDL lifecycle management invoking RisingWave's native ALTER SOURCE and ALTER MATERIALIZED VIEW commands.
  • Post-remediation verification confirming that compute nodes applied the updated thread count.

Who it's for

  • Stream Processing Engineers maintaining real-time event-driven ETL pipelines.
  • Database Administrators operating RisingWave clusters over Kafka or Kinesis topics.
  • Site Reliability Engineers ensuring real-time business dashboards and fraud detection systems remain fresh.
  • Analytics Engineers relying on continuous materialized view freshness for sub-second query SLAs.

Why orchestrate this with Kestra

  • Native Wire-Protocol Support: Connects directly to RisingWave via standard PostgreSQL JDBC drivers without requiring custom CLI binaries.
  • Active Operational Control: Manages the complete remediation loop by pausing sources, scaling views, and resuming stream ingestion.
  • Downstream Protection Gates: Prevents downstream data corruption by halting dependent workflows when streaming lag breaches SLAs.
  • Centralized Secrets Governance: Protects sensitive database passwords using encrypted namespace secrets.
  • Declarative YAML Operations: Version-controls streaming data reliability runbooks alongside application code in Git.

Use cases

  • Ingestion Surge Relief: Pauses upstream Kafka sources temporarily during traffic spikes while scaling worker capacity.
  • Stale Read Protection: Fails downstream batch transformations if real-time materialized views have uncommitted barrier lags.
  • Dynamic Compute Elasticity: Adjusts streaming worker allocations automatically to match changing incoming event velocity.

Inputs

Name Type Default Description
risingwave_host STRING localhost Hostname or IP address of the RisingWave compute or frontend node.
risingwave_port INT 4566 PostgreSQL-wire compatible port for RisingWave (default 4566).
database_name STRING dev RisingWave database containing target streaming sources and views.
risingwave_username STRING root Database user with DDL privileges on target streaming objects.
target_source_name STRING src_kafka_orders Name of the upstream streaming source connector feeding the pipeline.
target_materialized_view STRING mv_realtime_order_aggregates Name of the streaming materialized view evaluated for barrier lag.
max_allowable_lag_ms INT 5000 Streaming barrier latency threshold in milliseconds triggering remediation.
target_scale_parallelism INT 8 Target worker thread count applied to relieve streaming backpressure.

Expected outputs

  • {{ outputs.probe_streaming_jobs_and_sources.row.total_streaming_jobs }}: Total number of registered streaming jobs in the database.
  • {{ outputs.evaluate_streaming_lag_and_backpressure.vars.requires_remediation }}: Boolean flag indicating if source pausing and scaling were applied.
  • {{ outputs.evaluate_streaming_lag_and_backpressure.vars.current_parallelism }}: Original worker parallelism observed prior to remediation.
  • {{ outputs.verify_drained_barrier_latency.row.verified_parallelism }}: Post-remediation worker parallelism verified from system catalogs.
  • {{ outputs.verify_drained_barrier_latency.row.verified_state }}: Operational state of the streaming job post-remediation.

Prerequisites

  • RisingWave cluster (v1.0 or newer) running and accessible over PostgreSQL port 4566.
  • Upstream streaming source and target materialized view registered in the target database.
  • Database user with SELECT and ALTER permissions on target sources, views, and rw_catalog.
  • Network connectivity from Kestra workers to the RisingWave frontend host.
  • Secret configured in Kestra under RISINGWAVE_PASSWORD.

Secrets

  • RISINGWAVE_PASSWORD: Password for the RisingWave database user.

Quick start

  1. Confirm that RisingWave is running and listening on port 4566.
  2. Add RISINGWAVE_PASSWORD into your Kestra namespace secrets.
  3. Specify your RisingWave endpoint in risingwave_host, source in target_source_name, and view in target_materialized_view.
  4. Run a manual execution via the Kestra UI to verify connectivity and view active streaming job metrics.
  5. Enable the periodic_streaming_audit schedule trigger to establish automated continuous surveillance.

Common pitfalls and troubleshooting

  • Default Port: RisingWave uses port 4566 for PostgreSQL wire compatibility, not the default PostgreSQL 5432.
  • DDL Privileges: Ensure the configured database user has permissions to execute ALTER SOURCE and ALTER MATERIALIZED VIEW.
  • Catalog Name Matching: The target_materialized_view parameter must match the exact view identifier in rw_catalog.rw_streaming_jobs.
  • Firewall Rules: Ensure security groups or network firewalls permit inbound TCP traffic on port 4566 from Kestra worker IPs.

How to extend

  • Downstream dbt Model Execution: Chain a downstream dbt transformation task to execute only when RisingWave lag is verified within tolerance.
  • Kafka Partition Scaling: Trigger automated Kafka topic partition expansion in parallel when RisingWave worker parallelism is scaled.
  • PagerDuty Incident Escalation: Route quarantined execution failures directly to on-call data platform engineers via PagerDuty webhook.

Links

Orchestrate with Kestra
Orchestrate Postgres with Kestra
Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.