SlideShare a Scribd company logo
Distributed Transactions: with Great
Power Comes Great Responsibility
Alyson Cabral, Product Manager
@aly_cabral
I know what you’re thinking…
@aly_cabral
But, Really…
MongoDB Transactions are ACID Compliant
(yes, even across shards)
@aly_cabral
Transactions make application
development easier
1. Don’t need to worry about interim states
2. Rollback/Abort is handled automatically
3. Point-in-time consistency
@aly_cabral
def insertDocuments(s):
s.client.db.col.insert_one({'abc': 1}, session=s)
s.client.db.col.insert_one({'xyz': 999}, session=s)
with client.start_session() as s:
s.with_transaction(insertDocuments);
New API in MongoDB 4.2!
@aly_cabral
Transactions Guarantees
@aly_cabral
Multi- Collection
Database
Statement
Document
Shard
@aly_cabral
All or Nothing Execution
TXN
Application
MongoDB
Uncommitted Writes
{ Document 1 } { Document 2 }
{ Document 3 }
Committed Writes
@aly_cabral
Snapshot Isolation
100 101 102 103 104 105 106 107 108 109 110 111
Snapshot
102
Snapshot
108
@aly_cabral
Read Your Own Writes
Operation
Read
TXN
{_id: “OWNER12345”,
name: { first: “Aly”,
last: “Cabral”},
accountType: “Paid”,
pets: [ { type: “Dog”,
name: “Lady”}],
contact: { phoneNumber: 8008675309},
Address: { city: “New York”,
street: “94th”,
zipecode: 10025}}
Uncommitted Writes
street: “92nd”
Address.street = 94th
Address.street = 92nd
@aly_cabral
Transactions Guidelines
@aly_cabral
1) All data modeling rules still apply
2) Transactions should not be the most common
operation (sanity check for rule 1)
3) Pass in the session to all statements
4) Implement retry logic, transactions can always
abort
5) Don’t unnecessarily leave snapshots open
6) To trigger write conflicts, make sure you’re doing
writes
7) Plan for DDL Operations
@aly_cabral
Distributed Transactions Workflow
@aly_cabral
Majority Writes
No Arbiters!
@aly_cabral
P
S
S
S
S
Participant
any shard that executes operations on behalf of a
given transaction
Coordinator
A single shard that is responsible for coordinating
the commit across shards for a given transaction
@aly_cabral
P
S
S
S
P
S
Query Router
Insert {_id : “abc”}Insert {_id : “xyz”}
Coordinator!
Commit transaction
@aly_cabral
“ We see at least 2x performance
improvement when running MongoDB
transactions vs logic on our own, in-
app”
Imagine a world without transactions
@aly_cabral
For even better perf results… collocate the data
@aly_cabral
If you cannot collocate, write to a single shard
@aly_cabral
READS WRITESREADS
Read Isolation
@aly_cabral
READ CONCERN = READ ISOLATION
Options: LOCAL, MAJORITY,
SNAPSHOT, LINEARIZABLE
Fun Fact: ReadConcern: Majority does not need to
coordinate across nodes to return results!
@aly_cabral
Read Concern: Snapshot
P
S
S
P
S
S
P
S
S
time: 102
Majority
or
Local
time: 102 time: 110 time: 104
@aly_cabral
Locking
@aly_cabral
@aly_cabral
TXN
Write
TXN
Write
{Doc 1}
TXN write is unable to obtain a write lock!
TXN is ABORTED
rolledback entirely
@aly_cabral
TXN
Write
Operation
Non-Transactional Write
{Doc 1}
Operation Blocks Behind TXN Commit
Infinitely retries with Backoff Logic until MaxTimeMS is reached
Operation non-transactional write is unable to obtain a write lock!
@aly_cabral
When non-transactional writes encounter
write conflicts
Operation Blocks Behind TXN Commit
Infinitely retries with Backoff Logic until MaxTimeMS is reached
When transactions encounter write
conflicts
Transactions abort
rollback entirely
@aly_cabral
TXN
Read
TXN
Write
{Doc 1}
Reads do not lock a document from being modified
Only writes make write conflicts
More New Functionality in 4.2
@aly_cabral
Transactions Larger than 16MB
In MongoDB 4.0:
@aly_cabral
{<statement 1>}
{<statement 2>}
{<statement 3>}
{<statement 4>}
In MongoDB 4.2:
{<statement 1>,
<statement 2>,
<statement 3>,
<statement 4>}
This does not mean you can have
infinitely large transactions --
• WT still has to maintain the history since the snapshot
time
• Transactions have the same snapshot throughout the
duration of the transaction
• Transactions automatically abort after 60 seconds –
TUNABLE. transactionLifetimeLimitSeconds
@aly_cabral
Mutable Shard Key Values
Tiered storage: Aging out older documents to low cost
storage shard
• Global-redistribution: Rehoming documents to a new
region
@aly_cabral
ShardShard
• Use MongoDB 4.2 drivers
• Transactions targeting a single shard will be faster than those
spanning multiple shards
• Best practice: No more than 1,000 documents modified in a
single transaction
• No arbiters
• Chunk migrations will block behind running transactions
@aly_cabral
Parting Wisdom
ATLAS CODE:
MONGODB4DOT2
@aly_cabral
• Free ▪ Online ▪ 9 Chapters
• Register Now! - https://university.mongodb.com/courses/M042/about
@aly_cabral
Thank You!
MongoDB. local Houston 2019: Distributed Transactions: With Great Power Comes Great Responsibility [MongoDB]

