Filtering events in a stream based on metadata


I want to implement multi-tenant streams in SingleNode event store by adding a “Tenant” key to event metadata.

I would like to ensure during reading that only events related to a current tenant are loaded and processed. I can easily implement a check while reading events from ReadStreamEventsForward and only process those that have a matching Tenant Any in event metadata.

I wonder if there’s a ‘better’ way to do that :wink:

Any ideas will be appreciated.



If you are going to do this it might be better to do something like prefix stream names with the tenant name, rather than trying to mix events from different tenants in a single stream.

That way you can read a stream belonging to a certain tenant without receiving events for all others (no client side filtering needed).

This has the other advantage of being able to use the new security features in v2 to really lock things down properly. (Just have a user group per tenant, and restrict access to the appropriate group for each stream).

Do the streams conceptually house data that is shared between multiple
tenants? Normally I would end up with say a stream per tenant. Can I
ask why the data for multiple tenants is in the same stream? or
perhaps more information on the business problem being solved.


There shouldn’t be any sharing of streams between tenants.
I just want to guarantee than certain tenant cannot load streams related to a different tenant.
Just another layer of security in case someone manages to submit a command with an aggregate id belonging to a different tenant.

Prefixing stream names with tenant sounds like a great idea and should be very easy to implement.

Many thanks!

You can also go one step further and setup permissions on the streams
to prevent this from happening in 2.0.



Cool. What is an ETA for 2.0?

Is mostly in master … Stress testing now for binary release. If you are brave build yourself :slight_smile: