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

What's hot (20)

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

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...
MongoDB
 
PPTX
Transaction
Sanjoy Kumar Roy
 
PPTX
MongoDB.local Sydney: How and When to Use Multi-Document Distributed Transact...
MongoDB
 
PDF
MongoDB .local Munich 2019: Distributed Transactions: With Great Power Comes ...
MongoDB
 
PDF
RICON keynote: outwards from the middle of the maze
palvaro
 
PDF
Developer Data Modeling Mistakes: From Postgres to NoSQL
ScyllaDB
 
PDF
MongoDB.local Berlin: How and when to use multi-document transactions
MongoDB
 
PDF
Error Handling with Kafka: From Patterns to Code
HostedbyConfluent
 
PPTX
Paris Kafka Meetup - patterns anti-patterns
Florent Ramiere
 
PDF
Site reliability in the Serverless age - Serverless Boston 2019
Erik Peterson
 
PPTX
Scaling opensimulator inventory using nosql
David Daeschler
 
PDF
What Developers Need to Unlearn for High Performance NoSQL
ScyllaDB
 
PPTX
Scaling Writes on CockroachDB with Apache NiFi
Chris Casano
 
PDF
Cocoa heads 09112017
Vincent Pradeilles
 
ODP
The free lunch is over
Thadeu Russo
 
PPTX
Using chained transactions for maximum concurrency under load (QCONSF 2010)
Billy Newport
 
PDF
Pets vs. Cattle: The Elastic Cloud Story
Randy Bias
 
PDF
Introduction to Cassandra
aaronmorton
 
PPT
Mysql Latency
srubinstein
 
PPTX
MongoDB World 2018: How and When to Use Multi-Document Distributed Transactions
MongoDB
 
MongoDB .local Bengaluru 2019: Distributed Transactions: With Great Power Com...
MongoDB
 
Transaction
Sanjoy Kumar Roy
 
MongoDB.local Sydney: How and When to Use Multi-Document Distributed Transact...
MongoDB
 
MongoDB .local Munich 2019: Distributed Transactions: With Great Power Comes ...
MongoDB
 
RICON keynote: outwards from the middle of the maze
palvaro
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
ScyllaDB
 
MongoDB.local Berlin: How and when to use multi-document transactions
MongoDB
 
Error Handling with Kafka: From Patterns to Code
HostedbyConfluent
 
Paris Kafka Meetup - patterns anti-patterns
Florent Ramiere
 
Site reliability in the Serverless age - Serverless Boston 2019
Erik Peterson
 
Scaling opensimulator inventory using nosql
David Daeschler
 
What Developers Need to Unlearn for High Performance NoSQL
ScyllaDB
 
Scaling Writes on CockroachDB with Apache NiFi
Chris Casano
 
Cocoa heads 09112017
Vincent Pradeilles
 
The free lunch is over
Thadeu Russo
 
Using chained transactions for maximum concurrency under load (QCONSF 2010)
Billy Newport
 
Pets vs. Cattle: The Elastic Cloud Story
Randy Bias
 
Introduction to Cassandra
aaronmorton
 
Mysql Latency
srubinstein
 
MongoDB World 2018: How and When to Use Multi-Document Distributed Transactions
MongoDB
 
Ad

More from MongoDB (20)

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

Recently uploaded (20)

DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 

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