# Source: https://docs.squared.ai/open-source/guides/architecture/sync-states.md

> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squared.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Sync States

# Overview

This document details the states and transitions of sync operations, organizing the sync process into specific statuses and run states. These categories are vital for managing data flow during sync operations, ensuring successful and efficient execution.

## Sync Status Definitions

Each sync run operation can be in one of the following states, which represent the sync run's current status:

| State        | Description                                                                                       |
| ------------ | ------------------------------------------------------------------------------------------------- |
| **Healthy**  | A state indicating the successful completion of a recent sync run operation without any issues.   |
| **Disabled** | Indicates that the sync operation has been manually turned off and will not run until re-enabled. |
| **Pending**  | Assigned immediately after a sync is set up, signaling that no sync runs have been initiated yet. |
| **Failed**   | Denotes a sync operation that encountered an error, preventing successful completion.             |

> **Note:** Ensure that sync configurations are regularly reviewed to prevent prolonged periods in the Disabled or Failed states.

### Sync State Transitions

The following describes the allowed transitions between the sync states:

* **Pending ➔ Healthy**: Occurs when a sync run completes successfully.
* **Pending ➔ Failed**: Triggered if a sync run fails or is aborted.
* **Failed ➔ Healthy**: A successful sync run after a previously failed attempt.
* **Any state ➔ Disabled**: Reflects the manual disabling or enabling of the sync operation.

## Sync Run Status Definitions

| Status             | Description                                                                                                                                                                                                                                                                                    |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Started**        | Indicates that the sync operation has begun. This status serves as the initial state of a new sync run operation after being triggered.                                                                                                                                                        |
| **Querying**       | The sync is currently querying a source with its associated model to retrieve the latest data. This involves moving data to a temporary table called "SyncRecord".                                                                                                                             |
| **Queued**         | Indicates the sync is scheduled for execution, following the successful transfer of source data to the "SyncRecord" table. This marks the completion of the preparation phase, with the sync now ready to transmit data to the destination as per system scheduling and resource availability. |
| **In Progress**    | The sync is actively transferring data from the "SyncRecord" table to the destination. This phase marks the actual update or insertion of data into the destination database, reflecting the final step of the sync process.                                                                   |
| **Success**        | The sync run is completed successfully without any issues.                                                                                                                                                                                                                                     |
| **Paused**         | Indicates a temporary interruption occurred while transferring data from the "SyncRecord" table to the destination. The sync is paused but designed to automatically resume in a subsequent run, ensuring continuity of the sync process.                                                      |
| **Aborted/Failed** | The sync has encountered an error that prevents it from completing successfully.                                                                                                                                                                                                               |

### Sync Run State Transitions

The following describes the allowed transitions between the sync run states:

* **Started ➔ Querying**: Transition post-initiation as data retrieval begins.
* **Querying ➔ Queued**: After staging data in the "SyncRecord" table, indicating readiness for transmission.
* **Queued ➔ In Progress**: Commences as the sync operation begins writing data to the destination, based on availability of system resources.
* **In Progress ➔ Success**: Marks the successful completion of data transmission.
* **In Progress ➔ Paused**: Triggered by a temporary interruption in the sync process.
* **Paused ➔ In Progress**: Signifies the resumption of a sync operation post-interruption.
* **In Progress ➔ Aborted/Failed**: Initiated when an error prevents the successful completion of the sync operation.