databricks-spark-structured-streaming

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Spark Structured Streaming

Spark Structured Streaming

Production-ready streaming pipelines with Spark Structured Streaming. This skill provides navigation to detailed patterns and best practices.
生产就绪的Spark Structured Streaming流处理管道。本技能提供详细模式与最佳实践的导航指引。

Quick Start

Quick Start

python
from pyspark.sql.functions import col, from_json
python
from pyspark.sql.functions import col, from_json

Basic Kafka to Delta streaming

Basic Kafka to Delta streaming

df = (spark .readStream .format("kafka") .option("kafka.bootstrap.servers", "broker:9092") .option("subscribe", "topic") .load() .select(from_json(col("value").cast("string"), schema).alias("data")) .select("data.*") )
df.writeStream
.format("delta")
.outputMode("append")
.option("checkpointLocation", "/Volumes/catalog/checkpoints/stream")
.trigger(processingTime="30 seconds")
.start("/delta/target_table")
undefined
df = (spark .readStream .format("kafka") .option("kafka.bootstrap.servers", "broker:9092") .option("subscribe", "topic") .load() .select(from_json(col("value").cast("string"), schema).alias("data")) .select("data.*") )
df.writeStream
.format("delta")
.outputMode("append")
.option("checkpointLocation", "/Volumes/catalog/checkpoints/stream")
.trigger(processingTime="30 seconds")
.start("/delta/target_table")
undefined

Core Patterns

Core Patterns

PatternDescriptionReference
Kafka StreamingKafka to Delta, Kafka to Kafka, Real-Time ModeSee references/kafka-streaming.md
Real-Time Mode (RTM)Sub-second E2E latency — cluster setup, slot math, supported ops (incl. stream-stream inner join on DBR 18+),
transformWithState
, observability, error classes, delivery semantics
See references/real-time-mode.md
Lakebase SinkWrite streaming records into Lakebase Postgres with transactional upserts. Native
format("postgresql")
sink (DBR 18.3+) and manual
foreach
sink as a fallback
See references/lakebase-sink-python.md
Stream JoinsStream-stream joins, stream-static joinsSee references/stream-stream-joins.md, references/stream-static-joins.md
Multi-Sink WritesWrite to multiple tables, parallel mergesSee references/multi-sink-writes.md
Merge OperationsMERGE performance, parallel merges, optimizationsSee references/merge-operations.md
模式描述参考
Kafka流处理Kafka到Delta、Kafka到Kafka、实时模式查看 references/kafka-streaming.md
实时模式(RTM)亚秒级端到端延迟 —— 集群设置、槽位计算、支持的操作(包括DBR 18+版本的流-流内连接)、
transformWithState
、可观测性、错误类别、交付语义
查看 references/real-time-mode.md
Lakebase输出端将流处理记录以事务性更新写入Lakebase Postgres。原生
format("postgresql")
输出端(DBR 18.3+)和手动
foreach
输出端作为备选方案
查看 references/lakebase-sink-python.md
流连接流-流连接、流-静态连接查看 references/stream-stream-joins.mdreferences/stream-static-joins.md
多输出端写入写入多张表、并行合并查看 references/multi-sink-writes.md
合并操作MERGE性能、并行合并、优化查看 references/merge-operations.md

Configuration

Configuration

TopicDescriptionReference
CheckpointsCheckpoint management and best practicesSee references/checkpoint-best-practices.md
Stateful OperationsWatermarks, state stores, RocksDB configurationSee references/stateful-operations.md
Trigger & CostTrigger selection, cost optimization, RTMSee references/trigger-and-cost-optimization.md
主题描述参考
检查点检查点管理与最佳实践查看 references/checkpoint-best-practices.md
有状态操作水印、状态存储、RocksDB配置查看 references/stateful-operations.md
触发器与成本触发器选择、成本优化、RTM查看 references/trigger-and-cost-optimization.md

Best Practices

Best Practices

TopicDescriptionReference
Production ChecklistComprehensive best practicesSee references/streaming-best-practices.md
主题描述参考
生产环境检查清单全面的最佳实践查看 references/streaming-best-practices.md

Production Checklist

Production Checklist

  • Checkpoint location is persistent (UC volumes, not DBFS)
  • Unique checkpoint per stream
  • Fixed-size cluster (no autoscaling for streaming)
  • Monitoring configured (input rate, lag, batch duration)
  • Exactly-once verified (txnVersion/txnAppId)
  • Watermark configured for stateful operations
  • Left joins for stream-static (not inner)
  • 检查点位置为持久化存储(UC卷,而非DBFS)
  • 每个流处理任务使用唯一的检查点
  • 固定大小集群(流处理不使用自动扩缩容)
  • 已配置监控(输入速率、延迟、批处理时长)
  • 已验证Exactly-once语义(txnVersion/txnAppId)
  • 为有状态操作配置水印
  • 流-静态连接使用左连接(而非内连接)