{'fraction_non_alphanumeric': 0.03471532388769802, 'fraction_numerical': 0.003502901657343023, 'mean_word_length': 4.635827931644077, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
A Real-Time Whole Page Personalization Framework for E-Commerce

E-commerce platforms consistently aim to provide personalized recommendations to drive user engagement, enhance overall user experience, and improve business metrics. Most e-commerce platforms contain multiple carousels on their homepage, each attempting to capture different facets of the shopping experience. Given varied user preferences, optimizing the placement of these carousels is critical for improved user satisfaction. Furthermore, items within a carousel may change dynamically based on sequential user actions, thus necessitating online ranking of carousels. In this work, we present a scalable end-to-end production system to optimally rank item-carousels in real-time on the Walmart online grocery homepage. The proposed system utilizes a novel model that captures the user's affinity for different carousels and their likelihood to interact with previously unseen items. Our system is flexible in design and is easily extendable to settings where page components need to be ranked. We provide the system architecture consisting of a model development phase and an online inference framework. To ensure low-latency, various optimizations across these stages are implemented. We conducted extensive online evaluations to benchmark against the prior experience. In production, our system resulted in an improvement in item discovery, an increase in online engagement, and a significant lift on add-to-carts (ATCs) per visitor on the homepage.


I. INTRODUCTION
Modern e-commerce companies provide personalized user experiences through their homepages. They provide a curated assortment of various heterogeneous components (text, hyperlinks, images, videos, advertisements, etc.), each potentially optimizing for different business metrics. To determine the optimal page layout, numerous eye-tracking studies have been conducted to analyze user behavior as they browse webpages. These studies show a clear positional bias i.e., a user is more likely to browse the top and left parts of a webpage [1], [2]. An e-commerce system that dynamically positions carousels based on user behavior and context is more likely to engage and retain users rather than a static layout [3].
Dynamically re-ranking carousels to personalize page layout requires that the system be highly scalable and efficiently incorporate real-time feedback signals, such as user-item interactions and user-carousel interactions. Apart from scalability of the system, layout personalization requires two important considerations. First, there are multiple user-personalized carousels which may individually have their own objectives. These objectives may range from encouraging users to discover previously unseen items to assisting users re-order items easily based on their purchase patterns. This may lead to optimizing the page layout over different, and potentially competing, axes. In our use case, due to business constraints, individual objectives of the carousel need to be honored by preserving the initial ordering of items within the carousel. Second, since a layout optimization system has dependencies upon various upstream item carousel models, some of which may only be inferred at real-time, it is necessary for the layout optimization system to be able to perform carousel ranking inference in an online fashion at low latency. Given these considerations, it makes this layout optimization system uniquely challenging to design.
In this work, we present a production system that optimizes the ranking of carousels for the Walmart online grocery homepage 1 . Our contributions can be summarized as follows: • We introduce an end-to-end scalable production system which provides personalized ranking of carousels for millions of users in real-time. • We present an offline training and online inference framework that relies on real-time user feedback signals and provides the optimal carousel ranking at low-latency. • We formulate a model to facilitate re-purchase of items and promote discovery of new items based on users' interests, which can be easily extensible to similar settings.

II. RELATED WORK
Fragmentation of web pages into heterogeneous components provide a platform for rendering different designs based on user preferences [4], [5]. There has been significant work in page layout optimization for web search engines [6]- [8]. For instance, [9] proposes a framework for whole page personalization by utilizing content and presentation features to train an ensemble of Quadratic Feature Model and Gradient Boosted Decision Tree Model (GBDT) to predict page-wise user response. The user's interactions with a page can also be modeled as a Markov chain which can be inferred using click logs for optimizing search results presentation [10].
Component-based ranking systems have also been deployed for optimizing constrained objectives from multiple stakeholders for video recommendations [11] and social networks [12]. Multi-objective optimization problems in personalized click shaping has also been tackled utilizing a Lagrangian duality formulation [13]. Contextual Bandits provide a natural framework that learns from user behaviour. It learns over time to maintain the required balanced between helping user reorder items (i.e. exploitation) and promoting new items of interest (exploration). It has shown great promise in areas of news article recommendation and ads recommendation [14]- [16]. This framework however, requires a learning phase in which sub-optimal orderings may be shown which may not be appropriate in some business problems. To the best of our knowledge, our work is the first to present an end-to-end system for dynamic ranking of carousels in the online grocery domain.

III. PROBLEM STATEMENT
Consider a set of users U and a set of N personalized carousels for a user u ∈ U as M u = {m uk | k ∈ {1, 2, ..., N }}, where k acts as an identifier for a carousel m uk . Let Z(≤ N ) denote the number of zones where each zone serves as a placement for carousels on the webpage. Each carousel is defined as an immutable ordered list of M items from a global set of items I. Let π u (i) represent the carousel assigned to zone i for user u and Π Z u denote the set of all possible assignments of carousels to zones, such that π u ∈ Π Z u is an injective function π u : {1, 2, ..., Z} → M u . Consider a scoring function F : Π Z u → R that scores every assignment π u , then the objective is to find π u that maximizes F(π u ), without altering the ordering of items within a carousel.
Since Π Z u is an exponentially large space, a score-and-sort approach is used. Let M = {(u, m uk ) | u ∈ U ∧ m uk ∈ M u } denote the set of all possible user-carousel pairs. Given a pointwise scoring function φ : M → R that maps every carousel for a user to a score, selecting top Z carousels according to φ produces a valid assignment for the carousels. In real-world scenarios, scoring functions such as φ are modeled to reflect business requirements.

IV. MODEL
A. Outline In our system, φ(u, k) (shorthand for φ(u, m uk )) is modeled as a linear combination of α uk and γ uk , which captures the user's affinity to a carousel and the user's propensity to discover new items respectively, as described in (1). Since only the relative ranking of carousels is needed, φ(u, k) can be reduced to a convex combination with weight w ∈ [0, 1].
Further, we have various constraints applied on this optimization problem based on specific business needs. For example, the system might need to consider carousel-specific capacity constraints while assigning carousels to zones on the page. Based on these business requirements, the weight w can be trained. Since our production system serves millions of users, we use a scalable collaborative filtering based matrix factorization (MF) [17] approach to model α uk and γ uk . Depending on use case, this can be replaced by any generic user-item embedding framework, such as NCF [18] and LightGCN [19].

B. User-Carousel Affinity
Given a carousel m uk consisting of an immutable ordered , the probability that a user u will interact with an item i uk l is denoted by P (i uk l , m uk |u). For each user-carousel pair (u, m uk ), the usercarousel affinity score α uk is assumed to be proportional to the sum of these probabilities weighted by ω l , as given by: where P (m uk |u) is the prior probability of the user interacting with a carousel and P (i uk l |u, m uk ) is the probability that the user will purchase an item i uk l in the carousel. 1) User-Carousel Prior: The prior probability of a user interacting with a given carousel P (m uk |u) is modeled as a beta distribution with parameters a uk and b uk , using historical user interaction data. The expected value of this beta distribution is used to estimate the prior probability, denoted by λ uk , as follows: The user-item interaction events are captured on the ecommerce platform as (u, m uk , e, t), where t is the event timestamp and e ∈ E = {view, click, AT C}, E being the set of all possible user-carousel interaction events. A event is marked as "view", "click", or "ATC" if any of the items in the carousel is viewed, clicked, or added to cart, respectively, by the user in a session.
Since model inference is performed online, fast and timely updates of user-carousel priors are required to capture the most recent user behaviour. Using a beta distribution to model the prior probability provides the advantage of quick online updates, since the posterior distribution is also a beta distribution with parametersâ uk ,b uk given by: 2) User-Item Affinity: Given a user-item transaction matrix, we train an MF model to learn user and item embeddings and obtain user-item affinity scoresr ui : U × I → R asr ui = x T u y i . Sincer ui captures a user's affinity towards a particular item and given that item i uk l exists in a carousel m uk , we can user ui uk l as a representative score for P (i uk l |u, m uk ), thereby P (i uk l |u, m uk ) ∝r ui uk l . Given λ uk = P (m uk |u) and using (2) we get: To capture horizontal position bias observed while browsing webpages [20], the weights ω l in (5) are modeled using a logarithmic reduction factor. Without loss of generality, a unit constant of proportionality can be assumed, as we are only concerned with the relative scoring when ranking carousels, thus reducing (5) to:

