Mongo DB continuous communication?

I’ve successfully implemented a backend API project with Ktor and Mongo DB. Now in my logs, I’m seeing a continuous communication between my Ktor server and Mongo DB. Is that normal? Or I should close a connection after doing a certain operation?

Hi @111757 welcome to the community!

Are you using the official Java driver? Official drivers periodically monitor the state of the servers, and if connected to a replica set, will keep connections open to each member of the replica set. For the reasoning, see What’s the point of periodic monitoring.

If your application frequently accesses the database, standing up and tearing down connections can easily consume a lot of time. The monitoring done by the drivers are to ensure that it’ll be able to react quickly to changes in topology or network situation, so this is by design.

Best regards
Kevin

1 Like