How does airbyte handle deleted records at source ...
# ask-ai
y
How does airbyte handle deleted records at source for incremental syncs? Any options for hard/soft deletes even with incremental syncs?
k
Airbyte’s default incremental sync modes do not propagate deletions from the source to the destination. If a record is deleted in the source, it will remain in the destination after an incremental sync. This is a known limitation: incremental syncs only replicate new or updated records, not deletions. As a result, the destination will not mirror deletions that occur in the source unless additional strategies are used. Options for handling deletes with incremental syncs: 1. Hard Deletes (True Deletion in Destination): - Change Data Capture (CDC): For supported databases (e.g., Postgres, MySQL, MSSQL, MongoDB), Airbyte offers CDC, which can capture and propagate
DELETE
operations. With CDC, deleted records in the source are flagged (e.g., with a
_ab_cdc_deleted_at
timestamp) or removed in the destination, depending on your sync configuration. This is the recommended approach if you need the destination to reflect hard deletes from the source. CDC is only available for certain sources and requires primary keys on tables. [Read more about CDC support and limitations](https://docs.airbyte.com/platform/1.6/understanding-airbyte/cdc). 2. Soft Deletes (Marking Records as Deleted): - If your source system exposes a "deleted" flag (e.g., via an API field), you can replicate this field to the destination and use it to indicate soft deletes. This requires the source to provide such information; otherwise, Airbyte cannot infer deletions. - For APIs that provide a separate endpoint for deletions, you can design your connector to fetch deleted records and update a "deleted" status in the destination, typically via custom transformations or by merging update and delete streams in your data warehouse logic. [See forum discussion for best practices](https://discuss.airbyte.io/t/1256). 3. Full Refresh Overwrite: - If you need the destination to always exactly mirror the source (including deletions) and cannot use CDC, you can use the "Full Refresh Overwrite" sync mode. This mode erases all data in the destination and reloads it from the source on each sync, ensuring deletions are reflected but at the cost of efficiency and higher resource usage. 4. Refresh Syncs: - Airbyte also offers "Refresh Syncs," which can be used to re-import all records and optionally remove records in the destination that are no longer present in the source. This can help detect deletions for sources that do not track them, but is more resource-intensive than incremental syncs. [See Refresh Sync documentation](https://docs.airbyte.com/platform/operator-guides/refreshes). Summary Table: | Sync Mode | Handles Deletes? | Notes | |--------------------------|------------------|----------------------------------------------------------------------------------------| | Incremental (default) | No | Deleted records in source remain in destination. | | Incremental + CDC | Yes | For supported DBs; propagates deletes using metadata columns. | | Soft Delete (custom) | Yes (soft) | Requires source to expose a deleted flag or a deletes endpoint. | | Full Refresh Overwrite | Yes | Destination is fully replaced each sync; resource-intensive. | | Refresh Sync | Yes (optionally) | Can remove records not present in source; more expensive than incremental. | Key Takeaway: If you need to propagate deletes with incremental syncs, use CDC for supported sources, or implement soft deletes if your source exposes the necessary information. Otherwise, consider full refresh or refresh syncs for full mirroring, but be aware of the performance trade-offs. [See more: Airbyte Incremental Sync and Deletes](https://airbyte.com/tutorials/incremental-data-synchronization#step-7) [CDC documentation](https://docs.airbyte.com/platform/1.6/understanding-airbyte/cdc) [Refresh Syncs](https://docs.airbyte.com/platform/operator-guides/refreshes)
y
@kapa.ai is there a way for a sync to update data incrementally per hour but once a week, we do a full refresh
k
A message from kapa.ai
Airbyte does not natively support scheduling both incremental syncs (e.g., hourly) and a periodic full refresh (e.g., weekly) for the same connection through the UI. The UI allows you to choose either an incremental or a full refresh sync mode, and you can schedule syncs at regular intervals or via cron, but not a combination of both modes on different schedules within a single connection. However, there are workarounds: 1. Manual or API-Driven Full Refresh: You can set your connection to run incremental syncs on an hourly schedule. Then, once a week, you can manually trigger a full refresh (overwrite) sync via the Airbyte API or UI. This approach requires you to programmatically change the sync mode or trigger a "Refresh Sync" at your desired interval. The Airbyte API allows you to trigger syncs and update connection configurations, so you could automate this with a script and a cron job outside of Airbyte. For example, you could use a weekly cron job to call the Airbyte API and trigger a refresh sync or change the sync mode for a one-time full refresh, then revert to incremental afterward. This is discussed as a workaround in the community forum and GitHub issues, but there is no official guide for this process [Forum: Custom Replication/Sync Time](https://discuss.airbyte.io/t/379), [GitHub Issue: Schedule full refresh for incremental stream](https://github.com/airbytehq/airbyte/issues/26513). 2. Refresh Syncs: Airbyte's "Refresh Sync" feature allows you to reset the incremental cursor and re-import all data, effectively performing a full refresh. This can be triggered via the UI or API, and you could automate this process externally to run weekly, while your regular incremental syncs continue on their schedule. Note that while a refresh sync is running, other scheduled syncs are blocked until it completes [Refreshing your data](https://docs.airbyte.com/platform/operator-guides/refreshes). Summary: There is no built-in way to schedule both hourly incremental syncs and a weekly full refresh in the UI, but you can achieve this by combining scheduled incremental syncs with periodic, API-triggered refresh syncs or by programmatically switching sync modes as needed. If you need more details on how to implement this with the API, let me know!
y
@kapa.ai how do you automate "refresh sync" feature on a schedule?
k
A message from kapa.ai
To automate the "Refresh Sync" feature on a schedule in Airbyte, you need to use the Airbyte API, as there is no built-in UI option to schedule refresh syncs at custom intervals. Here’s how you can approach this: 1. Use the Airbyte API to Trigger a Refresh Sync: Airbyte allows you to trigger syncs (including refresh syncs) via its API. You can make a POST request to the appropriate endpoint with your connection ID and specify the type of sync you want to perform. This can be scripted and scheduled using external tools like cron. 2. Automate with a Scheduler (e.g., cron): Set up a cron job (or any other scheduler) to run your script at the desired interval (e.g., weekly). The script should call the Airbyte API to trigger a refresh sync for your connection. 3. Example Approach: - Write a script (in bash, Python, etc.) that sends a POST request to the Airbyte API to trigger a refresh sync. - Schedule this script to run at your desired interval using cron or another scheduler. Note: The knowledge sources confirm that refresh syncs can be triggered via the API, but do not provide a specific API endpoint or payload example for "refresh sync" (as opposed to a standard sync). However, the general approach is to use the API to trigger jobs, as shown in the tutorials and documentation. You may need to consult the [Airbyte API documentation](https://airbyte-public-api-docs.s3.us-east-2.amazonaws.com/rapidoc-api-docs.html) for the exact endpoint and parameters for a refresh sync. For more details, see: [Refreshing your data](https://docs.airbyte.com/platform/operator-guides/refreshes) [Create and Monitor a Data Pipeline Using the Airbyte API](https://airbyte.com/tutorials/create-and-monitor-a-data-pipeline-using-the-airbyte-api) Summary: You can automate "Refresh Sync" by scripting API calls and scheduling them with an external scheduler like cron. The knowledge sources do not provide a step-by-step guide or code sample specifically for refresh syncs, so you may need to refer to the Airbyte API documentation for implementation details.
y
@kapa.ai Or is it reasonable to set up another connection to do full refresh on a table weekly while another connector refreshes it hourly incrementally? does this mess up state?
k
A message from kapa.ai
Yes, it is reasonable to set up two separate Airbyte connections for the same source and destination table—one running hourly incremental syncs and another running a weekly full refresh. This approach is sometimes used as a workaround to achieve both frequent incremental updates and periodic full refreshes. State Management: Airbyte manages state at the connection level, not at the destination table level. This means each connection maintains its own state and cursor independently. Therefore, running two connections in parallel (one incremental, one full refresh) will not mess up the state of either connection. Each connection will track its own progress and sync history separately. However, there are important considerations: - Table Overwrites: If both connections write to the exact same destination table (without using unique prefixes or namespaces), the full refresh connection will overwrite the table, potentially erasing data written by the incremental connection. This can lead to data inconsistencies or loss. - Unique Stream Requirement: As of Airbyte 1.6, stream identifiers (table names) must be unique across connections sharing a destination. You must use unique prefixes or namespaces for each connection to avoid conflicts. After syncing, you can merge the tables downstream if needed. [Unique stream prefixes or namespaces are now mandatory](https://docs.airbyte.com/release_notes/v-1.6#unique-stream-prefixes-or-namespaces-are-now-mandatory). Recommended Approach: - Use unique prefixes or namespaces for each connection to avoid table conflicts. - Merge the data from the two tables in your data warehouse if you need a unified view. - Do not have both connections write to the exact same table, as this can cause concurrency and data integrity issues, especially if syncs overlap in time [Forum: Multiple source sync to same destination table](https://discuss.airbyte.io/t/1105), [Forum: Manage multiple sources sync to the same tables](https://discuss.airbyte.io/t/323). Summary: You can safely run two connections (one incremental, one full refresh) as long as they write to different tables (using prefixes/namespaces). This will not mess up state, but you must handle downstream merging if you want a single unified table. If you need both connections to write to the same table, this is not supported and can cause issues. Use unique table names and merge downstream instead.