Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
-
skiplist
A Go library for an efficient implementation of a skip list: https://godoc.org/github.com/MauriceGit/skiplist (by MauriceGit)
The Mercure Hub originally dealt with this issue using an in memory cache to eliminate duplicate regular expression evaluations.
Each subscriber is stored in a skip list. As subscribers are added, they are assigned an autoincrementing ID and the skip list grows. Skip lists are preferred over slices here due to their discontinuous nature. Subscribers can be added and removed at random and the memory usage will remain bounded.
Each topic has a roaring bitmap. Each bit corresponds to a subscriber in the skip list. For each topic, head and tail cursors are also maintained to ensure that newly added subscriptions are always tested and deleted subscriptions are always evicted. Roaring bitmaps are compressed and discontinuous so memory usage again remains bounded as subscribers come and go.