1. Home
  2. The Data Engineering Show - Podcast

Sep 17, 2025

Why Instacart replaced Elasticsearch with PostgreSQL

Ankit Mittal

25 min → 1:42

Overview

Former Instacart Senior Engineer Ankit Mittal explains how the company migrated its product search architecture from Elasticsearch to a customized PostgreSQL cluster to simplify applications and reduce network latency.

3 things to know

Instacart turned one Postgres cluster into a search engine

Instacart extended PostgreSQL to work as a search engine by combining search indexes, ranking tables, availability data, and product taxonomies inside a single self-hosted cluster.

More

This was achieved by consolidating search indexes, ranking tables, availability data, and product taxonomies into a single, self-hosted cluster.

▶ Watch at 17:21

Mittal: Moving search logic into Postgres simplified the app

Ankit Mittal explains that Instacart moved complex filtering and ranking logic from the application layer into the PostgreSQL database to make the applications simpler.

More

This simplified the application, reduced network round-trips, and leveraged the database's transactional capabilities.

▶ Watch at 2:27

Custom C code handled personal search ranking in Postgres

Before pg_vector was available, the database architecture relied on a custom C extension in PostgreSQL for dot product calculations to handle personalized ranking models directly inside the database.

▶ Watch at 22:11

Also in this episode

Mittal says Instacart loaded bulk search data from S3

Ankit Mittal clarifies that Instacart ingested data in bulk from S3, loading temporary tables before building and hot-swapping an optimized primary table with minimal disruption.

More

The system would then use tools like `pg_repack` to build a new, optimized, and clustered primary table, which was then "hot-swapped" to serve live traffic with minimal disruption.

▶ Watch at 0:00

Instacart mixed text search with live inventory filtering

Instacart's search system combined traditional text search with complex, real-time filtering and personal ranking driven by fast-changing data like inventory and user preferences.

Quotes

“If there's a lot of things that you can get the database to do, then the applications become simpler.”

▶ Watch at 2:27

“Eventually what we found out was that the DevEx, the developer experience, and how engineers use it, especially search engineers, it was less than ideal.”

▶ Watch at 22:11

“Almost everything that we got retrieved had to be filtered out.”

▶ Watch at 0:00

1 more quote

“All the rights are pipelined. We don't use Kafka. We, uh, the interface is, is S3.”

▶ Watch at 17:21

Full summary

Episode Overview

  • Ankit Mittal, former Senior Engineer at Instacart, discusses the evolution of their product search architecture.
  • The episode details the migration from a standard Elasticsearch setup to a highly customized PostgreSQL cluster for handling search queries.
  • Key architectural principles are explored, such as pushing compute down to the data layer to simplify applications and reduce network latency.
  • Ankit breaks down the technical trade-offs, the data ingestion pipeline, and the specific PostgreSQL extensions that made this unique architecture possible.

Key Concepts

  • Hybrid Search Retrieval: Instacart's search system combined traditional text search with complex, real-time filtering and personalized ranking based on rapidly changing data like inventory and user preferences.
  • Pushing Compute to the Data Layer: The core strategy was to move complex logic (filtering, ranking, joins) from the application layer into PostgreSQL. This simplified the application, reduced network round-trips, and leveraged the database's transactional capabilities.
  • PostgreSQL as a Search Engine: Instacart extended PostgreSQL to function as a search engine. This was achieved by consolidating search indexes, ranking tables, availability data, and product taxonomies into a single, self-hosted cluster.
  • Data Ingestion and Hot-Swapping: Data was ingested in bulk from S3 into temporary tables. The system would then use tools like pg_repack to build a new, optimized, and clustered primary table, which was then "hot-swapped" to serve live traffic with minimal disruption.
  • PostgreSQL Extensions: The architecture relied heavily on PostgreSQL extensions, including a custom C extension for dot product calculations (before pg_vector was available) to handle personalized ranking models directly within the database.

