Engineering details and analysis for our new recovery feature.
by Jose Torres
In data engineering, as in life, mistakes are inevitable. They can come from a variety of different causes: sometimes a source system will generate a bit of bad data, or a new change to a transformation will introduce a subtle bug, or changes to upstream data will land before the aggregate processing has been properly updated to handle them. But the consequence is the same: our data pipeline has generated some bad results, and we need to find a strategy to fix them.
Today, this strategy generally ends up involving ad hoc corrections after the fact. Open table formats like Delta Lake support a powerful category of operations called time travel, which help with this; we can peek into the past on a table-by-table basis to understand (1) when the issue started, and (2) what data needs to be removed or corrected.
But corrections are often required far beyond the scope of a single table. A pipeline might manage data for dozens, hundreds, or even thousands of tables, all of which might have received a bad row from the first table or bad data derived from that row. Even when all tables are corrected, the bad data might have propagated into the pipeline’s operational state, improperly advancing a watermark or flowing into an intermediate aggregate buffer. And for issues that require backfill, the set of data to be backfilled is quite hard to compute, requiring complex reasoning about the original offsets in the source streaming system and how those offsets propagated through the pipeline.
We sat down to think the problem through from first principles, and we realized that there was a common thread across many of the trickiest recoveries we’d seen. What if you could rewind the entire data pipeline - table data and operational state alike, encompassing the entire dataflow graph - back to some point in the past? Then you could apply the easy fix, and resume processing as though nothing ever went wrong.
So we built a new feature, powered by Spark Declarative Pipelines (SDP), to do precisely that! The new rewind functionality enables scrolling back into the past, inspecting what the data used to look like, and replaying a streaming pipeline from that point onwards with any fixes or corrections required. As the graph executes, we periodically generate what we call “rewind points”:

These rewind points are consistent metadata snapshots, containing a set of info for each flow and dataset in the pipeline. Then, when something goes wrong, we simply have to pick one of those snapshots:

And execute the rewind to bring the pipeline’s state back in time.

