Ad Targeting Pipeline
An advertiser wants to reach “women aged 25-34 in San Francisco who have browsed running shoes in the last 7 days.” When a bid request arrives for a user, the DSP must evaluate whether this user matches the targeting criteria in under 5ms. The ad targeting pipeline is the system that makes this lookup fast.
Audience Segments as Bit Arrays#
Each targeting criterion defines an audience segment: a set of user IDs. “Browsed running shoes in the last 7 days” is a segment computed from clickstream data. Rather than storing this as a list of user IDs (expensive to query), represent it as a bitmap: a bit array where bit N is set if user N is in the segment.
Bitmap operations are fast: an AND of two bitmaps intersects two segments in O(N/64) with 64-bit operations. “Women aged 25-34 AND browsed running shoes” is a bitmap AND. Roaring bitmaps compress sparse bitmaps efficiently and are the standard implementation.
Segment bitmaps are precomputed by a batch pipeline (running hourly or daily), stored in Redis or a dedicated segment store, and loaded into DSP memory. At bid time, the user ID is looked up in the relevant bitmaps — a O(1) bit check.
Frequency Capping#
A campaign might target 10 million users but cap each user at 3 impressions per day. Frequency capping requires tracking per-user, per-campaign impression counts. This is a distributed counter problem: INCR freq:user:87654:campaign:123. Check before bidding: if count >= 3, skip.
At scale, frequency cap counters are hot. The same user hitting many sites in a day generates many counter reads. Bloom filters reduce load: maintain a Bloom filter of users who have reached the frequency cap for a campaign. False positives (incorrectly capping a user who hasn’t reached cap) are acceptable; false negatives (serving to a capped user) are not. This trades occasional underspend for significantly lower counter read load.
Contextual vs Behavioral Targeting#
Contextual targeting uses signals from the current page (keywords, category, URL) rather than user history. No user profile lookup needed. Contextual targeting is privacy-preserving and doesn’t require cross-site tracking, making it relevant after third-party cookie deprecation. The pipeline is simpler: parse page content, match against campaign keyword lists, bid.
At Oracle#
Oracle Data Cloud built third-party audience segments sold to DSPs. The segment pipeline: ingest clickstream data from publisher partners, compute segment membership daily, export bitmaps to customer DSPs via S3. Customers imported these bitmaps and could evaluate targeting in-process at bid time. The bitmap export size for a 50-million-user segment was about 6MB as a compressed Roaring bitmap — small enough to fit entirely in a single DSP server’s memory.
What I’m Learning#
Targeting pipelines win on precomputation. Anything that can be computed offline before the bid arrives should be. The bid-time path should be pure lookup: bit checks, counter reads, and simple comparisons. Anything requiring real-time computation at bid time will blow the latency budget.
Have you worked with audience segments or targeting systems, and what was the hardest targeting criterion to evaluate efficiently?