C. User-Carousel Discovery
In this section, we develop a model to promote discovery of items by assigning a discovery score γ uk to each user-carousel pair. All items in the catalog are divided into a set of categories C, defined by a many-to-one function ψ : I → C. The user-category transaction matrix is denser than the user-item transaction matrix, therefore modeling user-category score better captures affinity towards categories the user has not purchased from before. We train an MF model on usercategory transaction data to obtain the user-category affinity scoresŝ uc : U × C → R.
For a given user u and category c ∈ C, the user-category discovery score is defined by a function g(u, c) ofŝ uc and η uc , where η uc is the number of times user u has purchased items from category c over a period of time. The more purchases from a category, the higher the chance that a user has explored that category. Hence, to ensure higher scores for unexplored categories, g(u, c) is modeled as g(u, c) =ŝ uc e −ηuc .
For a user u and carousel m uk = [i uk 1 , i uk 2 , ..., i uk l , ..., i uk M ], where item i uk l is in category ψ(i uk l ), using a similar logarithmic reduction factor for the ordering as described in Section IV-B, the user-carousel discovery score γ uk can be computed as: In the next section, we describe the end-to-end system architecture, which combines the user-carousel affinity α uk and discovery scores γ uk to generate carousel ranking in realtime using (1).

V. SYSTEM ARCHITECTURE
We provide an overview of our production system which comprises of three core components: Model Development, Model Store and Deployment, and Online Inference with Feedback Loop, as illustrated in Figure 1.

