ML Systems Lab Open interactive version →
Advanced 65 min read PinSagePinterestfraud detectiondrug discoverydynamic graphs

GNNs in Production at Scale

PinSage, fraud detection, drug discovery, dynamic graphs, feature engineering, real-time inference

A drug molecule has atoms as nodes and bonds as edges. A protein has residues as nodes and spatial contacts as edges. You want to predict whether the drug binds to the protein — a graph-graph matching problem. Hand-crafted features (molecular fingerprints, protein descriptors) have been used for this task for decades. But the features must be designed by domain experts, they are fixed at design time, and they discard structural information that doesn't fit the feature schema. GNNs learn task-specific representations directly from the molecular graph, capturing the geometric and chemical compatibility between drug and protein that hand-crafted features miss.

This is the general pattern for GNN applications: wherever entities have structure (molecules, proteins, social networks, knowledge graphs, circuit layouts) and tasks depend on that structure, GNNs outperform feature-engineering approaches by learning the relevant structural representation end-to-end.

Moving a GNN from an academic benchmark to production exposes problems that benchmark papers omit: graphs with billions of edges, millisecond latency requirements, continuous updates that invalidate cached embeddings, and predictions that must be explainable to analysts. PinSage (Ying et al., 2018) is the canonical case study — from a 2-layer GraphSAGE prototype to a system serving hundreds of millions of users. Its most important innovations are not architectural: random walk importance sampling, MapReduce offline embedding computation, and ANN serving are the engineering decisions that made billion-scale GNN deployment feasible.

NOT this. "GNNs are only used for node classification." GNNs support node classification (protein function prediction), link prediction (friend recommendation, drug-target interaction), graph classification (molecule property, circuit quality), and graph generation (drug design). The readout function changes — per-node output for node classification, pair scoring for link prediction, global pooling for graph classification — but the message-passing backbone is the same. The drug-target binding task above is a graph-graph matching problem that uses GNN encoders on both graphs plus cross-attention for compatibility scoring.

Key points

Takeaway

PinSage is the definitive case study for production GNNs at scale: 3B nodes, 18B edges, sub-10ms serving latency. Its innovations — random walk-based neighborhood importance sampling, MapReduce offline embedding computation, and ANN retrieval — collectively solve the three hard production problems: neighborhood explosion, embedding staleness, and low-latency inference. The practical lesson is that a production GNN system is not one model but a pipeline — feature store, graph store, batch embedding computation, ANN index, and event-driven cache invalidation are all load-bearing components, and the GNN model itself is often the least complex part of the system.

Recap

Check your understanding

Q1. You are the ML lead for friend recommendations at a social network with 500M users. Design a GNN system end-to-end, from data pipeline to serving. What are the top 3 engineering challenges?

Q2. PinSage uses random walks to define "neighborhoods" rather than direct graph neighbors. Why? What problem does this solve?

Q3. Which two of the following are plausible causes of a fraud GNN scoring 99% offline AUC but only 70% precision at 10% recall in production? (Select two.)

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →