Question regarding ChangeStreams vs. Triggers (and limitations in concurrent connections))

Hello,

For the solution that I am building, I am using MongoDB Atlas (Cloud) and building services with Spring Webflux. Using ReactiveMongoRepository and ReactiveMongoTemplate.

I have now successfully implemented our services which uses ChangeStreams to get reactive updates on changes (insert and/or updates) to documents in the MongoDB Atlas database. This means, every time a user logs in (in the front-end), they are seeing a dashboard with 5 ChangeStreams active on just 1 screen. With many users, this means a good amount of ChangeStreams.

I have contacted MongoDB Atlas, through the chat, but am getting mixed signals. First I am told that the ChangeStreams are part of the active connection limits as part of the cluster tier, as described by the link below:
https://docs.atlas.mongodb.com/reference/atlas-limits/#connection-limits-and-cluster-tier

Meaning that if you have 500 concurrent connections limit, and you have 50 ChangeStreams running, than you have used 50 of the 500, thus 450 remaining.

On another note, I am told, the limitations for ChangeStreams are different as per link below:
https://docs.mongodb.com/realm/reference/service-limitations/#change-streams

I am kind of confused and hope someone can perhaps answer my questions here.

Questions:

  1. Are the ChangeStream limits part of the Connection limit (as per cluster tier) or are they separate? If they are separate (and according to the second link), that means that you are not able to have a lot of ChangeStreams, if I am correct. This limits my ‘reactive’ application severely.

  2. If ChangeStreams are really that restrictive with those kind of limits. Are Triggers an alternative perhaps and how are they different compared to ChangeStreams?

Hope someone is able to provide any guidance/info here. Thanks in advance.

Hi Vahid –

The difference here is really whether you are opening change streams with the driver (as it sounds like you are today) or are using Realm (ex. with one of the Realm SDKs/Sync or Triggers).

When opening change streams directly, each one will count as it’s own connection from the client/server to Atlas.

However, Realm has built-in proxying of change streams across clients, giving some scalability benefits for change streams that you would otherwise need to write yourself in an interim layer between Atlas/change stream consumers. For this reason, when using Realm the change stream/end-user limits are structured slightly differently. When using Realm, generally the number of change streams open will count against your Atlas limit but you will be able to have far more concurrent clients due to the proxying.

Hope that helps!
Drew

1 Like

Thanks for the explanation Drew. So just to make sure that I understand your answer correctly: in my case, since I am using ReactiveMongoTemplate as part Spring Reactive MongoDB and Spring Webflux, I am opening a change stream with the driver, thus not through use of a Realm. Therefore the connections that I am using are not as limited as would be with a Realm.

Do I understand it correctly there?

Correct, the Realm limits are not applicable here, only the standard MongoDB Atlas connection limits.

Much appreciated Drew. That clarifies a lot.