All work Retail · Data engineering

The audience-creation engine behind online marketing campaigns

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.

Our role
Pipeline ownership, customization and the self-service application
Technology
BigQueryDataformAirflowPySparkCloud RunPub/SubPythonREST APIs

The challenge

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.

How it works

From customers to test and control groups
How audiences are builtCustomers are grouped into communities, such as item buyers or recent movers. Each community is divided into pods and sub-pods. Each sub-pod is split into a test group exposed to the campaign and a control group held out for measurement. The two groups are statistically matched on three to six months of prior sales. Groups range from about 10,000 to 700,000 customers.Customersall segments,1,000+ a weekCommunitiese.g. item buyers,recent moversPodsgroups within acommunitySub-podssplit into testand controlTest groupexposed to the campaignControl groupheld out for measurementstatistically matched on3-6 months of prior sales10,000 to 700,000 customers per group

Test and control groups are matched on recent sales so measured lift reflects the campaign.

Three ways to request an audience
How audience requests reach the pipelineThe weekly schedule runs the audience pipeline directly. Users can also request a custom audience through a self-service API on Cloud Run, or publish the request as JSON to a Pub/Sub topic, which triggers the same Cloud Run service so callers do not need to poll. The pipeline, orchestrated by Airflow with BigQuery, Dataform and PySpark, produces test and control audiences.Weekly schedule1,000+ segmentsSelf-service APIrequest a custom audiencePub/Sub messagerequest as JSONevent based, no polling for completionCloud RunAPI endpoint forthe pipelines,also triggered byPub/SubAudience pipelineAirflow orchestrationBigQuery + DataformPySpark for heavytransformationsAudiencestest and controlready to use

The weekly schedule, the self-service API and a Pub/Sub message all lead to the same pipeline.

What we built

The weekly audience 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.

  • More than 1,000 segments every week.
  • Group sizes of roughly 10,000 to 700,000 customers, and on the order of 100 million audience records processed in a weekly run (estimated).
  • Extended repeatedly for new initiatives, with customizations added to the same pipeline instead of forked copies.

A self-service API

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.

Event-driven requests with Pub/Sub

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.

SQL pipelines and performance

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.

How it flows

  1. RequestSegments arrive from the weekly schedule, the self-service API or a Pub/Sub message.
  2. Build segmentsBigQuery and Dataform pipelines assemble each community, pod and sub-pod.
  3. Split and matchEach sub-pod is divided into test and control groups that match on 3 to 6 months of sales.
  4. OrchestrateAirflow schedules, sequences and retries the jobs; PySpark scales the heavy steps.
  5. DeliverTest audiences go to the campaign; control audiences are held out for measurement.

What changed

  • More than 1,000 audience segments processed every week, at group sizes up to 700,000 customers.
  • Test and control groups matched on recent sales, so downstream measurement of lift is trustworthy.
  • One pipeline serving many initiatives through configuration and customization, not copies.
  • Campaign teams across the business can create customized audiences themselves through an API, or trigger them with events.
  • Faster, better-organized SQL jobs after optimization work in BigQuery.

Facing something similar?

Tell us what you are building and we will say plainly whether and how we can help.

Start a conversation