How we built a Data Management Platform: architecture, problems, takeaways

Evgeny Chmel9 Feb 2022

Problem

Ozon uses user segments to target notifications, emails, recommendations, banners and promo prices. At first an analyst built each segment by hand after a customer request, and the number of requests kept growing. Once segments became self-service, the platform had to store about 3,000 segments for millions of users and refresh them on schedule. Soon the segment store hit the per-node I/O limit set by the DBAs.

Example from the article: a manager builds the segment "viewed products of brand 87314531 in the last 60 days or added them to favorites". The system turns it into ClickHouse queries and saves the user ids as a segment.

Solution in brief

A segment constructor turns manager filters into parallel queries to ClickHouse (events) and Vertica (orders), combines the results by a formula and writes them into a sharded PostgreSQL table. Segment updates are batched across segments, sharded, and reduced to the difference between two builds.

Questions this case answers
  • How to build and refresh thousands of rule-based user segments on event data and serve them to other services when the segment store becomes the write bottleneck
  • How to merge the segments of an anonymous session with those of a known user id without a growing number of re-links
  • How to let marketers build audience segments themselves instead of filing requests to analysts?
  • How to store and update thousands of user segments for millions of users without overloading PostgreSQL?

Tools and methods

  • ClickHouse — user events and the daily export of segments for intersection counting
  • Vertica — order-based segments, loaded once a day from the order system
  • PostgreSQL (JSONB, 24 shards) — segments per user; links of ids and sessions in a separate table
  • Apache Kafka — real-time events and segment update commands
  • Ceph — bitmap of the previous active set for diff updates
Continue reading — it's free

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