- The data needed by the action is already available from a previous sync
- You want to minimize API calls, reduce latency, and improve reliability
- You want to provide a fast, consistent user experience even if the third-party API is slow or unavailable
Key Characteristics
- Uses previously fetched or synced data when available
- Falls back to a live API call only if no data is available
- Transforms data as needed before returning
- Returns a consistent, typed response
Visual Representation
Implementation Example
Here’s a generic example of this pattern:Key Implementation Aspects
- Synced data first: The action first attempts to use data that was previously fetched by a sync
- Fallback: If no records are found, it can fallback to a live API call (not shown in this example)
- Transformation: The action transforms the data as needed before returning
- Consistent Response: Always returns a consistent, typed response, even if no data is found
Best Practices
- Prefer previously synced data to minimize API calls and improve performance
- Handle empty or special cases gracefully
- Return a consistent response shape regardless of data source
- Document fallback logic for maintainability
- Keep transformation logic simple and clear
Common Pitfalls
- Not keeping synced data up to date, leading to stale or missing data
- Failing to handle the case where no data is available from sync or API
- Returning inconsistent response shapes
- Not transforming data as needed
- Overcomplicating fallback logic