Structured Streaming already manages offset tracking and commit logs through its checkpoint directory. You do not need to configure a separate write-ahead log when reading from Azure Event Hubs through the Kafka connector.
However, foreachBatch provides at-least-once write guarantees by default, meaning a micro-batch may be executed again after a failure.
For example, if a batch successfully writes to Delta but the application fails before recording the batch completion, Spark may replay that batch after restarting.
For Delta targets, you can prevent duplicate writes using txnAppId and txnVersion:
def write_batch(batch_df, batch_id):
(
batch_df.write
.format("delta")
.mode("append")
.option("txnAppId", "eventhub-stream-01")
.option("txnVersion", batch_id)
.saveAsTable("bronze.events")
)
query = (
source_df.writeStream
.foreachBatch(write_batch)
.option("checkpointLocation", checkpoint_path)
.start()
)Keep the application ID consistent across restarts using the same checkpoint. If you create a new checkpoint, use a new application ID because batch IDs restart from zero.
My recommendation is to combine durable checkpoint storage, sufficient Event Hubs retention and idempotent destination writes.
Checkpointing handles processing recovery, while idempotent writes prevent duplicate records during batch retries.
Official references:
https://docs.databricks.com/aws/en/structured-streaming/checkpoints
https://docs.databricks.com/aws/en/structured-streaming/foreach
https://docs.databricks.com/aws/en/structured-streaming/delta-lake