databricks-spark-structured-streaming

Build production Spark Structured Streaming pipelines with Kafka, Delta Lake, and stateful operations.

Updated Mar 24, 2026
One-click install
npx skills add https://github.com/AarushiShah/coding-agents-databricks-apps --skill databricks-spark-structured-streaming-aarushishah
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: databricks-spark-structured-streaming
Source: https://github.com/AarushiShah/coding-agents-databricks-apps/tree/main/.claude/skills/databricks-spark-structured-streaming
Command: npx skills add https://github.com/AarushiShah/coding-agents-databricks-apps --skill databricks-spark-structured-streaming-aarushishah

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building reliable real-time data pipelines requires deep knowledge of checkpointing, watermarks, state stores, and merge semantics. This Skill provides production-tested patterns for Spark Structured Streaming on Databricks, covering Kafka ingestion, stream joins, multi-sink writes, and Delta MERGE operations so you avoid common pitfalls like data loss, state explosion, and duplicate records. ## Core Features & Use Cases - Kafka Streaming Patterns: Ingest Kafka topics into Delta bronze tables, build Kafka-to-Kafka pipelines, enable Real-Time Mode for sub-second latency, and route invalid records to dead letter queues. - Stateful Operations & Checkpoints: Configure watermarks, RocksDB state stores, and persistent checkpoint locations in Unity Catalog volumes with recovery procedures for lost or corrupted checkpoints. - Stream Joins & Multi-Sink Writes: Correlate events across streams with time-bounded joins, enrich streams with Delta dimension tables, and fan out one stream to bronze/silver/gold tables using ForEachBatch. - Merge Optimization: Implement upserts with Liquid Clustering, Deletion Vectors, and parallel merges to multiple tables. - Use Case: You need to match payment events to order events arriving on separate Kafka topics within a 10-minute window, then write matched results to a Delta table with exactly-once guarantees. ## Quick Start Ask the agent to create a Spark Structured Streaming pipeline that reads from a Kafka topic and writes to a Delta table with checkpointing and a 30-second trigger.

Frequently Asked Questions about databricks-spark-structured-streaming

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I stream data from Kafka to Delta Lake with Spark?

Use spark.readStream with the kafka format to read topics, parse JSON values with from_json, then writeStream with the delta format in append mode. Set a persistent checkpointLocation in a Unity Catalog volume and configure a processingTime trigger such as 30 seconds.

How do I join two streaming DataFrames in Spark Structured Streaming?

Apply withWatermark on both streams, then join with an explicit time-bounded condition such as payments between order_time minus 5 minutes and plus 10 minutes. Watermarks let Spark expire state automatically and prevent unbounded state growth.

Where should I store Spark streaming checkpoints on Databricks?

Store checkpoints in Unity Catalog volumes backed by S3 or ADLS, not DBFS, which is ephemeral. Use a unique checkpoint per stream tied to the target table name, and back up checkpoints before migrations or major code changes.

Why is my Spark streaming state store growing too large?

State grows when watermark durations are too long or join keys have high cardinality. Reduce the watermark duration, lower key cardinality, and enable the RocksDB state store provider when state exceeds memory capacity.

How do I write one Spark stream to multiple Delta tables?

Use foreachBatch with a function that writes the batch DataFrame to each target table, passing txnVersion as the batch_id and a unique txnAppId per table for idempotent writes. Cache the batch DataFrame to avoid recomputation and use ThreadPoolExecutor for parallel writes.

When should I use Real-Time Mode instead of microbatch triggers?

Use Real-Time Mode with trigger(realTime=True) only when latency below 800 milliseconds is required, since microbatch processing is more cost-effective. RTM requires Photon enabled, RocksDB state store, and a fixed-size cluster without autoscaling.