Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish events using MongoDB Change Streams #32

Open
bounoable opened this issue Mar 29, 2022 · 2 comments
Open

Publish events using MongoDB Change Streams #32

bounoable opened this issue Mar 29, 2022 · 2 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@bounoable
Copy link
Contributor

bounoable commented Mar 29, 2022

By default, events are not published over a bus when inserted into a store. To automatically publish inserted events, a decorator can be used:

package example

func example(store event.Store, bus event.Bus) {
  // store publishes events over the given bus after insertion into the store
  store = eventstore.WithBus(store, bus)
}

This has a flaw: when the process crashes between the insert and publish, the event will never be published, causing a "data-loss" (not really, the event was inserted into the store). If such an event would trigger a projection, the projection would likely be in an invalid state until it is manually reset by a user/developer because there is no way for a projection to know that it is missing events (not even through a projection.Progressor).

Proposal

Proposal is to create a service that uses the MongoDB Change Streams feature to tail the oplog of the event store. When an event is inserted into the database, the oplog notifies the service, which then publishes the event over the event bus.

Change Streams provide a "resume token" which are used to resume tailing the oplog after a service crash/restart. This should ensure that no events are "dropped" / all inserted events are eventually published.

@bounoable bounoable changed the title MongoDB Oplog Tailing Publish events using MongoDB Change Streams Mar 29, 2022
@bounoable bounoable added bug Something isn't working enhancement New feature or request labels Mar 28, 2023
@bounoable
Copy link
Contributor Author

@gedw99
Copy link

gedw99 commented May 29, 2023

https://github.com/damianiandrea/mongodb-nats-connector

Exactly !!

This is ready for integration

I presume we put the cdc events into nats ?

Then workers react to the events and create materialise read only data into something . Maybe mongo actually . Talk about inversion !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants