Skip to main content
Back to Articles
MagentoNovember 15, 20246 min read

How to Enable Asynchronous Indexing in Magento 2 on Ubuntu -- Setting Up Beanstalk

Synchronous indexing is straightforward but can lock the database and slow your store during large catalog updates. This guide shows how to install Beanstalkd on Ubuntu, wire it into Magento 2 as a message queue, and enable schedule-based asynchronous indexing for better performance and scalability.

Why Asynchronous Indexing?

Magento 2 offers multiple indexing modes to keep catalog data fresh. Synchronous indexing is simple but blocks other operations; asynchronous indexing processes updates in the background, which is far better for large catalogs and high-traffic stores.

Key Benefits

  • Better performance: Index updates run in the background, reducing load on the live storefront and keeping the experience smooth during peak traffic.
  • Reduced downtime: Unlike synchronous indexing, background processing avoids database locks, so the store stays operational even during large updates.
  • Efficient resource usage: Distributing tasks over time prevents resource bottlenecks and maintains stable server performance.
  • Scalability: Handles extensive catalogs and frequent updates without degrading the live site -- ideal for growing businesses.
  • Improved customer experience: Uninterrupted functionality and faster response times increase shopper satisfaction.

When You Need It

  • Frequent catalog changes: Stores that constantly add products or update inventory benefit the most.
  • Large databases: Managing thousands or millions of SKUs demands a robust indexing strategy.
  • Concurrent operations: Asynchronous indexing allows order processing, catalog updates, and customer browsing to coexist without interference.

Step 1: Install and Configure Beanstalk

Beanstalkd is a simple, fast work queue that Magento 2 can use for asynchronous task processing.

sudo apt update && sudo apt upgrade -y
sudo apt install beanstalkd -y

Enable and start the service:

sudo systemctl enable beanstalkd
sudo systemctl start beanstalkd

Configure Beanstalk for persistent storage:

sudo nano /etc/default/beanstalkd

Update the following lines:

START=yes
OPTIONS="-l 127.0.0.1 -p 11300 -b /var/lib/beanstalkd -f 5 -z 1048576"

Save the file and restart the service:

sudo systemctl restart beanstalkd

Step 2: Install the Magento Asynchronous Operations Module

Magento needs the magento/module-asynchronous-operations package for background indexing:

composer require magento/module-asynchronous-operations
php bin/magento module:enable Magento_AsynchronousOperations
php bin/magento setup:upgrade
php bin/magento cache:clean

Step 3: Configure the Message Queue in Magento

Magento uses message queues to dispatch asynchronous tasks. Point it at your Beanstalkd instance:

sudo nano app/etc/env.php

Add the following under the queue key:

'queue' => [
  'amqp' => [
    'host' => '127.0.0.1',
    'port' => '11300',
    'user' => '',
    'password' => '',
    'virtualhost' => ''
  ]
],

Step 4: Enable Asynchronous Indexing

Switch all indexers to schedule mode:

php bin/magento indexer:set-mode schedule

Verify the indexer status:

php bin/magento indexer:status

Step 5: Test the Setup

Trigger an index update by adding a product or editing a category. Monitor queue activity by installing the Beanstalk Console:

composer require ptrofimov/beanstalk_console

Launch the console:

php -S 127.0.0.1:8000 vendor/ptrofimov/beanstalk_console/public/index.php

Visit http://127.0.0.1:8000 to inspect queue activity in real time.

Summary

Asynchronous indexing is a powerful capability that keeps your Magento 2 store fast and responsive, even as your catalog grows. By pairing Beanstalkd with Magento's message queue framework, background index processing becomes straightforward to set up and maintain.

For professional assistance with Magento performance tuning or server management, contact us at Private DevOps.

Need help with this?

Our team handles this kind of work daily. Let us take care of your infrastructure.