1

It seems that MongoDB Wire Protocol is also used for replication. Not only client/driver connections. Is that true and what are the main differences between client/driver and replication traffic?

The MongoDB Wire Protocol is a simple socket-based, request-response style protocol. Clients communicate with the database server through a regular TCP/IP socket.

1

From a protocol perspective, there is no difference. A really basic way to think of it is this (assuming you start a secondary that is reasonably up to date and is not performing an initial sync):

  • Replication is a client connection from a secondary to the primary
  • That is done using TCP/IP and with the MongoDB wire protocol being used over the top (unless you are using SSL, which would add that to the mix)
  • The secondary creates a tailable cursor and begins streaming the operations from the Oplog
  • The secondary applies these idempotent operations to its data in order to reach the same state as the primary

Now, in reality things are more complicated than that but that gives you a good starting point. You still have to add in multi-threaded replication, replication chaining so that you can replicate from another secondary rather than the primary etc. These are advanced topics which I have given multi-hour whiteboard sessions on (when I worked in MongoDB) and beyond the scope of this answer, not to mention the fact that I am likely out of date with my information at this point.

If you would like to go deeper into how replication works, I recommend the internals posts from Kristina Chodorow (though they are a little dated these days) as well as the various talks the MongoDB engineers have given on the topic (here is one example).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.