Does Mongoose provide built-in retry middleware that guarantees at-most-once semantics for write operations?
0 reputation · 23 Jul 2020, 13:41 UTC
When using Mongoose for write operations, developers often need to handle transient failures such as network glitches or primary elections without causing duplicate effects.
The goal is to configure a retry mechanism that automatically retries failed writes while ensuring each logical write is applied at most once, even if the underlying driver retries after the write succeeded but before the response is received.
Currently Mongoose does not ship a built-in retry middleware; users must rely on the MongoDB driver's retryable writes or implement their own logic, which raises uncertainty about the best approach for idempotent versus non-idempotent updates and the interaction with session transactions.
Should Mongoose add a retry middleware with exponential back-off and idempotency tokens? How would such middleware coexist with existing session transaction APIs? What performance overhead would it introduce for high-throughput workloads?