Webhook icon
Schedule icon
Request icon
Download icon
Script icon
BulkIndex icon
Search icon
FacetSearch icon
If icon
Log icon

Zero-Downtime Typesense Collection Reindexing and Alias Cutover Gate

Rebuild Typesense search collections without downtime. Create a versioned collection, bulk index records, verify canaries, and atomically swap the alias.

Categories
Data

Production search engines power revenue-critical user experiences like e-commerce storefronts, SaaS navigation, and documentation search. In Typesense, modifying an existing schema (such as adding facet fields, updating token separators, or re-weighting ranking fields) cannot be performed in-place on a live collection without locking queries or risking corrupt search results.

This blueprint implements the industry-standard Zero-Downtime Collection Aliasing pattern for Typesense. It creates an isolated, versioned physical collection, ingests and bulk-indexes incoming records using io.kestra.plugin.typesense.BulkIndex, and executes automated search recall and facet distribution canaries via io.kestra.plugin.typesense.Search and io.kestra.plugin.typesense.FacetSearch. Only when every quality gate passes does Kestra atomically re-point the production alias (PUT /aliases/{alias_name}) in Typesense memory. If any canary fails, the staged collection is purged immediately, ensuring that customer-facing search queries never experience a single dropped request or degraded result set.

How it works

  1. inspect_current_alias (io.kestra.plugin.core.http.Request) queries GET /aliases/{{ inputs.alias_name }} to capture the name of the currently active physical collection for rollback reference and optional post-cutover retirement.
  2. stage_new_collection (io.kestra.plugin.core.http.Request) declares a new timestamped versioned collection {{ inputs.alias_name }}_v{{ execution.id | slice(0, 8) }} with the required field schema, sorting parameters, and facet definitions.
  3. download_catalog_feed (io.kestra.plugin.core.http.Download) fetches the product catalog from catalog_feed_url into Kestra internal storage. prepare_catalog_payload (io.kestra.plugin.scripts.python.Script) reshapes it into line-delimited JSON (catalog.jsonl) matching the staged collection's schema.
  4. bulk_index_catalog (io.kestra.plugin.typesense.BulkIndex) streams the JSONL records into the newly staged versioned collection in chunked HTTP batches, returning the verified count of indexed documents under outputs.bulk_index_catalog.size.
  5. run_canary_search (io.kestra.plugin.typesense.Search) executes a representative full-text search against the new collection, validating query response latency and ensuring hit counts meet inputs.canary_min_hits.
  6. run_canary_facet_search (io.kestra.plugin.typesense.FacetSearch) runs an aggregation search against inputs.canary_facet_field to confirm that faceted navigation structures indexed correctly.
  7. evaluate_cutover_gate (io.kestra.plugin.core.flow.If) branches on the canary outcomes:
    • Then (Validation Passed): atomic_alias_cutover issues PUT /aliases/{{ inputs.alias_name }} with {"collection_name": "<new_collection>"}, switching live traffic in an instant memory operation. If retire_previous_collection is enabled, delete_superseded_collection drops the old collection; otherwise, it is retained for instant manual rollback.
    • Else (Validation Failed): abort_and_delete_staged_collection purges the staged collection from the cluster, leaving the live alias completely untouched.
  8. The flow-level errors block intercepts any unhandled task failures and guarantees cleanup of orphaned staged collections so disk capacity is never leaked.

What you get

  • Zero downtime for customer queries during schema upgrades, catalog rebuilds, and full data reloads.
  • Automated canary gating that prevents broken or empty collections from reaching the storefront.
  • Atomic alias switching via Typesense's native /aliases API.
  • Safe collection retirement options with rollback protection.
  • Self-contained execution that cleans up staged artifacts on both success and failure.

Who it's for

  • Search Platform Engineers managing Typesense, Meilisearch, or Elasticsearch clusters.
  • E-commerce Operations Teams requiring uninterrupted storefront search during catalog refreshes.
  • Data Engineers orchestrating ETL-to-search pipelines with schema evolution.

Why orchestrate this with Kestra

Scripting zero-downtime reindexing with bash or ad-hoc scripts frequently leads to ghost collections, failed rollbacks, or unnoticed canary failures when scripts crash halfway through. Kestra manages the complete multi-step lifecycle with state tracking, native secret masking, flow control branching, and automated error handlers. If network glitches or API errors occur during bulk ingestion, Kestra can retry transient operations while guaranteeing that defective collections never receive production traffic.

Prerequisites

  • A running Typesense cluster (v0.25+ or v27+) reachable by the Kestra worker.
  • An admin API key with permission to create collections, manage aliases, and index documents.

Secrets

  • TYPESENSE_API_KEY: Typesense administrative API key used for authentication across all tasks.
  • TYPESENSE_REINDEX_WEBHOOK_KEY: Secret authentication key for the event-driven webhook trigger.

Quick start

  1. Start a local Typesense container with Docker:

    docker run -d -p 8108:8108 \
      -v /tmp/typesense-data:/data \
      typesense/typesense:27.1 \
      --data-dir /data \
      --api-key=test-typesense-api-key \
      --enable-cors
    
  2. Configure the required secrets in your Kestra namespace:

    • TYPESENSE_API_KEY: test-typesense-api-key
    • TYPESENSE_REINDEX_WEBHOOK_KEY: secret-webhook-key-12345
  3. Execute the flow manually in Kestra with the default catalog_feed_url (a public demo endpoint) or trigger it via the webhook endpoint once enabled.

  4. Verify in the execution logs that the versioned collection was staged, passed canary queries, and atomically assumed the products alias.

How to extend

  • Point catalog_feed_url at your PIM or commerce platform's export endpoint, and adjust the field mapping in prepare_catalog_payload to match its JSON shape.
  • Add automated Slack or PagerDuty notification tasks inside the then and else blocks to broadcast cutover summaries to your engineering team.
  • Enable the reindex_webhook and weekly_reindex_schedule triggers to run automated off-peak maintenance sweeps once catalog_feed_url points at a real feed.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.