Skip to main content

Guidance for Product Substitutions on AWS

Provide instant product substitutions for out-of-stock items

Overview

This Guidance demonstrates how retailers can use Amazon OpenSearch Service, in combination with natural language processing, to create digital recommendations when needing to replace out-of-stock store products. Product names and descriptions are embedded and stored in a k-nearest neighbors (k-NN) index. When a consumer is querying for product recommendations, neighboring products are located within the k-NN index and returned to the consumer. The relevance of returned products can increase by using the optional category and price-based filters. 

How it works

These technical details feature an architecture diagram to illustrate how to effectively use this solution. The architecture diagram shows the key components and their interactions, providing an overview of the architecture's structure and functionality step-by-step.

Well-Architected Pillars

The architecture diagram above is an example of a Solution created with Well-Architected best practices in mind. To be fully Well-Architected, you should follow as many Well-Architected best practices as possible

Amazon CloudWatch, OpenSearch Dashboards, and Amazon SNS are all services used to enhance operational excellence throughout this Guidance. Consisting of serverless and managed services, the services output their own metrics to CloudWatch, where the state of the service can be monitored. OpenSearch Dashboards is also used to explore, inspect, and visualize data. Amazon SNS is used in collaboration with the monitoring services to provide notifications. These services help to run and scale your OpenSearch clusters, monitor the state of each service used in the architecture, and notify you of metrics and state changes that you define as important to your business. Amazon CloudWatch , OpenSearch Dashboards, and Amazon SNS are all services used to enhance operational excellence throughout this Guidance. Consisting of serverless and managed services, the services output their own metrics to CloudWatch , where the state of the service can be monitored. OpenSearch Dashboards is also used to explore, inspect, and visualize data. Amazon SNS is used in collaboration with the monitoring services to provide notifications. These services help to run and scale your OpenSearch clusters, monitor the state of each service used in the architecture, and notify you of metrics and state changes that you define as important to your business.

Cognito , Lambda , and AWS Identity and Access Management (IAM) are services deployed in this Guidance to enhance your security. IAM can be used to create fine-grained roles and policies to control who can manage and create your APIs, as well as control who can invoke them. 

To control access to your APIs, Cognito user pools or a Lambda authorizer can also be used for secure authentication and authorization. Cognito provides customizable secure authentication and authorization for users in your user pools. Lambda authorizers control access to your APIs using bearer token authentication, as well as information described by headers, paths, query strings, stage variables, or context variable request parameters.

Read the Security whitepaper 

Lambda , OpenSearch Dashboards, and API Gateway were used throughout this Guidance to enhance reliability. Lambda is used for serverless compute and is designed to provide managed scaling. As traffic increases, Lambda increases the number of concurrent processes of your functions. OpenSearch Dashboards allows you to monitor and visualize your OpenSearch data for better insight into the performance of your cluster. API Gateway uses throttling to prevent your APIs from being overwhelmed. You can configure custom throttling for your APIs to set a limit on steady-state rate and a burst of requests against your APIs. Through monitoring and built-in scaling capabilities, these services help to provide a reliable architecture to ensure consistent performance for your product substitution application.

Read the Reliability whitepaper 

This Guidance deploys Lambda to enhance performance efficiency. It is used as serverless compute to load seed data into DynamoDB , embed, and index data for OpenSearch , as well as query product substitution requests to OpenSearch . Lambda can be set up to operate based on trigger functions to automate the flow of data through the architecture. Leveraging Lambda for serverless compute improves performance for loading data and querying data within the architecture. 

Read the Performance Efficiency whitepaper 

OpenSearch , Lambda , and Amazon S3 were deployed in this Guidance to optimize your costs. Amazon S3 is a low-cost storage option for product data. Lambda is a serverless compute service that runs your code without having to manage servers, and incurring costs while the code is running. And following OpenSearch best practices, such as using the latest generation instance types and node storage volumes, can help to reduce OpenSearch cluster costs. Reserved instances can also be used for your OpenSearch instances.

Amazon S3 lifecycle

policies, infrequently accessed data can be moved to lower-cost storage tiers to further optimize costs. Also, Lambda contributes to a lower cost architecture by allowing you to avoid paying for idle compute resources. Additionally, following OpenSearch best practices ensures you are optimizing compute instances and storage volumes for your cluster, so you are only paying for the resources necessary for your workload. Finally, using reserved instances provides a better price for your OpenSearch cluster. 
Using Amazon S3 lifecycle policies, infrequently accessed data can be moved to lower-cost storage tiers to further optimize costs. Also, Lambda contributes to a lower cost architecture by allowing you to avoid paying for idle compute resources. Additionally, following OpenSearch best practices ensures you are optimizing compute instances and storage volumes for your cluster, so you are only paying for the resources necessary for your workload. Finally, using reserved instances provides a better price for your OpenSearch cluster. 

Lambda , OpenSearch , and OpenSearch Dashboards were deployed throughout this Guidance to enhance sustainability. Lambda uses the minimum amount of hardware resources to run your code, then terminates the environment on completion. OpenSearch clusters can be optimized and monitored using OpenSearch Dashboards. Finally, with Lambda and OpenSearch , using the minimum number of resources also reduces the amount of energy needed to operate the workload, contributing to greater sustainability efforts.

Read the Sustainability whitepaper 

Deploy with confidence

Ready to deploy? Review the sample code on GitHub for detailed deployment instructions to deploy as-is or customize to fit your needs. 

Go to sample code

Disclaimer

The sample code; software libraries; command line tools; proofs of concept; templates; or other related technology (including any of the foregoing that are provided by our personnel) is provided to you as AWS Content under the AWS Customer Agreement, or the relevant written agreement between you and AWS (whichever applies). You should not use this AWS Content in your production accounts, or on production or other critical data. You are responsible for testing, securing, and optimizing the AWS Content, such as sample code, as appropriate for production grade use based on your specific quality control practices and standards. Deploying AWS Content may incur AWS charges for creating or using AWS chargeable resources, such as running Amazon EC2 instances or using Amazon S3 storage.