Real-Time Airline Data Engineering
Event-driven pipelines that move operational airline events from Event Hubs through stateful Structured Streaming into Cosmos DB — without losing data when clusters restart.
Aviation · Connected Operations data platform · Xebia Middle East
Problem
Airline operations depend on fresh, consistent operational data. Events arrive continuously, can be duplicated or late, and must reach low-latency serving stores without gaps — including when a streaming cluster restarts or is redeployed.
Architecture
- 01Azure Event Hubs receives operational events from source systems.
- 02Databricks Structured Streaming consumes the stream and applies stateful processing — deduplication, ordering, and per-key state with timers.
- 03State is held in the RocksDB state store and checkpointed so it survives restarts.
- 04Curated results are written to Azure Cosmos DB for low-latency serving and to Delta Lake for history.
- 05Cosmos DB Change Feed propagates changes onward for synchronization and archival.
Engineering decisions
- Keep deduplication state across restarts
- Deduplication lives in checkpointed streaming state rather than in memory, so a cluster restart resumes from the last committed offsets with its state intact instead of re-emitting or dropping events.
- Use arbitrary stateful processing where SQL operators fall short
- transformWithStateInPandas gives explicit control over per-key state, TTLs, and timers for business rules that built-in aggregations cannot express.
- Parallelize I/O-bound ingestion
- Moving Event Hubs ingestion from sequential calls to a ThreadPoolExecutor removes idle I/O wait and raises throughput without adding cluster capacity.
- Pick the right Cosmos DB integration per pipeline type
- The Cosmos DB Spark connector does not work inside Spark Declarative Pipelines, so those flows use an alternative integration pattern while classic jobs keep the connector.
Technologies
- Azure Event Hubs
- Databricks Structured Streaming
- transformWithStateInPandas
- RocksDB state store
- Azure Cosmos DB
- Cosmos DB Change Feed
- Delta Lake
- PySpark
Outcomes
- Streaming pipelines resume after cluster restarts without losing deduplication state.
- Event Hubs ingestion throughput improved by parallelizing I/O-bound work.
- Patterns documented and shared publicly as technical articles.
Lessons learned
- Treat restarts as a normal event in streaming design, not an edge case.
- Stateful logic needs explicit TTLs; state that never expires eventually becomes an incident.
- Validate connector support for each Databricks pipeline type before committing to an architecture.
Go deeper
- Data Quality8 min read
Preventing Data Loss in Real-time Streaming Pipelines When Databricks Clusters Restart (opens on Medium in a new tab)
How to preserve deduplication state and protect integrity across cluster restarts.
Read on Medium
- Streaming10 min read
Mastering Stateful Streaming: A Technical Deep Dive (opens on Medium in a new tab)
In-depth stateful streaming patterns with transformWithStateInPandas.
Read on Medium
- Azure4 min read
Speed Up Your Azure Event Hub Ingestion with Python ThreadPoolExecutor (opens on Medium in a new tab)
A practical guide to moving from sequential to parallel processing for Event Hub ingestion.
Read on Medium
- Databricks8 min read
Why Your Cosmos DB Connector Fails in Databricks Spark Declarative Pipelines (opens on Medium in a new tab)
Why cosmos.oltp fails in Spark Declarative Pipelines and architecture patterns that work.
Read on Medium
- Azure6 min read
Real-Time Data Sync with Azure Cosmos DB Change Feed (opens on Medium in a new tab)
Build scalable real-time synchronization pipelines with Cosmos DB Change Feed and Databricks.
Read on Medium