Solution ideas
This article is a solution idea. If you'd like us to expand the content with more information, such as potential use cases, alternative services, implementation considerations, or pricing guidance, let us know by providing GitHub feedback.
This article presents a solution for generating personalized recommendations for customers in real time. Core solution components include Azure Cosmos DB and its change feed and Azure Databricks.
ApacheĀ® and Apache Spark are either registered trademarks or trademarks of the Apache Software Foundation in the United States and/or other countries. No endorsement by The Apache Software Foundation is implied by the use of these marks.
Architecture
Download a Visio file of this architecture.
Dataflow
- A shopper signs in to an e-commerce app by using their own credentials.
- The shopper places an order, and the order goes to an API app.
- Data from the customer order is stored in Azure Cosmos DB.
- The change feed is enabled on Azure Cosmos DB and processes all the changes for available events.
- Apache Spark on Azure Databricks is used to train and store product and user vector data in Azure Cosmos DB.
- The e-commerce app uses a recommendation API in Azure Container Service to retrieve the latest recommendation for the shopper.
Components
The Web Apps feature of Azure App Service is an HTTP-based service for hosting web applications, REST APIs, and mobile back ends. With Web Apps, you can develop in your favorite language, be it .NET, Java, Ruby, Node.js, PHP, or Python. Applications run and scale with ease on both Windows and Linux-based environments.
The API Apps feature of App Service is used to build and consume cloud APIs. App Service provides cross-origin resource sharing (CORS) support for RESTful APIs. API Apps simplifies mobile app scenarios by enabling authentication, offline data sync, and push notifications.
Azure Cosmos DB is a multiple-model database that can serve data elastically at a massive scale. Azure Cosmos DB was designed for applications that are globally distributed in a multi-write model. The Azure Cosmos DB change feed provides a persistent record of changes to a container while maintaining the order that the changes occur in.
Azure Container Instances runs containers on demand in a serverless Azure environment. Container Instances is a low-friction method of running containers that doesn't require a full Docker host or Kubernetes installation.
Azure Kubernetes Service (AKS) automates deployment, scaling, and management of containerized applications, such as recommendation models.
Azure Databricks is a data analytics platform optimized for the Azure cloud services platform. Azure Databricks offers various environments for developing data-intensive applications: Databricks Data Science & Engineering, Databricks Machine Learning, and Databricks SQL.
Alternatives
Like Azure Databricks, Azure Synapse Analytics also provides native Apache Spark capabilities. As an alternative option for the development and training of a recommendation model, consider Azure Synapse Analytics.
Scenario details
This solution uses Azure Cosmos DB to store data from customer orders. The Azure Cosmos DB change feed reacts to each order by triggering a process to generate recommendations. Apache Spark on Azure Databricks is used to train a machine learning model that recommends products based on customer data.
Azure Cosmos DB also stores the product and user vectors that the machine learning models use. Azure Cosmos DB offers five levels of consistency. You can adjust the consistency level to lower latency. Fast response times make it possible for the e-commerce site to make immediate recommendations to customers.
Potential use cases
This solution is ideal for the retail industry. It applies to scenarios where organizations use customer shopping history to provide relevant product recommendations.
Considerations
These considerations implement the pillars of the Azure Well-Architected Framework, which is a set of guiding tenets that can be used to improve the quality of a workload. For more information, see Microsoft Azure Well-Architected Framework.
The solution uses Azure API Management in front of the container service. API Management provides many benefits such as rate throttling, API versioning, and policies. For more information, see Azure API Management.
Performance efficiency
Performance efficiency is the ability of your workload to scale to meet the demands placed on it by users in an efficient manner. For more information, see Performance efficiency pillar overview.
In Azure Cosmos DB, you can configure either standard (manual) or autoscale-provisioned throughput on your databases and containers. When you use autoscale-provisioned throughput, you can scale the throughput of your database or container automatically and instantly. Azure Cosmos DB measures throughput in request units (RUs). The throughput is scaled based on the usage, without affecting the availability, latency, throughput, or performance of the workload.
Scale the AKS cluster to meet your performance and throughput requirements. Take care to scale up the number of pods to fully utilize the cluster, and to scale the nodes of the cluster to meet the demand of your service.
Next steps
- Use Apache Spark in Azure Databricks
- Train a machine learning model with Azure Databricks
- Common Azure Cosmos DB use cases
- App Service overview
- Welcome to Azure Cosmos DB
- Change feed in Azure Cosmos DB
- What is Azure Container Instances?
- Azure Kubernetes Service (AKS)
- Azure Databricks documentation