A. Model Development
In this section, we explain the components required to develop the user-item and user discovery models. Given the large scale of the Walmart consumer base, we use a high performance Kafka-based distributed event streaming job to store the user-item interaction data in a Hadoop-based distributed data store (HDFS). This HDFS data store serves as the primary central storage and also hosts the item catalog metadata for all items sold on the Walmart online grocery ecommerce platform. After data validation, Beeline and Pyspark workflows are used for feature extraction and subsequent model training on an extensive network of nodes in our distributed computation framework. The extracted user-item transaction features (u, i, η ui ) and user-category transaction features (u, c, η uc ) are stored in the feature store for model ingestion where η ui and η uc denote the number of transactions for a user-item and user-category pairs respectively.
Using these features, the user-item model (Section IV-B) and user-discovery model (Section IV-C) are trained. For our use case, we employ transaction data from the past year and obtain 32-dimensional user and item embedding vectors. These learned representations are stored in an embedding store for online inference. The user-category discovery scores g(u, c) are computed and stored in a distributed memory cache. After model training, the model validation phase oversees the outputs of these models and checks for anomalies. Before serving online traffic, using the candidate carousel models with the trained models, the final ranking of carousels of the proposed system is also validated for a subset of users.
A workflow management platform, Apache Airflow, is used to orchestrate the pipeline stages described above. It enables event-based scheduling and monitoring of complex workflows, along with providing a centralized log monitoring and an alerting system.

B. Model Store and Deployment
This module consists of a model store, continuous integration (CI) tool, Docker registry, and Jenkins deployment engine. The model store is based on a version control system and serves as a repository of models. When a model is pushed to the model store, a build is triggered by a proprietary CI tool, which then executes automated unit tests, integration tests, and additional checks for model validation. In case of a successful build, a Docker image of the model is generated, pushed to the Docker registry, and packaged as a Docker container. A Jenkins deployment engine then deploys the containerized application to the target production environment, which runs TensorFlow Serving (TF Serving).

C. Online Inference with Feedback Loop
The online inference system consists of a closed-loop architecture that utilizes real-time user feedback, along with pretrained model outputs, to dynamically compute the optimal ranking of carousels for each user. The user interacts with the front-end client of the Walmart online grocery homepage through web and mobile interfaces. Two fault-tolerant spark streaming jobs listen to a Kafka stream of user interaction event. One job stores user interactions in the data store as described in Section V-A, while the other job periodically updates the user-carousel priors, as per (4). The updated user-carousel priors are stored in a distributed memory cache (Memcached) for high-performance, low-latency, and realtime retrieval.
When a user visits the homepage, a call is made to the inference-wrapper API to retrieve the optimal ranking of carousels to be displayed. Then, the inference-wrapper API calls TF Serving, where inference is performed for all candidate carousels. TF Serving allows for a unified framework to serve and version these multiple candidate carousel models, while keeping the same server architecture and APIs. Once the candidate carousels are obtained from TF Serving, the inference-wrapper API fetches the required data (x u , y i , λ uk , g(u, c)) for the carousel ranking computation. The embedding store provides the user embedding x u and the item embeddings y i for only those items which are part of any of the candidate carousels. In parallel, the updated user-carousel priors λ uk for all candidate carousels m uk of a user, and user-category discovery scores g(u, c) for all categories c, are obtained from the distributed memory cache. This retrieved data is then passed to TF Serving to compute the user-carousel scores, as described in Section IV, according to the following equation: g(u, ψ(i uk l )) log(1 + l) (8) Using the computed user-carousel scores, the optimal ranking of the candidate carousels is generated by TF Serving and returned to the front-end client to be displayed to the user. Our system combines the benefits of a model training infrastructure, a model deployment framework, and an online inference setup, providing a personalized ranking of carousels to millions of users in real-time at low latency.

VI. RESULTS
We conducted a large scale online A/B test on a random sample of users on the Walmart online grocery homepage. In our experimental setup, a pool of 10 carousels were ranked in 10 zones of the homepage. The control group was provided a static ordering of carousels which was based on historical performance of carousels aggregated across all users. On the other hand, the treatment group was presented a dynamic carousel ranking generated by our proposed framework. We observed a lift of 17.79% ATC per visitor on the homepage, validating the efficacy of our personalized carousel ranking system. We also noted an increase of 0.78% in item page visits, indicating that our system promotes discovery of previously unseen items. The increased user engagement and item discovery resulted in an overall lift of 0.07% in all online orders. Our proposed framework thus significantly outperforms the previous system, with an additional latency of only 1.29ms derived from the real-time carousel ranking computations in the TF Serving layer.

VII. CONCLUSION
In this work, we present a large-scale production system to personalize the ordering of carousels on the Walmart online grocery homepage. Our system incorporates real-time feedback signals, considers positional biases, and dynamically updates carousel ordering at low latency. We infer user behaviour through the use of an online feedback loop by tracking user interests and updating user-carousel priors in real-time. Our ranking model is modular in design and can be easily extended to other carousel ranking applications. Online experiment results show that our system achieves a significant improvement in user interaction metrics as well as business metrics. The flexible design of our system allows for easy incorporation of additional real-time contextual signals to further improve the system performance. Extending to a contextual multi-armed bandit framework using Thompson sampling on the prior beta distribution is another avenue for exploration.