Introduce Query Parameter in handler.WithStore()
for Selective Startup Queries
#124
Labels
enhancement
New feature or request
This proposal is to enhance the
handler.WithStore()
function in the event handler by introducing a query options. This would permit us to constrain the events that are fetched during startup to, for example, a specific timeframe:Background & Motivation
Consider a Mailer that subscribes to events to dispatch emails. The Mailer must be resistent to crashes, so it has to check for missed events on service startup.
We can construct this Mailer as an event handler using the
handler.Handler
type andhandler.WithStore()
option provided by goes. The WithStore() option will fetch the events that are registered in the handler from the event store. This could potentially take a lot of time, depending on the size of the event store.If this proposal would be implemented, startup performance could be greatly improved by narrowing down the event query's temporal scope, which would limit the timeframe for which the events are checked by the Mailer. This could greatly reduce startup time on server restarts.
Additionally, the
handler.Handler
can be upgraded to support periodic handler restarts, which guarantees that the handler captures any previously overlooked events, all while not excessively consuming computational resources when the event store is very large.Considerations
The
handler.WithStore()
option could become difficult to modify in the future without breaking compatibility. We could adjust the design tohandler.WithStore(store, handler.StartupQuery(query.New(...)))
. This may slightly compromise DX, but it would ensure the API is future-proof.Could also deprecate
handler.WithStore()
and create a newhandler.Startup()
option. Would better describe the feature.To-Do
The text was updated successfully, but these errors were encountered: