database – Event sourcing with dynamic queries

  • I have a large database of users
  • I have a way for end users to segment these users by creating filters, i.e. last seen 3 days ago. last browser safari etc.

I need to detect when users enter these segments. This needs to be performant as I may have many of these filters, which are dynamically defined and millions of users, so running a query whenever user(s) change will cause significant db load in a naive implementation.

I’m looking for architectural ideas for how to solve this problem, or event the name of the problem I’m trying to solve here. Is this event sourcing or better described as something else. Is such a problem handled with specific tools, or are there patterns I could use to solve this alone.