Skip to content

Add Real-Time Mode (RTM) sub-second latency streaming demo#78

Open
jiteshsoni wants to merge 6 commits intodatabricks-solutions:mainfrom
jiteshsoni:rtm-pr-review-fixes
Open

Add Real-Time Mode (RTM) sub-second latency streaming demo#78
jiteshsoni wants to merge 6 commits intodatabricks-solutions:mainfrom
jiteshsoni:rtm-pr-review-fixes

Conversation

@jiteshsoni
Copy link
Copy Markdown

@jiteshsoni jiteshsoni commented Mar 31, 2026

Summary

This PR adds a Real-Time Mode demo that reads Ethereum-style block events from Kafka, applies a set of stateless guardrail checks, and routes each record to either an allowed or quarantine topic.

The intent is to show the full Kafka -> Databricks RTM -> Kafka loop in a way that is easy to run, inspect, and explain.

Included in the PR

  • rtm_stateless_guardrail.py: main notebook
  • cluster_config.template.json: RTM-capable cluster template
  • test_rtm_guardrail.py: local validation-pattern tests
  • e2e_local_test.py: local end-to-end validation logic via Databricks Connect
  • produce_test_data.py: sample Kafka producer
  • README.md: setup and testing notes

Setup Notes

A few setup details turned out to matter in practice and are now called out in the code and docs:

  • use a dedicated single-user cluster
  • disable autoscaling
  • keep Photon off
  • use outputMode("update")
  • create the Kafka topics explicitly if your provider does not auto-create them
  • use startingOffsets = "earliest" for demos and integration tests so seeded backlog is replayed

The notebook also now includes an explicit verification section that reads the target Kafka topics back and shows what was actually written to -allowed and -quarantine, instead of stopping at query status alone.

How I tested it

Local checks

  • ran python test_rtm_guardrail.py
  • verified the pattern checks for email, SSN, credit card, AWS key, JWT, and Ethereum private key detection

Workspace / integration validation

Validated on e2-dogfood using:

  • cluster: rtm-guardrail-cluster (0313-063110-u4ldfaiy)
  • Kafka: Redpanda Serverless with SASL/SCRAM over SSL
  • submit run: 875702710968733
  • notebook task run: 447049974860353

For the final validation run I created a fresh set of Kafka topics, seeded deterministic records, ran the notebook as a Databricks submit run, and then verified the output topics directly.

Confirmed routing:

  • 4000001 -> ethereum-validated-jobrun-20260401000541-allowed with decision=ALLOW
  • 4000002 -> ethereum-validated-jobrun-20260401000541-quarantine with validation_reasons=["HIGH_GAS_USAGE"]
  • 4000003 -> ethereum-validated-jobrun-20260401000541-quarantine with validation_reasons=["PII_EMAIL"]

Output verification screenshot:

RTM output topic verification

That verified both halves of the demo:

  1. the RTM query runs correctly on the configured cluster
  2. the records are actually written to the expected target topics with the expected routing decisions

Related Post

Unlocking Sub-Second Latency with Spark Structured Streaming Real-Time Mode

This demo showcases Databricks Real-Time Mode for achieving sub-second
latency in streaming pipelines. It implements a stateless guardrail
pipeline that validates Ethereum blockchain events in real-time.

Features:
- RTM-enabled streaming pipeline (Kafka to Kafka)
- Sensitive data detection (PII, credentials)
- Validation rules for operational guardrails
- Dynamic topic routing (ALLOW/QUARANTINE)
- Parse error handling for malformed JSON
- End-to-end and unit tests

Requirements:
- Databricks Runtime 16.4 LTS or later
- Dedicated clusters (serverless not supported)
- outputMode("update") required for RTM

Files:
- rtm_stateless_guardrail.py - Main notebook
- cluster_config.template.json - Cluster config template
- test_rtm_guardrail.py - Unit tests
- e2e_local_test.py - End-to-end tests
- produce_test_data.py - Test data producer
- README.md - Documentation

Blog: https://canadiandataguy.com/p/unlocking-sub-second-latency-with
Reflect the Databricks + Redpanda integration path that worked in practice by
requiring single-user clusters for UC volume checkpoints, documenting explicit
topic setup, and replaying backlog from earliest offsets during demos.
Replace the old canned validation notes with the actual staging workspace and
Redpanda checks used to verify the demo, including the live routing cases that
were confirmed end to end.
Extend the RTM notebook with an explicit output-topic verification section so the
demo shows what was actually written to the allowed and quarantine topics,
instead of only showing query status.
Point readers to the new output-topic verification and stream management
sections so the README matches the notebook flow during demos and testing.
Store the Kafka output verification screenshot in the PR branch so it can be
embedded directly in the pull request description.
@matthewmoorcroft
Copy link
Copy Markdown
Member

@jiteshsoni I can see jwt tokens, also missing readme and your name in codeowners file, can you review the code to make sure that there are no security issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants