An alternative approach to A/B test results calculation: Streaming

Galderic Punti30 Nov 2023

Problem

Adevinta receives billions of events a day from marketplaces in 10 countries. Most A/B platforms recompute results from the first day of the experiment at every update. The last 24 hours cannot be merged with earlier results, because the same user appears in both and means and standard deviations merge only for disjoint populations. So every day the same billions of events are read and aggregated again. A stored table of user-level aggregates avoids this but needs code for state updates, backfills and missed runs.

Example from the article: an experiment to raise the number of ad views, on day 14 and then day 15. Adding the day-15 aggregates to the day-14 result counts a user such as Joe twice.

Solution in brief

Run a streaming job that lives as long as the experiment and reads each event once. When a user's aggregate changes, remove the old value from the group statistics and add the new one, using weighted Welford's algorithm with weights -1 and +1. Keep the accumulators in 128 bits, because the weighted version is unstable at 64 bits.

Questions this case answers
  • How to maintain group-level mean and variance of a per-unit metric incrementally when the same units keep updating their values and each event may be processed only once
  • How to update A/B test group means and standard deviations every day without re-reading all events since the experiment started?
  • How to track guardrail metrics of a running experiment in near real time?
  • How to merge a user whose aggregate keeps changing into group-level mean and variance without double counting?

Tools and methods

  • Kafka Streams — partitions events by user id, keeps user aggregates in state
  • Weighted Welford's algorithm — adds (weight 1) and removes (weight -1) samples
  • 128-bit accumulators — restore numerical stability
  • A/B test — group mean and deviation feed the significance test
Continue reading — it's free

Google or a one-time email code. No password.