This document describes a high-level architecture for using AI to generate personalized product recommendations for a retail application in Google Cloud.
The intended audience for this document includes architects, developers, and administrators who build and manage generative AI applications in the cloud for the retail industry. The document assumes that you have a foundational understanding of generative AI.
Architecture
The following diagram shows an architecture that uses an AI model to generate personalized product recommendations based on insights from clickstream metrics.
The architecture shows the following flows:
- Ingest and process user data:
- Clickstream data such as page views, clicks, and purchases are uploaded to a Dataflow pipeline.
- Dataflow processes the data and derives insights such as user profiles and preferences. Dataflow then stores the data, insights, and vector embeddings in BigQuery.
- Generate and serve product recommendations:
- A customer visits the company's storefront, which is a Cloud Run service in this architecture.
- The storefront service sends the visitor's data to a recommender service that runs on Cloud Run.
- The recommender service performs a vector similarity search in BigQuery and retrieves data about the visitor's profile and preferences.
- The recommender service sends the visitor's profile and preferences data to Gemini Enterprise Agent Platform, with a prompt to generate product recommendations. On Agent Platform, a Gemini model generates product recommendations that are tailored for the visitor.
- The recommender service sends the product recommendations to the storefront service, which then displays the recommendations.
To optimize cost and performance, add a cache between the storefront service and the recommender service. The recommender service checks the cache for visitor data. If the cache doesn't contain relevant data, the service performs a vector similarity search in BigQuery. To set up the cache, you can use Memorystore or configure a load balancer with Cloud CDN.
Products used
This example architecture uses the following Google Cloud products:
- Cloud Run: A serverless compute platform that lets you run containers directly on top of Google's scalable infrastructure.
- Gemini Enterprise Agent Platform: A comprehensive platform that lets you build, scale, govern, and optimize enterprise‑grade AI agents.
- BigQuery: An enterprise data warehouse that helps you manage and analyze your data with built-in features like machine learning, geospatial analysis, and business intelligence.
- Dataflow: A service that provides unified stream and batch data processing at scale.
Design considerations
This section describes design factors, best practices, and recommendations in alignment with the Google Cloud Well-Architected Framework. Consider this information when you use this reference architecture to develop a topology that meets your specific requirements for security, reliability, cost optimization, operational efficiency, and performance.
Security, privacy, and compliance
To help protect customer data and meet your security, privacy, and compliance requirements in Google Cloud, consider the following recommendations:
- To screen prompts and recommendation responses for prompt injection, jailbreak attempts, and harmful content, use Model Armor.
- To inspect and de-identify personally identifiable information (PII) in clickstream data, user profiles, and prompts, use Sensitive Data Protection.
Reliability
To buffer bursty clickstream traffic and decouple storefront event producers from your Dataflow pipeline, ingest user events through Pub/Sub. Buffering events in Pub/Sub helps prevent data loss during traffic spikes or pipeline updates.
Cost optimization
To reduce input token costs when prompts share repeated system instructions or product catalog context, use context caching on Agent Platform.
Operational efficiency
To reduce operational overhead when you build and maintain your recommendation pipeline in Google Cloud, consider the following options:
- If you prefer a managed retail recommendation service over a custom pipeline, consider AI Commerce Search in Gemini Enterprise for Customer Experience. AI Commerce Search trains and serves personalized recommendation models directly from your product catalog and clickstream events.
- To automatically generate and refresh embeddings in BigQuery when source data changes, use autonomous embedding generation.
Performance optimization
To help meet low-latency serving requirements for storefront visitors in Google Cloud, consider the following recommendations:
- To accelerate similarity queries over large tables in BigQuery, create a vector index for approximate nearest neighbor (ANN) search.
- For low-latency online similarity serving under high storefront concurrency, consider Vector Search.
- When you deploy Memorystore for caching, use Memorystore for Valkey or Memorystore for Redis Cluster instead of the deprecated Memcached engine. To serve semantic queries at sub-millisecond latency, you can also use vector search in Memorystore for Valkey.
Deployment
To experiment with generative AI applications in Google Cloud for retail workloads, use the following code samples:
What's next
- Explore more generative AI architecture guides.
- For an overview of architectural principles and recommendations that are specific to AI and ML workloads in Google Cloud, see the AI and ML perspective in the Well-Architected Framework.
- For more reference architectures, diagrams, and best practices, explore the Cloud Architecture Center.
Contributors
Author: Kumar Dhanagopal | Cross-Product Solution Developer
Other contributors:
- Amina Mansour | Tech Lead, Global Developer Relations & Strategic Content
- Megan O'Keefe | Developer Advocate
- Samantha He | Technical Writer
- Shir Meir Lador | Developer Relations Engineering Manager