Skip to content
intermediate Phase 67 · Indexer System

Index Modes — Update on Save vs Update by Schedule

Understanding Magento 2 index modes: real-time (Update on Save) vs scheduled (Update by Schedule), mode selection, and trade-offs

45m
1 problems
Topic Progress 0%

Real-Time Mode (Update on Save)

How Real-Time Works

Product Save -> Index Updated Immediately -> Response

When a product is saved, the index is updated synchronously before the response is returned.

When to Use Real-Time

  • Small catalogs (< 10,000 products)
  • Low-frequency updates
  • When immediate consistency is required
  • Development environments

Configuration

php bin/magento indexer:set-mode realtime catalog_product_price

Real-Time Flow

// In product model save()
public function afterSave()
{
    parent::afterSave();
    // Index updated immediately
    $this-> indexer->reindex($this->getId());
}

Performance Impact

-- Real-time adds ~50-200ms to each save
-- For bulk operations:
-- 100 products: +5-20 seconds
-- 1000 products: +50-200 seconds

Pros and Cons

Pros Cons
Always consistent Slower saves
No cron dependency Database locks during save
Simple to debug Not suitable for bulk
Immediate availability Performance impact on save

Scheduled Mode (Update by Schedule)

How Scheduled Works

Product Save -> Index Flagged as Invalid -> Response
Cron Run -> Invalid Indexes Reindexed

The index is not updated immediately. Instead, the indexer state is set to 'invalid' and a cron job processes it later.

When to Use Scheduled

  • Large catalogs (> 10,000 products)
  • High-frequency updates
  • Bulk import operations
  • Production environments

Configuration

php bin/magento indexer:set-mode schedule catalog_product_price

Scheduled Flow

// In product model save()
public function afterSave()
{
    parent::afterSave();
    // Just mark as invalid
    $this->indexerState->setStatus(
        Indexer::STATE_INVALID
    );
}

// Cron job processes invalid indexes
public function execute()
{
    $invalidIndexers = $this->getInvalidIndexers();
    foreach ($invalidIndexers as $indexer) {
        $indexer->reindexFull();
    }
}

Changelog Table

Scheduled indexing uses a changelog table:

-- Tracks changes for incremental reindex
CREATE TABLE catalog_product_price_cl (
    entity_id INT,
    updated_at TIMESTAMP
);

Pros and Cons

Pros Cons
Fast saves Slight delay before index updates
No DB locks on save Requires cron to run
Better for bulk ops Temporary inconsistency
Scalable More complex debugging

Mode Selection Guide

Decision Matrix

Scenario Recommended Mode
Small store (<5k products) Real-time
Large store (>10k products) Schedule
Frequent imports Schedule
Low update frequency Real-time
Development/staging Real-time
Production Schedule
API-heavy integration Schedule
Real-time search needed Real-time

Per-Indexer Configuration

Different indexers can use different modes:

# Price: schedule (heavy computation)
php bin/magento indexer:set-mode schedule catalog_product_price

# Category product: schedule
php bin/magento indexer:set-mode schedule catalog_category_product

# Search: real-time (immediate consistency)
php bin/magento indexer:set-mode realtime catalogsearch_fulltext

Hybrid Approach

# Most indexers on schedule
php bin/magento indexer:set-mode schedule catalog_product_price
php bin/magento indexer:set-mode schedule catalog_category_product

# Search on real-time
php bin/magento indexer:set-mode realtime catalogsearch_fulltext

Mode Comparison

Aspect Real-time Schedule
Save speed Slow Fast
Data freshness Immediate Delayed
DB locks Yes No
Bulk import Slow Fast
Complexity Simple More complex
Consistency Strong Eventual

Switching Modes and Migration

Switching from Real-Time to Schedule

# 1. Set mode
php bin/magento indexer:set-mode schedule catalog_product_price

# 2. Full reindex to initialize changelog
php bin/magento indexer:reindex catalog_product_price

# 3. Verify
php bin/magento indexer:status catalog_product_price

Switching from Schedule to Real-Time

# 1. Full reindex first
php bin/magento indexer:reindex

# 2. Set mode
php bin/magento indexer:set-mode realtime catalog_product_price

# 3. Verify
php bin/magento indexer:status catalog_product_price

Checking Current Mode

# Show all modes
php bin/magento indexer:show-mode

# Output:
+------------------------------------+------------+
| Indexer                            | Mode       |
+------------------------------------+------------+
| catalog_product_price              | schedule   |
| catalog_category_product           | schedule   |
| catalogsearch_fulltext             | realtime   |
+------------------------------------+------------+

Impact of Mode on Bulk Operations

// Import with real-time (slow)
foreach ($products as $product) {
    $product->save(); // Index updated each save
}
// 1000 products * 200ms = 200 seconds

// Import with schedule (fast)
foreach ($products as $product) {
    $product->save(); // Just flag as invalid
}
$this->indexer->reindexList($productIds); // Batch reindex
// Total: ~10 seconds

Practice Problems

0 / 1 solved
Mode Selection

A store with 50,000 products does hourly imports. The import takes 3 hours. Recommend index mode changes.

Quiz

1. In real-time mode, when is the index updated?

Question 1 options

2. What table does scheduled indexing use to track changes?

Question 2 options

3. Which mode is better for large catalogs with frequent imports?

Question 3 options

4. What command shows the current mode of all indexers?

Question 4 options

Flashcards

Question

When is the index updated in real-time mode?

Answer

Immediately when data is saved, synchronously before response

Question

When is the index updated in schedule mode?

Answer

Via cron job after data is flagged as invalid

Question

What table tracks changes for scheduled indexing?

Answer

Changelog table with _cl suffix (e.g., catalog_product_price_cl)

Question

Which mode is better for bulk imports?

Answer

Schedule mode — avoids DB locks and enables batch reindexing

Question

How to switch from real-time to schedule?

Answer

Set mode, then full reindex to initialize changelog

Revision Notes

Key Takeaways

  • 1. Real-time mode updates index immediately on save (slow saves, immediate consistency)
  • 2. Schedule mode flags data as invalid and reindexes via cron (fast saves, eventual consistency)
  • 3. Schedule mode uses changelog tables (_cl suffix) for incremental reindexing
  • 4. Different indexers can use different modes based on needs
  • 5. Switch modes with indexer:set-mode and full reindex
  • 6. Schedule mode is preferred for large catalogs and bulk operations

Interview Tips

  • Compare real-time and scheduled modes with pros and cons
  • Explain when to use each mode with specific scenarios
  • Describe how changelog tables work in scheduled mode
  • Discuss mode switching implications

Cheat Sheet

Index Modes Cheat Sheet

Real-time:

  • Index updated on save
  • Immediate consistency
  • Slow saves, DB locks
  • Best for small catalogs

Schedule:

  • Index updated via cron
  • Eventual consistency
  • Fast saves, no locks
  • Best for large catalogs

Switch:
php bin/magento indexer:set-mode schedule catalog_product_price
php bin/magento indexer:reindex

Check:
php bin/magento indexer:show-mode