A stream’s subject filter is not one undifferentiated set scanned per event. It is split by subject kind, because SSF §8.1.3.1 matching splits cleanly:
subject_filters collection
carries an index on that canonical key.A subject filter may legitimately reach millions of entries (a watchlist of every account or email a receiver cares about). A single linear scan per delivered event would be O(N) — unworkable. The split makes delivery-time matching O(1) when the event subject is simple and O(complexCount) when it is complex, and complexCount is small in practice: bulk watchlists are simple subjects, complex subjects are the rare device/session composites.
On top of the store sits a per-node, bounded (LRU), short-TTL match-result
cache keyed by (stream_id, subject canonical key) → deliver/drop. Events
about a subject arrive in temporal clusters, so a small cache absorbs most
lookups; the canonical hash-indexed table stays in Mongo rather than being
pinned whole in node memory (millions of entries is real memory pressure). PUSH
(the lease owner) and POLL (any serving node) both use cache-or-single-lookup.
Cache accuracy is deliberately soft. A stale “deliver” merely over-delivers for a few seconds — harmless, and consistent with SSF §9.3’s tolerance for events after removal. A stale “drop” wrongly suppresses, which is the hazardous direction — so the cluster invalidation signal fires promptly on delivery-increasing operations (Add), while delivery-decreasing operations are already softened by the §9.3 removal grace period. Short TTL bounds the rest.
SubjectFilterService exposes simple-key membership and complex field-wise
matching as distinct paths; Allows(stream, event) picks the path by the
event subject’s kind.SubjectFilterDAO / the subject_filters collection carries a canonical-key
index and a sparse index on the §9.3 enforceAt field (only pending-removal
entries carry it) so pending removals are enumerable without scanning the
table.(C)2026 Independent Identity Inc.