Skip to main content

Why is two-phase commit expensive in MongoDB, and when should you avoid it?

Expert MongoDB
Quick Answer Two-phase commit (2PC) across shards in MongoDB is expensive because: it requires locking resources on multiple shards simultaneously, increases latency (two round trips across network to all participating shards), increases conflict and abort rate under high concurrency, and mongos must coordinate all phases. Avoid cross-shard transactions by designing data locality - put data that changes together on the same shard.

Answer

Two-phase commit requires cross-shard coordination and oplog tracking, increasing latency and resource usage. Avoid unless strict multi-document atomicity is required.
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice