Peach · impressions pipeline
The life of one impression
A carousel of recommendations scrolls into view. That one moment is counted for the A/B comparison, remembered per user so endpoints can stop repeating themselves, and kept as a row for analysis. One event in, three copies out.
The recommendation is served, with a token
Ray Serve endpoint personal_episodes · namespace peach-codops-sesr
An impression only means something if it can be traced back to what produced it. So every endpoint response carries an id: the recommendation token. It packs repo::endpoint::component::version::uuid, encrypts it, and Base64-encodes the result. The component is the A/B variant; the uuid is new on every request.
{ "status": "ok", "result": { "items": [{"id": 2436668}, {"id": 2396369}], "id": "a+jaUI6+uiEW…==" // the token } }
- mint the token, once per request
- if minting fails the endpoint still answers, with
placeholder_123
- None. The token is self-describing: nothing is stored to look it up later
The carousel becomes visible
the member's tracker + pipe SDK, in the browser / mobile app
When the module scrolls into view, the app fires recommendation_displayed and hands the token back in event.id, with the items it showed. Its siblings: recommendation_loaded (the response arrived), recommendation_hit (the user picked an item) and recommendation_item_displayed (one item was seen).
{ "event": { "type": "recommendation_displayed", "id": "a+jaUI6+uiEW…==", // the token from hop 00 "event_timestamp": 1763385600061, "context": { "page_uri": "home", "source": "carousel", "items": ["2436668", "2396369"] } }, "user_id": "a756b2b2-…", "client": { "id": "b7d4689d-…", "type": "mobileapp" }, "site_key": "sesr000000000044" }
- the tracker decides when a module counts as seen
- SDK batches it with other events
- None durable. In memory until the SDK flushes
HTTPS into the collector
peach-pipe-collect · 3–150 pods
Same door as every other event: /v3/collect?s=sesr000000000044. The collector checks the site key and forwards. It does not know or care that this is an impression.
- site-key check, CORS, split the batch
- None. Pass-through to Kafka
Lands on the raw topic, where three paths begin
MSK cluster peach2 · 3 brokers · topic sesr000000000044_events
The impression is now one JSON record among all of sesr's events. Nothing routes it: each consumer group reads the whole topic at its own pace and picks out what it wants. Three of them care about impressions, and from here the path splits.
- MSK broker disks: the only copy of the event as it was sent
- group
realtime_metrics→ branch A, counted - group
impressions-dragonfly→ branch B, remembered per user - group
peach-events-bridge-v3→ branch C, kept as a row
Counted: is this variant working?
Answers within about a minute, for the whole audience, with no user in it.
Decoded and counted in a 60-second window
realtime-processing, mode metrics · 1 pod · namespace peach-realtime-processing
A small Python stream keeps only the three recommendation events (loaded, displayed, hit), collects them for 60s, then decrypts each token to recover who produced the recommendation. It counts per (codops, endpoint, component, version) and writes the totals out. Our impression becomes +1 for personal_episodes / milvus2_gauss_decay.
- filter, 60 s wall-clock window
- decrypt
event.id; a token that fails to decode is logged and skipped - count by endpoint, component, version
- None durable. The open window lives in the pod's memory
- after a restart it resumes where it stopped and counts the backlog as if it had just happened
A point in VictoriaMetrics
VMSingle metrics-vm · namespace metrics
Each window becomes one data point per variant. The value is the count in that minute, not a running total, which is why every query sums the points instead of taking a rate.
reco_metrics_v3_recommendation_displayed{ codops="sesr", endpoint="personal_episodes", component="milvus2_gauss_decay", version="sesr_v1.0.270" } 412 ← displayed in this 60 s
- series
reco_metrics_v3_recommendation_{loaded,displayed,hit} - kept for the long run (retention set to 100 years), backed up hourly to S3
- the user is gone: only counts per variant remain
The A/B table reads it
this dashboard, Overview › Endpoints · Grafana "A/B evaluation"
The Overview page sums the last 24 hours of points per endpoint and component, for displayed and for hit, and divides: CTR = hit ÷ displayed. It hides the CTR until a variant has at least 100 impressions, because a rate over a handful of views says nothing.
sum by (endpoint, component) (sum_over_time(reco_metrics_v3_recommendation_displayed{codops="sesr"}[24h]))
Remembered: has this user seen it already?
The same event, kept per person and per item, so a recommendation endpoint can look it up while answering.
One write per item shown
realtime-processing, mode impressions · Deployment sesr-impressions · 1 pod
A second copy of the same service, running in the codops's own namespace, handles impressions one event at a time, with no batching. For each item in context.items it runs a short script inside the cache that bumps a counter and stamps the time. Live content is skipped; an item id that is not valid for the codops is skipped.
- filter the 8 impression types (recommendation_* and collection_*)
- one atomic script call per item: increment, set timestamps, refresh expiry
- None. Nothing is buffered, so a restart loses nothing
- after downtime it resumes from where it stopped and catches up
A hash per user in Dragonfly
Dragonfly sesr-dragonfly · 1 instance, in memory · 17 GB cap
Every user has one hash. Each item they were shown gets a few fields in it: how many times, first time, last time. Each write pushes the whole hash's expiry out again, so a user who keeps coming back is never forgotten and one who leaves disappears after 90 days.
2436668:rec_d:count 3 ← was 2 2436668:rec_d:first_timestamp 1762780800412 2436668:rec_d:timestamp 1763385600061 ← now 2396369:rec_d:count 1
- short field names (
rec_d,rec_h,rec_i_d…) because there are millions of them - memory first: when the instance is full, writes fail; nothing is evicted
- snapshot to
s3://peach-members-sesr/dragonfly-backupfour times a day, so a crash can lose up to 6 hours
An endpoint reads it while answering
Ray Serve endpoint · pipe_algorithms_lib.impressions_utils
On the next request for this user, an endpoint can fetch the hash and drop items the user has already been shown too often. This closes the loop: the impression from hop 01 shapes the response at hop 00. Whether an endpoint does this is the member's choice, in their own code.
- one hash read by user id, inside the request
Kept: a row you can query
Nothing special here. The impression takes the ordinary analytics path, described hop by hop in The life of one event.
A row in StarRocks
bridge → AutoMQ topic sesr.recommendation_displayed → routine load
Typed as Avro, loaded into peach_events_sesr.recommendation_displayed, one row per impression with the items it showed. This is the copy for questions the two fast branches cannot answer: by page, by device, by day, joined to plays.
- the row, on the codops's StarRocks volume in S3; queryable from Data › Queries and Superset
What the impression left behind
- Raw: JSON on MSK (
sesr…044_events) - Count: a +1 in a per-minute point in VictoriaMetrics, no user attached
- Memory: counters in
sesr:impressions:<user>, for 90 days - Row: in
peach_events_sesr.recommendation_displayed
- endpoint: mint the token
- metrics stream: decrypt the token, count per minute
- impressions stream: one script call per item
- bridge + routine load: type it, load it
Reading this trace: names and settings are the prod-2 configuration for sesr; the counts and ids are illustrative. The per-user branch runs for the codops that enabled it (today dedlr, sesr, seur), each with its own expiry. The per-minute counts cover the site keys listed in the metrics stream's configuration, so an impression sent on another key is stored but not counted. recommendation_item_displayed is only remembered per user, never counted in the A/B series. Counts are stamped with the time they were written, not the time of the event. The raw topic is also archived to S3 by a separate sink, outside this journey.