Once the rewind is complete, the pipeline is ready for execution once again, with no need for backfills or ad hoc coordination. After any required fixes have been applied to the incoming data or transformation logic, the pipeline can resume, and will simply continue onwards as though nothing was ever wrong.
The harder question, of course, is how this all works under the hood? In the remainder of this post we’ll explore the underlying technologies and processes that power the rewind, the steps we had to take to get it working, and our future goals for how to make it better.
Delta lake has a multi-level storage system. The core of the table is the Delta log, a sequence of transaction entries according to the Delta Lake protocol. Each entry in the transaction log represents a change to the table, such as:
Within these transaction log entries, each file points to a particular blob storage path, and that path is where the underlying table data is actually located.
This additional layer of indirection does increase the system complexity, but in doing so it enables many advantages in practical workloads. Many new features, such as deletion vectors or liquid clustering, deliver large benefits in performance and maintainability by leveraging the transactional log structure. Another major advantage is the ability to leverage the transaction log as a historical view.
In a transactional storage system, the table history becomes more than an abstraction: it’s just another dataset living in blob storage which can be queried. Any user can look through a table in the Delta Lake format to understand what operations happened, when they happened, who performed them, and so on. They can time travel, seeing what the contents of the table used to be at a specific point in the past. They can even RESTORE the table to bring its contents back to that previous state.
However, while RESTORE rolls back the results of a write to the table, the processes which performed that write are unaffected. As far as they’re concerned, the data has already been processed. So recovering from a RESTORE will usually involve performing ad hoc backfills to correct the table state. Depending on the size of a data processing pipeline, this can range from annoying to outright infeasible.
In our declarative pipelines framework, this is particularly unfortunate, because this kind of imperative execution management is precisely what we aim to avoid. But the pipeline framework also provides us flows, directly representing the data ingestion processes along with the datasets they’re written into. If we could do something like a RESTORE to the flows as well, the problem would be solved; rather than having to find the source data that was cleared from the datasets and re-ingest it through a separate process, we would simply undo the entire ingestion process and then redo it just as though it was happening for the first time. This then poses two additional requirements.
To perform the pipeline-level rewind, we have to identify which version to rewind to for each dataset and each flow. For triggered execution processes, this is relatively straightforward, as we can simply take snapshots between updates. For continuous execution processes, though, flows and datasets with dependencies on each other may execute in a parallel and non-aligned manner.
We solved this problem with a two-step process. When computing a rewind point, we maintain a complex set of graph invariants, with the effect of ensuring that a naive reprocessing will produce a superset of the data which was rewound from the flow’s destination. In order to avoid data duplication, we add extra streaming logic on replay, instructing the flow to skip the range of data which was already consumed when replaying its source data. But that then leads into the second requirement: how do we implement such a rewind operation on the Structured Streaming process represented by a flow?
The Spark structured streaming protocol also has a log structure. This was originally motivated by failure recovery: storing the offsets, stateful operation data, et cetera in a metadata log with incrementing versions allows the Apache Spark system to ensure idempotency and achieve repeatable batches in scenarios where a microbatch query fails before committing its results. But the metadata log ended up being broadly similar in structure to the Delta Lake metadata log, and recent work has added a read_state_metadata lookup analogous to DESCRIBE HISTORY in Delta Lake.
We extended the Structured Streaming checkpoint layer to introduce two pieces of new functionality to help rewind workloads:
Auto Loader is an illustrative example of the problem described above. In the standard setup, it consumes from transient file notifications in a cloud provider’s system, processing files as they arrive into the source bucket. Rewinding the stream thus cannot produce the original source state; the file notifications are already consumed and cannot be restored.
To tackle this efficiently without unacceptable increases in storage costs, we needed to introduce a bit of incrementalism into the Auto Loader streaming source. We added a new component called the rewind log, containing metadata for archived checkpoint files to enable fast lookup of checkpoint files containing relevant replay information. This rewind log is also used to enable on-demand loading of Auto Loader’s checkpoint during non-replay execution to address disk usage concerns with increased retention. The combination of these two functionalities let us efficiently integrate Auto Loader rewind with the Structured Streaming pinning mechanism, efficiently performing rewinds without hurting the performance of normal execution.
Our beta launch is far from the end of the story, and we have a number of ongoing efforts to improve and expand on pipeline rewinding.
In addition to rewinding the pipeline’s execution state, we intend to also support rewinding the pipeline’s definition. This will allow one-step resolution for problems such as code changes that produced invalid data. However, the abstract concept of the definition of the pipeline includes a number of components:
Our efforts continue to investigate each of these components and how to best represent them within a rewind process.
The results of a pipeline are themselves consumed by other automated processes, which today cannot easily distinguish between a rewind and other kinds of updates. We hope to establish a protocol that will allow platform-wide consumers to understand that a rewind has been performed and react accordingly.
Delta Lake time travel and RESTORE work on a single table, while SDP rewind rolls back every table and flow in a pipeline together. RESTORE reverts a table's contents, but the processes that wrote the data still treat it as processed, so recovery usually requires ad hoc backfills. Rewind resets those processes too, so the pipeline reprocesses the affected data as though for the first time.
Not necessarily. In the next update after a rewind finishes, the pipeline will replay the rewound data. So any issues that come from problems with the transformation logic can be handled by simply correcting the transformation logic before the replay. If some data requires an out of band correction, the transformation can be adjusted to filter out the bad data and ingest the rest while the bad data awaits its backfill.
Yes, SDP rewind works with both triggered and continuous pipelines. In triggered pipelines, rewind points are taken between updates, but in continuous pipelines, flows that depend on each other can run in parallel and out of step. SDP handles this by choosing rewind points that guarantee replay covers all of the rolled-back data. On replay, a new type of streaming batch called a control batch skips the data each flow already consumed, so nothing gets duplicated.
Yes, SDP rewind works with Auto Loader. The file notifications which it uses to detect new files, of course, are gone once consumed and can't be directly restored. To handle this, Auto Loader keeps a rewind log with metadata about what was ingested at each of the rewind points, so it can quickly find what it needs to replay.
Choose a rewind point from before the problem started. You can explore the historical state of each dataset in the pipeline using the data preview within the rewind interface, or with the Delta LAke time travel functionality.
If you want to learn more, try out the beta! See our feature introduction or review the beta documentation.
Subscribe to our blog and get the latest posts delivered to your inbox.