Quotes

  • At 0:00 - "Almost everything that we got retrieved had to be filtered out." - Ankit describes the initial problem where the search retrieval was too broad, forcing the application to do heavy filtering, which was inefficient and led to multiple network calls.
  • At 2:27 - "If there's a lot of things that you can get the database to do, then the applications become simpler." - Ankit explains the core principle behind their decision to move complex filtering and ranking logic from the application layer into the PostgreSQL database.
  • At 17:21 - "All the rights are pipelined. We don't use Kafka. We, uh, the interface is, is S3." - Ankit clarifies that their data pipeline for updating the search cluster was a bulk-write process originating from S3, rather than a real-time streaming approach.
  • At 22:11 - "Eventually what we found out was that the DevEx, the developer experience, and how engineers use it, especially search engineers, it was less than ideal." - Ankit discusses a major trade-off of their custom PostgreSQL solution: it was operationally efficient but difficult for search engineers, who were more accustomed to Elasticsearch's query DSL, to work with.

Takeaways

  • Leverage the database to simplify your application. By pushing complex filtering, joining, and ranking logic into the database, you can reduce application complexity, minimize network latency from multiple data-fetching round trips, and improve overall system performance.
  • PostgreSQL can be a viable alternative to specialized search engines. For use cases that require both text search and complex, real-time transactional logic (like inventory checks or personalized filtering), a customized PostgreSQL setup with extensions can outperform a separate search system by avoiding data synchronization issues and enabling powerful single-query operations.
  • Balance architectural innovation with developer experience (DevEx). While a custom solution might be technically optimal, consider the learning curve and productivity impact on your team. Moving from a widely-used tool with a familiar interface (like Elasticsearch) to a complex, bespoke system can create significant challenges for developers.

Watch the full episode 25 min

Read along with the audio summary

Ankit Mittal, a former Senior Engineer at Instacart, points out an early efficiency problem with their product search: almost everything retrieved had to be filtered out. In this episode from September 17, 2025, Ankit discusses the evolution of Instacart's product search architecture and their migration from a standard Elasticsearch setup to a customized PostgreSQL cluster. By the end, you will learn the principles, data pipelines, and trade-offs behind turning a database into a search engine.

Combining text search with real-time data solves the problem of broad, inefficient retrieval. When a search retrieval is too broad, it forces the application to do heavy filtering, which is inefficient and leads to multiple network calls. Instacart's search system addressed this through hybrid search retrieval. It combined traditional text search with complex, real-time filtering and personalized ranking, all based on rapidly changing data like inventory and user preferences.

To handle that heavy lifting efficiently, you can simplify your application by pushing compute down to the data layer. Ankit explains that if there are a lot of things you can get the database to do, then the applications become simpler. Instacart's core strategy was to move complex logic, such as filtering, ranking, and combining data through joins, out of the application layer and directly into their PostgreSQL database. This reduced network round trips and made use of the database's transactional capabilities. You can push complex filtering, joining, and ranking logic into your database to reduce application complexity, minimize network latency from multiple data fetching round trips, and improve overall system performance.

Moving all that logic into the database meant extending PostgreSQL to function as a full search engine. Instead of relying on a separate search system that could cause data synchronization issues, Instacart consolidated everything into a single, self-hosted cluster. They brought search indexes, ranking tables, availability data, and product taxonomies together in one place. For use cases that require both text search and complex, real-time transactional logic like inventory checks or personalized filtering, you can use a customized PostgreSQL setup to outperform a separate search system and enable single-query operations.

Keeping that consolidated cluster updated without interrupting shoppers required a bulk data ingestion and hot-swapping strategy. Rather than using a real-time streaming approach like Kafka, Ankit notes that all the writes were pipelined using S3, a cloud storage system, as the interface. Data was ingested in bulk from S3 into temporary tables, and the system used tools like pg_repack to build a new, optimized, and clustered primary table. That new table was then hot-swapped in, replacing the active table on the fly to serve live traffic with minimal disruption.

Making personalized ranking work directly inside the database relied heavily on PostgreSQL extensions, which are add-ons that give the database new capabilities. Before the pg_vector extension was available, Instacart built a custom C extension to run dot product calculations, a type of math used to score and rank items. This allowed them to handle personalized ranking models right inside the database.

Pushing complex logic into a customized PostgreSQL cluster can simplify your application and improve performance, though moving away from familiar tools like Elasticsearch can create a steep learning curve and impact team productivity. Eventually what we found out was that the DevEx, the developer experience, and how engineers use it, especially search engineers, it was less than ideal.

More from The Data Engineering Show - Podcast

Related Episodes