The Problem of Repeated Data Processing
Even seemingly simple data pipelines rarely run just once. Real-world scenarios frequently necessitate reprocessing the same data. This can occur due to retries after a failed run, backfilling historical data, or even accidental duplicate submissions by operators. When identical inputs lead to duplicate outputs, critical metrics become unreliable, undermining the integrity of the entire data system.
This article details a design decision made for a personal portfolio project, manufacturing-data-platform-mini, to safely skip reprocessing identical inputs using a technique called source_hash. The data used is entirely synthetic and represents a verifiable mini-slice of a production platform, not a production deployment itself.
Common Scenarios Requiring Reprocessing
Consider a situation where manufacturing or robot event files for a specific business_date need to be processed again. Common reasons include:
- Retry: A previous run failed midway, and the entire process must be restarted.
- Backfill: Historical data needs to be populated or updated for past dates.
- Operator Mistake: An operator inadvertently re-submits the same input file.
A naive approach of simply appending data each time a file is processed would lead to duplicated gold metrics for the same date, rendering them untrustworthy.
Decision Pressure and Simple Pipelines
Many simple CSV pipelines might conclude their processing without a robust mechanism to handle duplicate inputs. For instance, a basic pipeline might read a CSV file, perform some transformations, and then write the results. Without a check, re-running the same CSV would append identical transformed records.
The core challenge is to identify when a specific input has already been processed successfully and, if so, to skip the current processing step without affecting the final output or the integrity of the stored data. This requires a method to uniquely identify an input and a way to track previously processed inputs.
Introducing Source Hash for Deduplication
The solution implemented in the manufacturing-data-platform-mini project involves generating a source_hash for each input file. This hash serves as a unique identifier for the content of the input file at the time of processing.
The process works as follows:
- Hash Generation: Before any processing begins, a cryptographic hash (e.g., SHA-256) is computed over the entire content of the input file. This hash is deterministic; the same file content will always produce the same hash.
- State Storage: A record of successfully processed input hashes is maintained. This could be in a database, a dedicated metadata store, or even a version-controlled file for simpler projects. Each record typically includes the computed hash and potentially metadata like the processing timestamp or the specific
business_dateassociated with the input. - Pre-processing Check: When a new input file is submitted for processing, its
source_hashis generated. This newly generated hash is then checked against the stored records of previously processed hashes. - Conditional Processing:
- If the generated hash is found in the stored records, it signifies that this exact input has already been processed successfully. The pipeline then safely skips the current processing step for this input, avoiding duplication.
- If the generated hash is not found, it indicates a new or modified input. The pipeline proceeds with the normal processing. Upon successful completion, the new
source_hashis added to the stored records, marking it as processed.
This mechanism ensures that regardless of how many times the same file content is submitted, the actual data transformation and loading processes are executed only once for each unique input.

Implementation Details and Considerations
The choice of hash algorithm is important. SHA-256 is a good standard as it provides a very low probability of hash collisions (where two different inputs produce the same hash). For extremely large files, chunking the file and hashing each chunk, then hashing the chunk hashes, can be more memory-efficient, though it adds complexity.
The storage mechanism for processed hashes needs to be reliable and queryable. For a small project, a simple JSON file or a SQLite database might suffice. For larger, production systems, a dedicated key-value store or a relational database with an index on the hash column would be more appropriate. The key consideration is the speed of lookup; a slow lookup would negate the performance benefits of skipping processing.
Furthermore, the system must handle potential race conditions. If two identical jobs are submitted concurrently, both might generate the hash and find it missing before either has a chance to write its success record. This can be mitigated using atomic operations or locking mechanisms on the hash storage during the check-and-write operation.
Benefits of Source Hashing
Employing a source_hash strategy offers several key advantages:
- Data Integrity: Prevents duplicate records from corrupting analytical metrics and downstream processes.
- Resource Efficiency: Saves computational resources (CPU, memory) and time by avoiding redundant work.
- Operational Simplicity: Allows operators to resubmit jobs or backfill data with confidence, knowing that duplicates will be handled automatically.
- Auditability: The stored hashes provide a clear audit trail of which unique inputs have been processed and when.
This approach transforms the potential problem of duplicate inputs into a manageable aspect of data pipeline design, ensuring robustness and reliability.
