Logging the served features removes skew. What does it cost?
The safest route has a price.
You log every feature vector you serve. Then you add a new feature. When can the model train on it?
Write the exact feature vector the model scored, keyed by request id. Join the labels to it later.
That's Rule #29 in Google's guide. It calls this the best way to make sure you train like you serve: save the features used at serving time, and log them for training. The guide adds that YouTube's home page switched to logging features at serving time, with significant quality gains and less code complexity.
The training row is the serving row: the same code, the same timestamps, the same lag, and the same default on every request where a store timed out. Nothing has to match, because nothing is computed twice.
The first cost is time. A new feature produces training data only from the day it ships. Netflix's fact store post gives that as its reason to regenerate features instead of logging them. Netflix trains on several weeks of data, so it would have to wait several weeks to collect it.
The second cost is volume, and you should estimate it out loud. Assume 200 member features, and per candidate 60 title features and 40 member-by-title features, all 4 bytes:
| What you log per request | Bytes per request | At 20,000 requests/s |
|---|---|---|
| Everything: 200 member features, plus 500 candidates × 100 features | 800 + 200,000 = 200,800 | 4.0 GB/s, about 347 TB a day |
| Title features by reference: member features, 500 × 40 cross features, 500 title ids, one 8-byte catalog version | 800 + 80,000 + 2,000 + 8 = 82,808 | 1.66 GB/s, about 143 TB a day |
| The same, for a 5% sample of requests | about 7.2 TB a day |
Title features are the same for every member served in the same minute. So each request logs only the catalog version, and you keep the catalog snapshots.
Sampling is fine for training data and for checking skew. Rule #29 suggests it: if you can't log every example, log a small fraction, so you can check that serving and training agree.
In the editor, write request_bytes(member, candidates, cross, title, by_reference) and tb_per_day(per_request, rps, sample). Check them against the table: logging everything is 200,800 bytes a request, and title features by reference are 82,808.
- 1
Every feature is 4 bytes. Write
request_bytes(member, candidates, cross, title, by_reference): the bytes one request logs. That'smemberfeatures, pluscrossmember-by-title features andtitletitle features for each candidate. Withby_reference, the title features are swapped for a 4-byte title id per candidate and one 8-byte catalog version. Then writetb_per_day(per_request, rps, sample=1.0), in terabytes of 1012 bytes.
Run your code to check it. Output shows here.