Distributed systems are inherently challenging to build reliable applications with. This applies to MongoDB and to any database system. For many years, MongoDB application developers have demanded a way to make their code resilient in the face of errors. There transient errors, long-lasting errors, and command failures. How should you code an application to be resilient in the face of these? Let's consider a simple operation: you want to increment a counter by 1. How can you do it reliably? There are a lot of bad strategies in the wild. Most code doesn't try to handle errors at all, which risks losing an update when there's an error. Almost as popular is code that retries every operation 5 or 10 times. This risks over-counting, or else wasting time retrying an operation when there's an unrecoverable error. There is a smart strategy, however. First, transform your schema and your operations so that all operations are idempotent. Second, write your code to retry exactly once after a network error. This strategy is correct and efficient in the face of all three kinds of errors.
A. Jesse Jiryu Davis, Staff Software Engineer, MongoDB
MongoDB Europe 2016