Quick Answer
Distributed transactions across shards use a two-phase commit coordinated by a transaction coordinator (runs on the mongos or shard). Phase 1: all shards prepare and lock resources. Phase 2: all shards commit or abort. This adds significant latency and lock contention. Keep cross-shard transactions short, or redesign schema to avoid them - keep related data on the same shard via shard key design.
Answer
MongoDB uses two-phase commit across shards to ensure atomic multi-shard updates, preventing partial writes.
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.
MongoDB interview questions and answers for beginner, junior, mid-level, senior, and expert developers. Perfect for freshers and experienced candidates.