- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Saturday
The best approach here is to make your pipeline idempotent rather than relying entirely on the job repair mechanism.
When a Databricks task fails after successfully writing data to a Delta table, repairing the task does not roll back the previously committed transaction.
Use MERGE instead of append
MERGE INTO target_orders AS t USING source_orders AS s ON t.order_id = s.order_id WHEN MATCHED AND s.updated_at > t.updated_at THEN UPDATE SET * WHEN NOT MATCHED THEN INSERT *;
For example, if a task inserts 1,000 orders and fails during downstream processing, rerunning it will not insert those same orders again, assuming unique, non-null business keys in both tables.
2. Separate independent operations into tasks
Task 1: Extract data.
Task 2: Write to Delta.
Task 3: Downstream processing.
This allows you to repair the failed task without unnecessarily repeating successful operations.
3. Maintain a batch audit table
Track batch IDs, processing status and record counts for troubleshooting. However, an audit table alone does not guarantee exactly-once processing.
My recommendation is to combine idempotent writes with task-level recovery.
Are you using batch processing or Structured Streaming with foreachBatch? The implementation would differ slightly.
Official references: