13/35
Part 2 of 3 · Two stores, one truthLearn and do

Design the online keys around the request, not the feature

The online store's keys decide how many reads each ranking call makes.

Feature kindValues per requestWhere it livesReads per request
Member1 setthe online store, under the member's key1
Title500 sets, the same for every membereach server's memory0
Member-by-title500 valuesinside the member's value, as a map from title to value0 more

A member-by-title feature describes one member and one title together, like how often this member saw this title today.

Naively, the ranker reads 1 member key and 500 title keys per request. At 20,000 requests a second, that's 20,000 × 501, about 10 million reads per second. Two changes fix that.

Title features are shared by every member. At 60 features plus a 64-number embedding, a title is about 500 bytes. So the whole 20,000-title catalog is about 10 MB. Keep it in each server's memory and refresh it every few minutes. Title reads drop to zero.

Member-by-title features go in one value per member. Impressions of each title today become a map from title to count, under the member's key. That's one read per request instead of 500.

That leaves about 20,000 member reads per second per store, a 500-fold cut.

In the editor, write reads_per_second(rps, candidates, titles_in_memory) and catalog_mb(titles, features, dims). The last lines count the reads both ways at 20,000 requests a second, and size the 20,000-title catalog.