How late is too late? Measuring late-arriving events

·

Our main event pipeline is a daily batch job: apps send analytics events, and every night the job cleans and deduplicates them into a table partitioned by day. Until this month, each run rewrote the last 28 days of that table.

The reason was late events. A mobile app can record an event and not send it for days, for example when the phone is offline or the app isn’t opened again. When the event finally arrives, it belongs in the partition for the day it happened, and the only way to get it there in a batch pipeline is to rewrite that day. A 28-day window meant any event up to four weeks late still landed in the right place.

It also meant each run processed about 3.5 billion events to add about 120 million new ones. And because the last 28 days changed every night, jobs downstream of the table had to reprocess those 28 days too.

Measuring how late events are

Every event carries both the time it happened and the time we received it, so the question has a direct answer. I took one week of events, and counted how many arrived more than seven days after they happened:

652,445 out of 847,519,128 events, or 0.077%.

The overall number hides most of the useful detail. Broken down by the app that sent them:

  • Web: effectively none. 68 out of about 115 million events were more than a week late.
  • Mobile apps: between about 0.1% and 1.8%, depending on the app.
  • iOS versus Android: for each app we have on both platforms, the iOS version had a much higher share of late events, from about three times to more than fifteen times the Android rate.

By event, the latest were app lifecycle events: the app starting, closing or being upgraded, login screens, push notifications received. For one Android app, about 20% of app-start events arrived more than a week late. That fits how mobile clients usually send events: they queue them and send the queue when the app is next opened. Events from the last session before someone stops using an app for a while arrive whenever they come back.

Choosing a window

With those numbers, I proposed cutting the window to seven days, which would have reduced the work for the pipeline and everything downstream of it by about three quarters. In exchange, the 0.077% of events that arrive more than a week late would no longer be added to the table.

Most of the questions that followed were about specific apps and metrics, not the total. A share that is negligible overall isn’t negligible for a team that measures one iOS app, or that counts how many people opened an app in a month. Teams asked how the change would affect their numbers, which is where the per-app and per-event breakdowns mattered.

We settled on 14 days, which took effect on December 2. Each run now rewrites half as many days as before, and an event that arrives more than two weeks after it happened is no longer added to the table.

What I’d do the same way next time

  • Measure lateness before picking a window. One week of data was enough to show how little of our 28-day window most events needed.
  • Break it down by source. The average was close to zero. The cost of a shorter window was concentrated in a few apps and a few kinds of event, and those were exactly the details the people affected needed.
  • Treat the window as a product decision. The pipeline team pays for a long window in compute; the teams reading the data pay for a short one in accuracy. Both sides need to be in the discussion, with the same numbers in front of them.

Comments

One response to “How late is too late? Measuring late-arriving events”

  1. […] cluster’s normal work. Our batch pipeline reprocesses the last 14 days every night to pick up late-arriving events, so the replayed events flowed into every downstream table without any manual […]

Leave a Reply

Your email address will not be published. Required fields are marked *