Logo
All posts

How Netflix recommends fresh content in the homepage - AI Engineering Case Study #3

In this blog we will see how Netflix cut one recommendation feature from 7.5% of its CPU to about 1%.

Gaurav Sen/13 min read

In the first half of 2023, Netflix members watched nearly 100 billion hours of content.[3]

The homepage is what drives this. It recommends fresh content to every user.

The rows on that homepage come from a service called Ranker. Netflix calls it one of its largest and most complex services, running at an enormous scale.[1]

A Netflix homepage fills in row by row: Trending Now, Because You Watched, and Top 10 in Your Country, each title shown by its poster. One new title in the middle row, Inception, is ringed in orange.

Ranker asks one question of every title it might show: "How different is this new title from what you've been watching so far?"

In early 2026, answering that question took about 7.5% of the CPU on each node running Ranker.[1]

That CPU is paid for in machines. A feature that costs 7.5% of every node costs 7.5% of Ranker's cluster, and it adds time to every request that waits on it.

To bring that cost down, Netflix's engineers faced two problems:

  1. One feature spent 7.5% of the CPU on every Ranker node.
  2. It compared titles one pair at a time, in plain Java loops.

In this blog we will see how Netflix cut one recommendation feature from 7.5% of its CPU to about 1%.

1. How different is a new title?

What does that one feature compute? It compares a new title with every title you have watched.

To a computer, each title is a list of numbers, called an embedding. Two titles that are alike get numbers that point the same way.

The Ranker service does this by comparing new titles against what you've already watched. It uses dot products between vectors to measure how similar two titles are.

Netflix measures it as cosine similarity: the dot product of two vectors, divided by their lengths. When every vector is first scaled to a length of 1, the similarity is just the dot product.[1]

Inception, in orange, on two axes, thriller and sci-fi, beside three titles the member watched, in green. A dotted line to each carries a similarity: 0.82 to Dark, 0.95 to Tenet, ringed as the highest, and 0.15 to Comedy X. Novelty is 1 minus 0.95, which is 0.05.

Ranker computes that similarity for Inception against each title you watched, and keeps the highest one.

similarity(Inception, Dark)     = 0.82
similarity(Inception, Tenet)    = 0.95    the highest
similarity(Inception, Comedy X) = 0.15
novelty = 1 - 0.95 = 0.05

Inception is barely new to you: you watched Tenet. A title far from everything you watched would score high on novelty. That number goes into the rest of Ranker's logic as one input.

This is called serendipity scoring.

2. Why did it cost so much CPU?

How many scores does one request need? One for every new title against every title in your history.

This process would consume 7.5% of CPU on every Netflix recommendation node. Netflix was doing this with basic Java multiplication. Every dimension of the vector multiplied and added one at a time.

One dimension at a time looks like this, for two short vectors, (3, 7, 2, 5) and (4, 1, 8, 6):

3 x 4 = 12
7 x 1 = 7
2 x 8 = 16
5 x 6 = 30
12 + 7 + 16 + 30 = 65

A single pair takes four multiplications, one after another. The code ran them in a nested loop: M new titles against N watched titles, M x N separate dot products. A profile of Ranker showed these Java dot products as one of its top hotspots.[1]

Those dot products came in two kinds of request. About 98% asked about one title.

The other 2% were large batches, so large that they carried about half of all the titles scored.[1] A faster batch would save half the work.

3. Solution 1: one matrix multiply, in flat buffers

Why compute M x N dot products one by one, when they are all one calculation?

Netflix packed the new titles' embeddings into one matrix, A, a row per title. The watched titles went into another, B, and every row was scaled to a length of 1.[1]

One matrix multiply, A x Bᵀ, then gives every similarity at once. The cell in row i and column j is new title i against watched title j.

Each row's highest number gives that title's novelty. Turning many small operations into one large one like this is batching, the shape CPUs and maths libraries are built for.

Netflix tried batching on canaries, servers that take a share of real traffic. It was about 5% slower.[1]

How can the same maths in one step be slower? The maths was right. The memory around it was wrong.

That memory was new arrays of arrays, double[][], built for every batch. They lived for a moment and were thrown away, so the garbage collector worked harder. And an array of arrays is scattered across memory: the CPU chases a pointer to every row, and its cache helps less.[1]

