A still per user
Feed it events as they arrive. The cut keeps what matters, the infusers add what's known about each event, once, on the way in. What stays is ready for any question.
Feed each user's events into a still, from a JetStream stream or a database replay. Cut what doesn't matter, infuse what you know, draw off what's stale, and distill as many states as you have recipes. Proven against a shop full of generated traffic.

Events come in from wherever they live: a NATS JetStream stream as they happen, or a replay from a database. Each user gets a still, and every event is worked on once, on arrival:
| feed | events go into the user's still, a batch at a time, in arrival order |
| cut | what isn't worth keeping is cut, and gone |
| infuse | what is known about each kept event (its time, its session, its taste) is infused into it |
| distill | a recipe reduces the still to a state, as often as you like, with any recipe |
| draw off | what the still should no longer hold is drawn off, by composable rules |
A shopper's month, fed into the affinity still and distilled two ways. This is the package's runnable example, output included:
still := affinity.New(nil)
for _, visit := range month {
for _, request := range visit {
still.Feed(affinity.Envelope(request), request.Events...) // a sesamy-go payload, as it comes
}
}
vector := still.Distill(affinity.DefaultFade.Vector) // the taste
phases := still.Distill(affinity.Phases(affinity.DefaultPhaseThreshold)) // who, and when
still.DrawOff(affinity.Rules.InSession(month[0].ID())) // forget a visit
// fed 7 visits, kept 65 choices
// the vector leads with classic, the month is 1 phase
// forgetting the first visit draws off 9 choicesThe exhibits are written by the test suite: every one is computed from the real code on every run, every product and persona shown by its image, every claim next to the test that checks it.
Schau ma moi: Bavarian for "let's have a look". Or, at a distillery, a taste.