redis / redis/redis-om-python

Zero-downtime schema migrations using RediSearch aliases

Open
#773 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
1.3k
Forks
128
PR merge metrics
No merged PRs in 30d

Description

Summary

Add support for zero-downtime schema migrations using RediSearch index aliases instead of the current DROP+CREATE approach.

Problem

The current migration system (Migrator.run()) detects schema changes and performs:

  1. FT.DROPINDEX on the existing index
  2. FT.CREATE with the new schema

This causes downtime because queries fail while the index is being recreated and data is being reindexed.

Proposed Solution

Use RediSearch aliases (FT.ALIASADD, FT.ALIASUPDATE) to enable atomic index switching:

Index Naming Convention
Real index:  {prefix}:{model}:index:v1, {prefix}:{model}:index:v2, ...
Alias:       {prefix}:{model}:index  (what queries use)
Migration Flow
  1. Create new versioned index (e.g., idx:Product:v2) with updated schema
  2. Reindex/copy documents to new index (queries continue hitting v1 via alias)
  3. Atomically switch alias: FT.ALIASUPDATE idx:Product idx:Product:v2
  4. Drop old index idx:Product:v1
Implementation Requirements
  1. Version tracking - Store current version in Redis key (e.g., {prefix}:{model}:index:version)

  2. Initial setup - First migration creates v1 index and adds alias pointing to it

  3. Model queries - No change needed; already use Meta.index_name which becomes the alias

  4. New migration commands:

    • om migrate run --zero-downtime - Use alias-based migration
    • om migrate status - Show current index version and alias target
  5. Background reindexing - Copy documents from old index to new (may need batching for large datasets)

Key Redis Commands
FT.ALIASADD <alias> <index>      # Create alias (first time)
FT.ALIASUPDATE <alias> <index>   # Atomic switch to new index
FT.ALIASDEL <alias>              # Delete alias

Benefits

  • Zero downtime during schema migrations
  • Queries continue working throughout migration
  • Atomic switchover (no partial state)
  • Easy rollback (switch alias back to previous version)

Considerations

  • Increased Redis memory during migration (two indexes exist temporarily)
  • Reindexing time depends on dataset size
  • Need to handle concurrent writes during migration

References

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading Migrator.run() and the proof of concept in .ai/qa_alias_migration.py, then trace the existing migrate commands. Done means supporting alias-based zero-downtime migrations, version and alias status reporting, background reindexing, and the proposed --zero-downtime command without interrupting queries.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, redis
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.