A weekly data pipeline, and a self-service API on top of it, that builds statistically matched test and control audiences for a large retailer's online campaigns.
Online campaigns are only as good as the audiences behind them, and campaign results are only believable if the audiences are built correctly. Customers are grouped into communities, such as people buying particular items or people who have recently moved. Each community is divided into pods and sub-pods, and each sub-pod is split into a test group that sees the campaign and a control group held out from it.
The catch is that the two groups must be statistically similar, judged on the previous three to six months of sales. If they are not, any difference measured later is noise, not the effect of the campaign. At this scale that is a demanding data engineering problem: more than a thousand segments every week, group sizes from about 10,000 to 700,000 customers, and campaign requirements that differ from one initiative to the next.
Test and control groups are matched on recent sales so measured lift reflects the campaign.
The weekly schedule, the self-service API and a Pub/Sub message all lead to the same pipeline.
We built and maintained the audience creation process that sits at the center of the retailer's online campaigns. It takes each audience segment and splits it into groups as the requirements specify, across multiple customer-hierarchy levels, with test and control groups kept comparable on historical sales.
Customization requests arrived faster than a data engineering team should have to fulfil them one at a time. We built a self-service application, using Python, BigQuery, Airflow and PySpark, that lets users create customized audiences for specific campaign needs. The pipelines are exposed as an API running on Cloud Run.
A request can also be published as a JSON message to a Pub/Sub topic, which triggers the same Cloud Run service. Callers who prefer events to API calls do not have to poll to find out whether the job finished; the workflow reports back when it is done.
Several pipelines were implemented in BigQuery Dataform, which gives the SQL transformations version control, dependencies and testing. We also optimized long-running SQL jobs, since audience creation runs on a weekly schedule that campaigns depend on.
Tell us what you are building and we will say plainly whether and how we can help.
Start a conversation