Realm does not seem to close mongodb connections on app redeployment


I’ve been experiencing an excessive number of connections on my application compared to the amount of use it gets. (hundreds of connections for under 10 users).

One thing I noticed today is that the connections spike up after I redploy the app as if realm is re-establishing new connections to the atlas cluster. This makes sense, I suppose, but why aren’t the connections dying off?

I currently have 10 database triggers in my application and I’m guessing that they’re persisting even after nobody is on the other side.

This picture shows the number of connections on the primary node; and each spike corresponds with a new deployment. This is ridiculous! I had to upgrade the production cluster on the fly yesterday because we maxed out connections and the entire application fell over.



I’m having the same issue. I tried asking for help, but as always, the chat loves to respond with “We don’ do Realm support, please purchase… blah blah blah”.

I guess my Realm app doesn’t connect with Atlas huh??
The question is directed to Atlas connections, therefore, it’s an Atlas question.

I had to completely turn up a new Project, Cluster, App and all (a few hours to get it all working correctly), to test what the problem is.

Here is a screenshot of the newly created app as of today 9.10.21
The huge spike is when I logged into my realm app from the browser. It went from 15 to 50 with ONE SINGLE USER!!

I’ll post another comment with the existing app.

1 Like

Here is my existing app. Over 48 hours, I stopped logging in and committing any new changes. The connections never started dropping until I DELETED MY APP!! and re-deployed as the new one above.

It went from 0 to 200 connections in 24 hours of me doing some dev testing and pushing commits. Again this is with ONLY ONE USER.

This is the first time I have seen this issue. So my guess is somewhere on MongoDB’s side they’ve change something for the worse. Because I have changed anything!!!

Very frustrating!

1 Like

Hello everybody! I’m very excited to be of assistance!

I’m Brock, I am one of the Technical Service Engineers for MongoDB Realm. Please allow me to explain what in particular you’re seeing if I may.

Short summary:
So simply put, the connections themselves aren’t client connections that you’re seeing. What you’re seeing is a series of redundant connection pathways that are waiting on more and more clients. As you get more clients the connections will begin to even out and disperse to balance the loads of an ever increasing number of clients. (Clients = Users/Devices/Instances of your app)

General points:

  • End user applications connect to Realm and Realm will connect to Atlas and share/manage connections as your app grows. Sometimes this leads to higher numbers of connections when numbers of users are small, but connections are efficiently shared at scale.
  • Sometimes a cluster change, Realm app deployment, or change in application behavior can cause a change in connections, but Realm releases unused connections regularly.
  • Users can scale up clusters for higher connection limits/resources.

In long summary:
If you are using Realm Triggers/functions/Sync, connection count in Atlas connections will increase but that should stabilise after some time(10-15 minutes) of no activity.

If you continue to experience any further issues with the connections not being released by the Realm application please let us know Realm app link and we would be happy to look into this further.

Realm internally proxies connection by default and keeps them open across multiple invocations so this will definitely be more efficient with connection utilization and may actually be more performant on average (less of a latency hit for opening new connections). Realm generally opens a single connection pool per Realm host and manages connections at the Realm host-level.

Further new devices connecting to Realm may not result in a new connection being made to Atlas from Realm Servers, it may re-use a connection.

So in another way to explain in short summary, connections count is not directly proportional on either the number of clients or the number of currently open Realms. Some unused connections can stay active on Atlas and later be reused by another Realm client.

To minimize the number of concurrent listening clients and open change streams:

  • Start Watch and Sync operations only when necessary.
  • Close any open Watch and Sync streams immediately when they’re no longer necessary.
  • Avoid data models that require you to Watch or Sync an unbounded number of collections.

Same here. The number of connections does not drop with time. I even could not perform all the tests I wanted without a notification regarding 500 connections were reached (with just an Android App and a WebHook). I wonder how many connections I would need when the system will be completely in use…

1 Like

Yes, I have bought payed plan about 100$/month to increate number of acceptable connections.
Seems dev will not solve (and don’t like to) this issue to keep more money.

I did a lot of stuff, starting from ip address separation to code review. But nothing changed, I have always 80%+ connections open.

Hello @Il_Chi,

Thank you for raising your query and apologies for the experience.

I am Community Manager for Realm and your feedback is important to us. Could you share your Realm App Id and I will take a look at what is causing the connections to increase?

I look forward to your response.

Kind Regards,

1 Like

This appears to be your request Id. You can get your Realm App Id from the cloud project Dashboard. The same Id is added to your mobile app to connect the client with the server.

I hope this helps. Look forward to your response.


Hello @Il_Chi,

I noticed your Atlas Cluster is on Azure in Zurich and you created 3 Atlas Triggers. When you create Triggers from the Atlas tab, the Realm Triggers App is automatically created. The default region is Virginia east while cloud provider is AWS for Realm at the moment.

I would recommend creating a Realm App from the Realm tab closer to your cluster region (Frankfurt perhaps) and with a local deployment model. After that you can create Triggers from the Realm UI Page.
Learn More.

Kind Regards,

1 Like

I can’t believe this is still a problem. It seems that the team really don’t bother to solve that and make people upgrade just because of that issue.