Streaming Performance & Cost Optimization
Making stateful streaming observable, fixing RocksDB-related driver memory growth, and cutting Databricks compute cost by around 45% through workload analysis and right-sizing.
Databricks platform engineering · Xebia Middle East
Problem
Long-running stateful streaming jobs gradually slowed down and consumed more memory as state grew, and compute spend rose with them. The team needed visibility into state behaviour and a disciplined way to tune performance and cost.
Architecture
- 01A custom StreamingQueryListener captures per-batch progress and state-operator metrics.
- 02Metrics are written to Delta tables, giving a queryable history of batch duration, state rows, and memory usage.
- 03Dashboards and alerts are built on those tables for proactive monitoring.
- 04Custom utilities analyze workload patterns to drive cluster right-sizing and configuration standards.
Engineering decisions
- Measure state before tuning it
- RocksDB state-store metrics — rows, memory, commit latency — are logged every batch so tuning decisions are based on trends, not guesses.
- Fix the root cause of driver memory growth
- Pinned RocksDB memory and unbounded state were diagnosed and addressed at the source rather than masked by larger drivers.
- Apply performance features deliberately
- Photon, partitioning, Delta optimization, and caching are applied per workload and captured as reusable standards.
- Treat cost as an engineering metric
- Workload analysis and cluster right-sizing became part of the operating standard, not a one-off clean-up.
Technologies
- Databricks
- Structured Streaming
- RocksDB
- StreamingQueryListener
- Delta Lake
- Photon
- Cluster policies
Outcomes
- Approximately 45% lower Databricks compute cost.
- State-store health visible in Delta tables for monitoring and alerting.
- Performance practices embedded into reusable platform standards.
Lessons learned
- Most streaming performance problems are state problems — watch state size first.
- Bigger clusters hide leaks; they do not fix them.
- Cost optimization sticks only when it becomes part of the platform's standards.
Go deeper
- Streaming7 min read
Why Your Databricks Streaming Job is Leaking Driver Memory (And How to Fix It) (opens on Medium in a new tab)
Diagnosing RocksDB memory bloat and fixing stateful streaming driver memory leaks.
Read on Medium
- Streaming6 min read
Databricks: Monitoring RocksDB State Store in Structured Streaming (opens on Medium in a new tab)
How to build streaming observability with custom listeners and Delta logging.
Read on Medium
- Architecture9 min read
From Chaos to Control: Our Journey to Production-Ready Stateful Streaming (opens on Medium in a new tab)
Lessons from failed approaches to production-grade stateful streaming design.
Read on Medium