Description:
We are currently using Google Cloud Datastream to replicate data from a CloudSQL (MySQL) instance into BigQuery in near real-time. The replication works perfectly for insert and update operations, and all changes are reliably reflected in BigQuery.
However, we are facing a major issue:
Whenever a DELETE or TRUNCATE operation is performed on the source MySQL database, the corresponding rows are also deleted from BigQuery. This results in the loss of historical data, which we want to retain.
What we've tried:
APPEND-ONLY Mode in Datastream
We explored the APPEND-ONLY mode provided by Datastream, which retains all versions of records (along with metadata such as operation type). However, this approach introduces a lot of data redundancy — each update operation creates a new row, leading to a rapid increase in table size and complexity in querying current vs. historical states.Disabling Binary Logging for Deletes (
SET SQL_LOG_BIN=0
)
We also tried disabling binary logging for delete operations. However, this is not feasible in our case as deletions are initiated programmatically, vary across scenarios, and cannot be reliably controlled at the session or query level.
Requirement:
We are looking for a no-code or low-code solution to prevent delete and truncate operations on the source database from being propagated to BigQuery. Ideally, we would like to retain only the latest state of data for updates but completely ignore deletes during replication.
Question:
- Is there any configuration in Datastream or BigQuery that can help achieve this behavior?
- Can we build a Dataflow pipeline or transformation layer that listens to Datastream's change records and filters out DELETE/TRUNCATE operations before writing to BigQuery?
- Are there any other Google Cloud-native solutions that support selective replication or change filtering?
We are trying to avoid managing this manually or using complex ETL transformations, so a low-maintenance, scalable solution would be preferred.
Any guidance or recommendations would be highly appreciated!