PinSage

PinSage is a graph convolutional neural network for web-scale recommendation, introduced by Rex Ying, Ruining He, Kaifeng Chen, Pong Eksombatchai, William L. Hamilton, and Jure Leskovec (Pinterest and Stanford) in their 2018 KDD paper “Graph Convolutional Neural Networks for Web-Scale Recommender Systems”. Deployed at Pinterest, PinSage operates on a graph of 3 billion nodes (representing pins and boards) and 18 billion edges, and was trained on 7.5 billion examples. The architectural innovation is random-walk-based localized convolutions: rather than computing graph convolutions over the full graph (which is impossible at this scale), PinSage samples a stochastic neighborhood around each node via biased random walks and applies graph convolutions over the sampled subgraph. This sampling-based approach makes graph neural networks tractable at industrial scale and produced the first widely-publicized successful deployment of graph CNNs in a major production recommender system. PinSage’s lineage descends from GraphSAGE (Hamilton, Ying, Leskovec, NeurIPS 2017), with adaptations for the recommendation setting and the engineering challenges of Pinterest’s scale.

1. The Pinterest Recommendation Setting

Pinterest’s content is pins (images with descriptions) organized into boards (user-curated collections). The recommendation task: given a user’s recent activity on pins and boards, recommend other pins they would likely save to their boards. The graph structure:

  • Pins and boards as nodes (Pinterest had 3 billion pins as of 2018).
  • An edge between a pin and a board if a user has saved the pin to that board.
  • 18 billion edges in total.

A standard graph neural network would compute, at each layer, a representation for every node based on its neighbors. At billion-node scale, this requires processing the entire graph in memory at every training step — infeasible.

PinSage’s contribution was to make graph CNNs work at this scale without compromising the architectural benefits.

2. Random-Walk-Based Localized Convolutions

The core idea: instead of computing each node’s representation from all its neighbors, sample a small important neighborhood via random walks and apply convolutions only over the sampled subgraph.

The procedure for computing a node’s embedding:

Step 1: Sample neighbors via random walks. Starting from the target node, perform several short random walks. The visit frequency of each visited node is recorded. The top-K most-visited nodes (by visit count) are selected as the importance-sampled neighborhood. This produces a small fixed-size neighborhood (typically K ≈ 50) per node, with the neighbors weighted by visit frequency.

Step 2: Apply graph convolution over the sampled neighborhood. A standard graph convolution aggregates the neighborhood’s features (using attention or weighted sum based on visit frequency) and combines them with the target node’s current features through a small neural network.

Step 3: Stack convolution layers. Multiple layers stack to capture higher-order graph structure. After K layers, each node’s embedding incorporates information from its K-hop random-walk neighborhood.

The random-walk sampling has two benefits beyond tractability:

  • Importance sampling: visit frequency biases the neighborhood toward structurally important nodes (those reachable from many paths), which carry more signal than rarely-visited nodes.
  • Localized computation: each node’s representation depends only on a small subgraph; training and inference are bounded in compute regardless of total graph size.

3. The Architecture

flowchart LR
  Target[Target node]
  Target --> Walks[Random walks from target]
  Walks --> Neigh[Top-K importance-sampled neighbors]
  Neigh --> Feat[Concatenate node features<br/>(visual, text, weighted by visits)]
  Feat --> GCN[Graph convolution<br/>(weighted aggregate + transform)]
  Target --> Self[Target's own features]
  Self --> GCN
  GCN --> Layer2[Stack of K layers]
  Layer2 --> Emb[Final node embedding]

What this diagram shows. For a target node, random walks produce a sampled neighborhood. The neighborhood’s features (each node’s visual embedding from a vision model and its text embedding) are aggregated, weighted by visit frequency. The aggregated neighborhood representation is combined with the target’s own features through a graph convolution operation (which is a small neural network with feature transformation and non-linear activation). Stacking K such layers captures K-hop graph structure. The key insight from this diagram is that the entire computation is localized — each node’s embedding depends only on its sampled neighborhood, not on the full graph. This makes the approach tractable at billion-node scale.

4. Engineering for Web-Scale Deployment

PinSage’s paper is unusually detailed about production engineering. Notable choices:

MapReduce-based inference. The graph is sharded across many machines; each machine computes embeddings for a partition of nodes. The MapReduce paradigm allows the entire 3-billion-node graph to be processed in batch.

Hard negative mining via random walks. During training, hard negatives are sampled via biased random walks that are likely to surface items semantically similar to the positive but not actually liked by the user. This is similar in spirit to WARP Loss’s active negative sampling.

Multi-task training. PinSage is trained jointly on multiple tasks (next-pin prediction, board membership prediction) which improves embedding quality.

Curriculum learning. Hard negatives are introduced progressively as training proceeds, easing the optimization.

The combination of algorithmic and engineering choices was what made PinSage actually work in production — the academic graph-CNN literature had not previously demonstrated billion-scale deployment.

5. Empirical Results

PinSage was deployed in Pinterest’s production recommender. The paper reports:

  • Substantially better offline metrics than the baseline non-graph recommender.
  • Better recommendations in user studies.
  • Positive A/B test results in production deployment.

The paper claims this was the largest deployment of deep graph embeddings to date (2018).

6. When to Use PinSage

PinSage is appropriate when:

  • You have a large bipartite or multi-partite recommendation graph.
  • The graph structure carries significant signal (multi-hop affinities matter).
  • You need to scale to billions of nodes.
  • You can afford the engineering investment for random-walk sampling, distributed inference, etc.

For smaller deployments, LightGCN is much simpler and gives competitive results without the engineering overhead.

7. Strengths

  • Production-proven at billion-node scale.
  • Random-walk sampling makes graph CNNs tractable.
  • Hard negative mining via the same random-walk infrastructure.
  • Combines content features with graph structure — node features (visual, text) are inputs to the graph convolution.

8. Weaknesses

  • Engineering complexity. Random-walk sampling, distributed inference, multi-task training — substantial production infrastructure.
  • Sampling introduces variance — different random walks for the same node give different neighborhoods.
  • Hyperparameter complexity — walk length, walk count, neighborhood size, layer count all matter.

9. See Also