Customer Segmentation at Glovo

Ahmad Hamouda, Marcos Paulucci13 Jul 2022

Problem

Glovo, a delivery marketplace, wanted to show some discounts only to chosen audiences, for example new customers. The business and partners were going to define segments themselves: about 1K at first and over 100K later. Each segment could hold millions of customers and weigh around 50 MB on average. Other services needed to ask "which segments does this customer belong to?" through synchronous API calls, so the lookup had to be fast and must not hurt their own latency targets.

Example from the article: a discount shown only to new customers, with the segment recalculated on a schedule and read by client services through an API.

Solution in brief

Split the system into Core and Store. Core recalculates every segment on a schedule with PySpark on the existing data lake. Store keeps segment definitions in a relational database, loads results into Elasticsearch through a separate ingestion cluster, and answers lookups from an API cluster with a Redis cache in front.

Questions this case answers
  • How to compute many audience definitions over terabytes of batch data and serve per-user membership lookups at low latency when the data is only eventually consistent
  • How to compute customer segments from data-lake tables and serve them to other services with single-digit-millisecond latency?
  • How to let the business define many audience segments for targeted discounts without building a new pipeline for each?
  • How to swap in freshly calculated segments without downtime or a half-loaded index?

Tools and methods

  • Apache Spark (PySpark on AWS EMR) — scheduled segment calculation over hundreds of millions of rows
  • Amazon S3 data lake — source tables and output location for calculated segments
  • Jenkins and Luigi — orchestration of the calculation jobs
  • Amazon SQS — notifies the ingestion cluster about new calculations
  • Elasticsearch — serves segment membership with filters on many fields
  • Redis — cache-aside layer and a lock for ingestion
  • Datadog APM, Kibana — monitoring of the clusters and indexes
Continue reading — it's free

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