Keep the stream and the backfill in step
A streaming feature has two implementations, even when you meant to write one. The stream computes it going forward. A batch backfill computes it over history, for training. They disagree for reasons no unit test shows.
The stream and the backfill drift apart in four ways
In the stream, last 7 days is a window that ends now. In SQL it's often 7 calendar days that end at midnight. Read both on a Thursday at 15:00. The SQL counts from last Thursday at 00:00, and the stream from last Thursday at 15:00. So 15 hours at the start count only for SQL, and 15 hours at the end only for the stream.
Pick one definition, for example 7 days moving in one-hour hops, and build both paths to it.
Three more ways the two paths drift apart:
- Event time against processing time. Window on when the event happened, not on when the processor saw it. Otherwise a 20-minute delay after a restart moves events into the wrong window.
- Late events. The stream drops events older than its allowed lateness, say 10 minutes. The warehouse keeps them. So the backfill counts a little more than the stream ever served, and the gap grows on days with outages.
- Time zones. Any feature with today or this week in it needs one stated time zone, used by both paths.
Define each feature once, then check the two paths against each other
The way out is to define each feature once and generate both paths from that definition. Airbnb's Chronon project page promises to eliminate data leakage with guaranteed point-in-time correctness (1 source).
Then check the two paths against each other. For a sample of keys and times, compare the value the stream served, from the log, with the value the backfill computes. Alert when the mismatch rate passes a threshold.
In the editor, write stream_window(t) and sql_window(t), the two meanings of last 7 days. thursday is the read time from the example, Thursday at 15:00.