More Related Content

PPTX
MongoDB World 2019: Distributed Transactions: With Great Power Comes Great Re...
PDF
MongoDB .local Bengaluru 2019: Distributed Transactions: With Great Power Com...
PDF
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
PDF
Exactly Once Delivery with Kafka - Kafka Tel-Aviv Meetup
PDF
I/O intensiveなKafka ConsumerアプリケーションのスループットをLINE Ads Platformではどのように改善したか
PDF
Node withoutservers aws-lambda
PDF
Building Thick Clients with Tower in Rust
PDF
Serverless architecture: introduction & first steps
MongoDB World 2019: Distributed Transactions: With Great Power Comes Great Re...
MongoDB .local Bengaluru 2019: Distributed Transactions: With Great Power Com...
Serverless Framework Workshop - Tyler Hendrickson, Chicago/burbs
Exactly Once Delivery with Kafka - Kafka Tel-Aviv Meetup
I/O intensiveなKafka ConsumerアプリケーションのスループットをLINE Ads Platformではどのように改善したか
Node withoutservers aws-lambda
Building Thick Clients with Tower in Rust
Serverless architecture: introduction & first steps

What's hot (20)

PDF
Microservices on .NET
PDF
Cortex: Prometheus as a Service, One Year On
PDF
Perfug 20-11-2019 - Kafka Performances
PPTX
Become Thanos of the LambdaLand: Wield all the Infinity Stones
PDF
Things you wish you never knew about the Prometheus Remote Write API.
PDF
Greyhound - Powerful Pure Functional Kafka Library
PPTX
Serverless by examples and case studies
PDF
Solutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
PDF
Devoxx university - Kafka de haut en bas
PPTX
Apache Kafka - Patterns anti-patterns
PDF
Via Varejo taking data from legacy to a new world at Brazil Black Friday (Mar...
PDF
Graphs: Fabric of DevOps
PPTX
Apache Incubator Samza: Stream Processing at LinkedIn
PPTX
Serverless GraphQL. AppSync 101
PDF
Compute @ edge
PPTX
Kafka Summit NYC 2017 - Data Processing at LinkedIn with Apache Kafka
PDF
JavaDay Lviv: Serverless Archtiectures
PDF
Docker Container automatisiert nach AWS deployen - Continuous Lifecycle 2016
PDF
Securing the Message Bus with Kafka Streams | Paul Otto and Ryan Salcido, Raf...
PDF
Lagom - Mircoservices "Just Right"
Microservices on .NET
Cortex: Prometheus as a Service, One Year On
Perfug 20-11-2019 - Kafka Performances
Become Thanos of the LambdaLand: Wield all the Infinity Stones
Things you wish you never knew about the Prometheus Remote Write API.
Greyhound - Powerful Pure Functional Kafka Library
Serverless by examples and case studies
Solutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Devoxx university - Kafka de haut en bas
Apache Kafka - Patterns anti-patterns
Via Varejo taking data from legacy to a new world at Brazil Black Friday (Mar...
Graphs: Fabric of DevOps
Apache Incubator Samza: Stream Processing at LinkedIn
Serverless GraphQL. AppSync 101
Compute @ edge
Kafka Summit NYC 2017 - Data Processing at LinkedIn with Apache Kafka
JavaDay Lviv: Serverless Archtiectures
Docker Container automatisiert nach AWS deployen - Continuous Lifecycle 2016
Securing the Message Bus with Kafka Streams | Paul Otto and Ryan Salcido, Raf...
Lagom - Mircoservices "Just Right"
Ad

Similar to MongoDB. local Houston 2019: Distributed Transactions: With Great Power Comes Great Responsibility [MongoDB] (20)

PDF
MongoDB .local Bengaluru 2019: Distributed Transactions: With Great Power Com...
PDF
MongoDB .local Munich 2019: Distributed Transactions: With Great Power Comes ...
PDF
MongoDB.local Berlin: How and when to use multi-document transactions
PPTX
MongoDB World 2018: How and When to Use Multi-Document Distributed Transactions
PPTX
How and When to Use Multi-Document Distributed Transactions
PPTX
MongoDB.local Dallas 2019: How and When to Use Multi-Document Distributed Tra...
PPTX
MongoDB.local Austin 2018: How and When to Use Multi-Document Distributed Tr...
PPTX
MongoDB.local DC 2018: How and When to Use Multi-Document Distributed Transac...
PPTX
MongoDB.local Seattle 2019: How and When to Use Multi-Document Distributed Tr...
PPTX
MongoDB.local Sydney: How and When to Use Multi-Document Distributed Transact...
PPTX
How and When to Use Transactions - Aly Cabral
PPTX
Are Transactions Right For You? Using and Not Abusing Transactions
PPTX
How and When to Use Multi-Document Distributed Transactions
PDF
MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...
PDF
To Transact or Not to Transact
PPTX
MongoDB World 2018: What's Next? The Path to Sharded Transactions
PPTX
Sharding in MongoDB 4.2 #what_is_new
PDF
MongoDB - How to model and extract your data
PPTX
Mongo db tips and advance features
PDF
MongoDB World 2018: Building a New Transactional Model
MongoDB .local Bengaluru 2019: Distributed Transactions: With Great Power Com...
MongoDB .local Munich 2019: Distributed Transactions: With Great Power Comes ...
MongoDB.local Berlin: How and when to use multi-document transactions
MongoDB World 2018: How and When to Use Multi-Document Distributed Transactions
How and When to Use Multi-Document Distributed Transactions
MongoDB.local Dallas 2019: How and When to Use Multi-Document Distributed Tra...
MongoDB.local Austin 2018: How and When to Use Multi-Document Distributed Tr...
MongoDB.local DC 2018: How and When to Use Multi-Document Distributed Transac...
MongoDB.local Seattle 2019: How and When to Use Multi-Document Distributed Tr...
MongoDB.local Sydney: How and When to Use Multi-Document Distributed Transact...
How and When to Use Transactions - Aly Cabral
Are Transactions Right For You? Using and Not Abusing Transactions
How and When to Use Multi-Document Distributed Transactions
MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...
To Transact or Not to Transact
MongoDB World 2018: What's Next? The Path to Sharded Transactions
Sharding in MongoDB 4.2 #what_is_new
MongoDB - How to model and extract your data
Mongo db tips and advance features
MongoDB World 2018: Building a New Transactional Model
Ad

More from MongoDB (20)

PDF
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
PDF
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
PDF
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
PDF
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
PDF
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
PDF
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
PDF
MongoDB SoCal 2020: MongoDB Atlas Jump Start
PDF
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
PDF
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
PDF
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
PDF
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
PDF
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
PDF
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
PDF
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
PDF
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
PDF
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
PDF
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
PDF
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Spectroscopy.pptx food analysis technology
PPTX
A Presentation on Artificial Intelligence
PDF
Empathic Computing: Creating Shared Understanding
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPT
Teaching material agriculture food technology
PDF
Electronic commerce courselecture one. Pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Approach and Philosophy of On baking technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Weekly Chronicles - August'25-Week II
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
The AUB Centre for AI in Media Proposal.docx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectroscopy.pptx food analysis technology
A Presentation on Artificial Intelligence
Empathic Computing: Creating Shared Understanding
20250228 LYD VKU AI Blended-Learning.pptx
Teaching material agriculture food technology
Electronic commerce courselecture one. Pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Network Security Unit 5.pdf for BCA BBA.
“AI and Expert System Decision Support & Business Intelligence Systems”
Spectral efficient network and resource selection model in 5G networks
Approach and Philosophy of On baking technology
Dropbox Q2 2025 Financial Results & Investor Presentation
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Review of recent advances in non-invasive hemoglobin estimation
Encapsulation_ Review paper, used for researhc scholars
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

MongoDB. local Houston 2019: Distributed Transactions: With Great Power Comes Great Responsibility [MongoDB]