The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Designing ML systems with fallbacks for third-party service failures

In machine learning (ML) systems, third-party services are often integrated for various functionalities such as data collection, model inference, storage, or API calls. These services, however, can sometimes fail due to network issues, downtime, or unexpected errors. To ensure the robustness and reliability of the system, ML engineers must design fallbacks that can gracefully handle these failures.

Here’s how you can design ML systems with fallbacks for third-party service failures:

1. Identify Critical Points of Failure

  • Third-party APIs: Many ML systems depend on external APIs for real-time data or services such as weather, user data, or sentiment analysis.

  • External Databases: ML pipelines might rely on data from cloud-based storage or third-party databases that could become temporarily inaccessible.

  • Model Hosting Platforms: Sometimes, models are hosted on external platforms for scalability, and these could experience outages.

  • Data Sources: External systems might also provide data (e.g., customer data, social media feeds, etc.), and an outage in these sources can disrupt model performance.

2. Designing a Fallback Mechanism

The key objective of a fallback mechanism is to ensure that if the primary service fails, the system can still function without a significant drop in performance or reliability. Here are some strategies:

a. Circuit Breaker Pattern

  • What It Is: The circuit breaker pattern is a software design pattern used to detect failures and prevent the system from trying to execute operations that are likely to fail. It involves monitoring the external service’s health and “tripping” the circuit breaker if the failure rate exceeds a predefined threshold.

  • How It Helps: When the circuit breaker is tripped, the system can switch to a backup path, preventing the failure from propagating.

  • When to Use: This pattern is ideal for cases where external services are unreliable, or their availability is inconsistent.

b. Graceful Degradation

  • What It Is: In cases where the primary service fails, the system degrades gracefully by providing a less sophisticated but still useful output.

  • How It Helps: Instead of failing completely, the system can switch to a simplified version of the ML model or use less critical data to produce an approximate result.

  • When to Use: This is particularly useful when some level of accuracy can be sacrificed in favor of availability.

c. Caching and Stale Data Handling

  • What It Is: Cache the results of third-party service calls, so if the service fails, the system can serve the cached data. This can be done for both model predictions and raw input data.

  • How It Helps: Caching allows the system to continue functioning even when real-time data cannot be fetched from the third-party service. Additionally, you can set expiration times for cached data to prevent the system from using stale information for too long.

  • When to Use: Ideal for scenarios where data does not need to be real-time, and you can tolerate delays in updating the cached information.

d. Redundancy with Multiple Third-Party Providers

  • What It Is: Instead of relying on a single third-party service, the system can use multiple providers for the same service (e.g., two APIs for weather data).

  • How It Helps: If one service fails, the system can switch to another. This is useful when there are multiple reliable service providers that offer the same functionality.

  • When to Use: This approach is effective for high-stakes applications where failures cannot be tolerated, such as financial predictions or healthcare applications.

e. Fallback to a Pre-trained Model

  • What It Is: In cases where external APIs are used for model inference or feature extraction (e.g., a language model API or facial recognition service), you can fallback to an on-premise, pre-trained version of the model.

  • How It Helps: If the third-party service is unavailable, the system can use a local, cached version of the model to make predictions. This eliminates the dependency on an external service for key decisions.

  • When to Use: This is useful when external models are too slow, unreliable, or costly to run, and a reasonable trade-off can be made by using pre-trained versions.

f. Monitoring and Alerts for Fast Response

  • What It Is: Implementing a real-time monitoring and alerting system that watches for third-party service failures and triggers an automatic fallback mechanism or alerts the engineering team.

  • How It Helps: This ensures that when a service fails, the system can react quickly, either by activating fallback mechanisms or notifying the relevant stakeholders to address the issue.

  • When to Use: This is essential in any critical ML system where quick detection and intervention are required to minimize downtime.

3. Handling Failure in Model Updates and Retraining

Third-party services often supply data for retraining models. If the service fails during the retraining phase, you’ll need strategies to ensure that the model is still updated:

a. Data Subset for Retraining

  • What It Is: Use a smaller, locally available dataset for retraining the model when external data sources are unavailable.

  • How It Helps: This ensures that the model is still updated, even if the complete dataset is unavailable.

  • When to Use: This is helpful when the training data is abundant, but the real-time data pipeline is temporarily offline.

b. Hybrid Retraining

  • What It Is: Instead of retraining the model using only the third-party service data, you can use hybrid approaches combining third-party data with internal data or alternative external sources.

  • How It Helps: This reduces reliance on a single external data source and ensures retraining can continue even if one service fails.

  • When to Use: Ideal when third-party data is only a small part of the overall dataset used for model training.

4. Testing and Validation of Fallbacks

When designing fallback mechanisms, thorough testing is crucial to ensure they work as expected during real failures. This can be done by:

  • Simulating failures: Introduce failures in third-party services and validate that the fallback mechanisms trigger appropriately.

  • Stress testing: Test the system under heavy load to ensure it can handle multiple failures concurrently without crashing.

  • End-to-End Monitoring: Continuously monitor the performance and accuracy of fallback mechanisms, ensuring that they don’t degrade system performance.

5. Documentation and Transparency

Clear documentation about how the fallback system works is critical for both the developers and end users. The system should log any fallback triggers and their impact, and the logs should be accessible for troubleshooting and auditing.


By incorporating these strategies, ML systems can become more resilient and reliable, even in the face of third-party service failures. Implementing robust fallbacks ensures the ML pipeline remains functional and can recover gracefully, maintaining its usefulness without compromising too much on the quality of predictions or insights.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About