Netflix moved each matrix into one flat double[], its rows laid end to end. Each thread kept its own buffers in a ThreadLocal, grown when a batch needed more and never shrunk. No batch allocated memory, and no two threads shared a buffer.[1]

That left one question: what is the fastest way to do the multiply itself? The first version still multiplied one number at a time.

4. Solution 2: BLAS

Is there a library that already multiplies matrices fast?

To speed this up, one idea was to try the BLAS library (Basic Linear Algebra Subprograms). These are optimized libraries for math computation, but every call crosses the Java Native Interface boundary. That means copying data back and forth between Java and native code. The overhead was so bad they abandoned it.

Java on the left and native BLAS on the right, with the JNI line between them. The Java array crosses to the native side and the result crosses back. The BLAS route is crossed out, and the Vector API takes its place on the Java side.

In Netflix's own tests on BLAS alone, it looked fast. In Ranker, the gains never came.[1] Three things got in the way:

  1. Java's default BLAS route, netlib-java, ran F2J: the Fortran code translated to Java. The fast native code never ran.
  2. Native BLAS paid for setup and for every crossing of the JNI line.
  3. Java lays a matrix out row by row, and many BLAS routines expect it column by column. Converting meant more copies and more temporary buffers.

Netflix needed the speed of BLAS without leaving Java.

5. Solution 3: the Java Vector API

Can Java code use the CPU's fast instructions directly?

So Netflix tried the Java Vector API instead. This uses SIMD (Single Instruction Multiple Data). Instead of multiplying one dimension at a time, SIMD multiplies 4 or 8 at once.

I explained this step in a one-minute reel. Here are the same two vectors as before, worked both ways.

Vector A over vector B. First each pair is multiplied on its own, 12, 7, 16 and 30, and added to 65. Then all four pairs are multiplied in one step, and the same four products arrive together.

The code stays plain Java, so nothing crosses the JNI line. Java's compiler turns each vector operation into the widest instruction the CPU has. That is often 4 doubles at a time on AVX2 hardware, and 8 on AVX-512.[1]

The flat buffers from Solution 1 were already laid out for it. The Vector API is still incubating in the JDK, and it needs a flag when Java starts: --add-modules=jdk.incubator.vector.[2]

Netflix didn't want Ranker to depend on that flag. At startup, Ranker checks for the API. If it's missing, Ranker falls back to a fast loop that multiplies one number at a time.[1]

6. What Netflix measured

Did it work in production? Netflix ran canaries on production traffic with every change in place.

This is how Netflix reduced its average latency for recommendations by 12%.

What Netflix measuredChange
CPU use on Rankerabout 7% lower
Average latencyabout 12% lower
CPU per request per secondabout 10% lower
Serendipity scoring's share of CPU7.5% to about 1%

The numbers held after the full production rollout.[1] Ranker serves the same traffic with about 10% less CPU.

No single library did this. Netflix's own lesson is about the basics: the right shape for the computation and memory laid out for the cache. Then no overhead is left to eat the gain.[1]

Summary

  1. Ranker builds the rows on Netflix's homepage. One of its features scores how different a new title is from your history.
  2. It takes the highest similarity against your history, and novelty is 1 minus it.
  3. That feature used about 7.5% of the CPU on every Ranker node, computing dot products one pair at a time.
  4. Batching them into one matrix multiply was 5% slower at first, because of new arrays on every batch.
  5. Flat, reused buffers fixed the memory. BLAS failed in production because of JNI crossings and copies.
  6. The Java Vector API multiplies 4 or 8 numbers per instruction in plain Java.
  7. Ranker's CPU fell about 7%, its average latency about 12%, and the feature went from 7.5% to about 1% of CPU.

Sources

  1. Optimizing Recommendation Systems with JDK's Vector API, Harshad Sane, Netflix TechBlog, 3 March 2026.
  2. JEP 508: Vector API (Tenth Incubator), OpenJDK.
  3. What We Watched: A Netflix Engagement Report, Netflix, 12 December 2023.
  4. This is how Netflix recommends fresh content in the homepage, Gaurav Sen, YouTube, 3 April 2026.
WhatsApp