This approach is deprecated. For new implementations, use Smart Groups with external sources instead.Smart Groups offer:
- Built-in deduplication. Algolia automatically removes duplicates between sponsored and organic results.
- Simplified implementation. Less custom merge logic required on your backend.
- Flexible placement. Control exact positions for sponsored items.
- Optional re-ranking. Apply Algolia’s relevance ranking to sponsored products.
How the parallel requests strategy works
- A user submits a search (for example, “running shoes”).
- Your app makes two requests in parallel: one to Algolia to get the regular search results and one to the RMP to get sponsored product results.
- The backend waits for both responses and then combines the results.
- The combined list of regular and sponsored results is sent to the frontend for display.
Requirements
To effectively implement the parallel requests strategy, you need:- Full RMP product data. The RMP’s API must provide all the necessary product data for display. This may include a unique product identifier (ideally one that aligns with your Algolia
objectID), product name, image URL, price, and stock status. - Up-to-date product information. The RMP’s product information must align with your product catalog. Discrepancies in attributes like price or stock levels between the RMP data and your Algolia index can lead to inconsistencies on the frontend, negatively affecting the user experience. Regular synchronization between the RMP and your product catalog is crucial.
- Backend data merging capability. Your backend or integration layer must be capable of making two asynchronous API requests (one to Algolia and one to the RMP) and efficiently merging the resulting datasets. This typically involves a server-side component or cloud function to orchestrate the API calls and process the responses.
- Duplicate handling. It’s common for sponsored products to also appear in the Algolia search results, if they’re a good match for the user’s query. Your data merging logic must identify and remove duplicate entries, ensuring that sponsored products appear only once in the blended results.
Pros
- Fastest response time. Compared to the other strategies, calling both requests in parallel improves performance. The slower of the two API calls dictates search time, rather than the combined duration.
- Direct use of RMP data. If the RMP provides complete product information, there’s no need to call Algolia to fetch details for the sponsored items. You can also display sponsored products that aren’t in an Algolia index.
Cons
- Impact on result counts. Since sponsored results aren’t part of the Algolia query, Algolia’s total results count (
nbHits) and facet filter counts don’t include these sponsored items. This can lead to a discrepancy between the number of results reported by Algolia and the total number of products displayed. You can mitigate this by using “fuzzy” ranges (10+, 100+) in the UI to reduce user perceptions of inconsistency.
Example
JavaScript
How the code works
- Trigger parallel API calls. Uses server-side code to simultaneously call the Algolia search and the RMP fetch. The Algolia search queries the primary index (with relevant filters applied). This search returns an array of product objects, stored in
algoliaHits. Simultaneously, thefetchRetailMediaWithTimeoutfunction calls the RMP’s API. - Apply a timeout to the RMP request.
fetchRetailMediaWithTimeoutensures you don’t wait longer thanRETAIL_MEDIA_TIMEOUT_MSfor the RMP response. This search stores its results inretailMediaHits. If the request times out or there are no results,retailMediaHitsis empty. - Merge results and remove duplicates. Once both responses are back (or the RMP call times out), the
injectSponsoredProductsfunction mergesalgoliaHitsandretailMediaHits. It also removes any regular search results that are duplicates of sponsored products. - Return merged results. The frontend receives the merged list, where sponsored products are appropriately labeled.
Before your strategy goes live, ensure you’ve considered the regulatory requirements and the influence of sponsored results on your analytics, ranking, and UI.