Health Check

Sparque performs frequent re-indexing to update and maintain the accuracy of the system's data. To prevent corruption (e.g., due to incorrect files), it is crucial to perform a health check before creating a new index. The health check verifies that the required data and resources are in good condition. This document explains the purpose of the health check, how it works, and how to configure it for your API.

What is a Health Check?

A health check validates the status of an API and its dependent data before a new index is published in Sparque. It ensures that the required objects are available so that the indexing process can proceed safely.

  • If the health check passes (i.e., objects are returned), the new index will be published.
  • If it fails (i.e., no objects are returned), the new index is NOT created and the old index is used.

How the Health Check Works

  1. Execution timing: Automatically triggered before each new index is published.
  2. API endpoint: Each API within a workspace must have an endpoint called /health_check.
  3. Object verification: The health check verifies that the API returns objects. If one or more objects are returned, it is considered successful.
  4. Health check failure: If no objects are returned, the index creation process stops and the old valid index is used.

Health Check Flow

  1. Initial index execution: A new index is about to be published.
  2. Triggering the health check: The health check is performed before the index is published.
  3. Health check output:
    • Success: The /health_check endpoint returns one or more objects and the new index is published.
    • Failure: No objects are returned. The index creation is stopped and the system falls back to the old index.

The system will repeat above steps whenever a new index is triggered.

Configuring the Health Check

To enable health checking for your API, you need to configure a /health_check endpoint within each API that returns a relevant object. The assigned strategy allows you to specify the objects that Sparque must check before creating the index.

Configuration steps:

  1. Define the /health_check endpoint:
    • Each API should expose an endpoint named /health_check.
    • This endpoint should return a valid response containing objects.
  2. Configure required objects:
    • In the API configuration strategy, define which objects the health check should validate. This could include data files, configuration files, or other resources that are essential for a successful index creation.

Example

This visualization shows an assigned strategy for the /health_check endpoint. It checks safety levels for each class (e.g., products = 1000, category = 200, order = 750). If any class has insufficient objects (e.g., if the index has 889 products instead of 1000 or more), the safety level is not reached and no objects are returned (Top N = 0), causing the health check to fail.


Strategy for the health check endpoint

Troubleshooting

If the health check fails:

  1. Investigate the response: Check in Sparque desk which objects are missing or invalid.
  2. Correct the issue: Fix any issues with the data or within the assigned health_check strategy.

Summary

The health check is a critical safeguard in Sparque to ensure that new indexes are only created when the necessary resources are available and valid. By correctly configuring the /health_check endpoint, you can help prevent issues such as missing or corrupt data, ensuring smooth index creation and stable system operation.

Key Points

  • Each API must expose a health_check endpoint.
  • Each health check must return objects for the index process to proceed.
  • If one of the health check fails, the index creation process will be stopped and will be repeated within the next iteration.