Course contentsShow
← System Design
Lesson 406 of 1,91911. NoSQL: Document StoresFree lesson

Complex Transaction Requirements

Why document stores struggle with multi-document ACID transactions compared to relational databases.

Complex Transaction Requirements

What you'll learn: Why document stores struggle to handle complex, multi-document transactions compared to relational databases.

The Transaction Challenge

In relational databases, ACID transactions spanning multiple rows across multiple tables are straightforward and guaranteed by design. Document stores like MongoDB traditionally offered ACID guarantees only within a single document. When your application needs to update multiple documents atomically—ensuring all changes succeed together or all fail—document stores face significant challenges.

Why This Is Hard for Document Stores

Document stores are optimized for flexible schemas and horizontal scaling through sharding. Coordinating multi-document transactions across different shards requires complex distributed coordination protocols (like two-phase commit), which conflict with the performance and availability goals these databases prioritize.

Example scenario: Imagine transferring money between two user accounts stored as separate documents. You need to:

  1. Deduct from Account A
  2. Add to Account B
  3. Record the transaction in a ledger document

If any step fails midway, you risk inconsistent data. Traditional document stores couldn't guarantee all three operations complete atomically.

Modern Improvements

Newer versions of MongoDB (4.0+) added multi-document ACID transactions, but they come with performance penalties and work best when transactions stay within a single shard. They're available but not the database's sweet spot.

When This Matters

If your application frequently requires complex transactions spanning many documents—like financial systems, inventory management with reservations, or order processing with multiple state updates—a relational database or NewSQL system is often the better architectural choice.

Key Takeaway: Document stores excel at single-document operations but struggle with complex multi-document transactions; when atomicity across many records is central to your application, relational or NewSQL databases typically provide better native support with less complexity.