SlideShare a Scribd company logo
MongoDB: A New Transactional Model
keith.bostic@mongodb.com
Keith Bostic
keith.bostic@mongodb.com
Distinguished Engineer, MongoDB Inc.
Welcome!
MongoDB: A New Transactional Model
keith.bostic@mongodb.com
Review & Motivations
Relational vs document data modeling
Goals: performance and complexity
Goals:
application domains, programmer models
Goals: checkboxes and vendor lock-in
Application developers are the focus
But not the only audience
“ACID transactions are a key capability for business critical
transactional systems, specifically around commerce processing.
No other database has both the power of NoSQL and cross
collection ACID transaction support.This combination will make it
easy for developers to write mission critical applications leveraging
the power of MongoDB.”
-- Dharmesh Panchmatia,
Director of E-commerce, Cisco Systems
ACID
Transactions: Acid
Transactions: aCid
Consistency, availability, partition tolerance
Transactions: acId
Transactions: aciD
MongoDB World talk!
Transactions and Durability: Putting the “D” in ACID
-- Sue LoVerso, Senior Engineer, MongoDB
The Path
Multi-year, all-hands company effort
• The storage layer,
Multi-year, all-hands company effort
• The storage layer,
• Sharding architecture,
Multi-year, all-hands company effort
• The storage layer,
• Sharding architecture,
• Introducing a global logical clock,
Multi-year, all-hands company effort
• The storage layer,
• Sharding architecture,
• Introducing a global logical clock,
• Replication consensus protocol,
Multi-year, all-hands company effort
• The storage layer,
• Sharding architecture,
• Introducing a global logical clock,
• Replication consensus protocol,
• Metadata management,
… and that’s just part of the list!
Multi-year, all-hands company effort
• The storage layer,
• Sharding architecture,
• Introducing a global logical clock,
• Replication consensus protocol,
• Metadata management,
… and that’s just part of the list!
Not forgetting the driver teams, documentation and education.
MongoDB 2.6: mmapv1 with ACID
2.6
P
S
S
S
The “storage engine” is part of the MongoDB database server.
It’s where the actual data lives.
Detour: the storage engine
networking, sharding, replication, drivers
analytics, middleware, query optimizer
storage engine
Detour: the storage engine
Single
Node
MongoDB’s pluggable storage architecture
• MMAPv1
• RocksDB (Facebook)
• TokuMX (TokuTek)
• WiredTiger
MongoDB 3.0: a new storage engine
2.6 3.0
B-D
Keys
E-I
Keys
J-N
Keys
F Keys &
Values
E Keys &
Values
G Keys &
Values
Write-heavy workloads
Document level locking
Compaction
Encryption
Compression
In-Memory
MongoDB 3.0: transactional features
2.6 3.0
MongoDB 3.2
P
S
S
S:w “majority”
readConcern
2.6 3.0 3.2
MongoDB 3.4
2.6 3.0 3.43.2
MongoDB 3.6: transactional features
2.6 3.0 3.63.43.2
P
S
S
S
logical sessions
global clock
… leads to causal consistency
MongoDB 3.6: enhanced consistency
2.6 3.0 3.63.43.2
P
S
S
S
secondary reads
retryable writes
read concern majority
MongoDB University video
Implementation of Cluster-Wide Causal Consistency in MongoDB
-- Misha Tyulenev, Engineer, MongoDB
MongoDB 4.0: multi-document transactions
2.6 3.0 3.63.43.2 4.0
P
S
S
S
MongoDB 4.0: prepared transactions
2.6 3.0 3.63.43.2 4.0
Commit?
Yes
Yes
Commit!
Phase One Phase Two
MongoDB 4.X
2.6 3.0 3.63.43.2 4.0
P
S
S
S
PS
S
4.X
MongoDB World talk!
What’s Next? The Path to Sharded Transactions
-- Andy Schwerin, VP, Engineering, MongoDB
Why is this work hard?
Reason #1:
single-node ordering vs. group ordering
MongoDB WiredTiger
Replication example
... 37 38 39
... 37 38 39
... 37 38 39
... 37 38 39
Primary Oplog
Secondary reads
Multi-threaded secondary oplog application
OpLog
... 37 38 39 40 4241
Primary oplog order
Secondary apply order
40 39 41 38
“People assume that time is a strict progression
of cause to effect, but actually, from a non-linear,
non-subjective point of view, it is more like a big
ball of wibbily-wobbly timey-wimey … stuff.”
-- Doctor Who
Reason #2: increasing entanglement
Getting the right answer requires communication.
Timestamps
MongoDB’s timestamp
... 40 4138 39 42
ACID for a set of systems
durability based on replication
WiredTiger’s transaction ID
... 40 4138 39 42
ACID for a single-node
durability based on checkpoints and journaling
MongoDB timestamp overrides WiredTiger ID
64-bit counter
fast comparisons
strictly increasing
MSB hex API
MongoDB secondary example
Set the timestamp at update or commit
OpLog
... 37 38 39 40 4241
Primary oplog order
Secondary timestamp order
... 37 38 39 40 4241
Timestamp stored with each MVCC update
FRUIT
mango
apple
banana
TXN ID
TIMESTAMP
Overlapping reads with oplog application
Secondary timestamp order
... 37 38 39 40 4241
Timestamp #1 Timestamp #2
3.6
4.0
Blocking
Parallel
Queries can be “as of” a timestamp
set at transaction begin
largest LTE value
The “oldest” timestamp
Durability based on the “stable” timestamp
Replication rollback for a single server
... 37 38 39 40 4241
Primary Oplog
... 37 38 39 117 119118
Corrected (Secondary) Oplog
Replacements
The “stable” timestamp
Sydney & New York
Keith Bostic
keith.bostic@mongodb.com
Distinguished Engineer, MongoDB Inc.
Thank you!
WiredTiger and transactions
• Per-thread “session” structure embodies a transaction
WiredTiger and transactions
• Per-thread “session” structure embodies a transaction
• Session structure references data-sources: cursors
WiredTiger and transactions
• Per-thread “session” structure embodies a transaction
• Session structure references data-sources: cursors
• Transactions are implicit or explicit (scope determined by the application)
• session.begin_transaction()
• session.commit_transaction()
• session.rollback_transaction() // Abort
• Transactions could always span objects and data-sources
Sample key-value store CRUD transaction
cursor = session.open_cursor(“some collection”);
session.begin_transaction();
Sample key-value store CRUD transaction
cursor = session.open_cursor(“some collection”);
session.begin_transaction();
cursor.set_key(“fruit”);
cursor.set_value(“apple”);
cursor.insert();
Sample key-value store CRUD transaction
cursor = session.open_cursor(“some collection”);
session.begin_transaction();
cursor.set_key(“fruit”);
cursor.set_value(“apple”);
cursor.insert();
cursor.set_key(“fruit”);
cursor.set_value(“banana”);
cursor.update();
Sample key-value store CRUD transaction
cursor = session.open_cursor(“some collection”);
session.begin_transaction();
cursor.set_key(“fruit”);
cursor.set_value(“apple”);
cursor.insert();
cursor.set_key(“fruit”);
cursor.set_value(“banana”);
cursor.update();
session.commit_transaction();
cursor.close();
MongoDB on top of WiredTiger
• MongoDB maps the document model on top of this key/value model
• For example
• A single document change involves indexes
• Multiple cursors updating a collection and its indexes
• Glue layer below the pluggable storage API
• 14K lines of code
WiredTiger transaction information
• 64-bit transaction ID
WiredTiger transaction information
• 64-bit transaction ID
• Isolation level and other snapshot information
• Read-uncommitted: everything
• Read-committed: committed updates after start
• Snapshot: committed updates as of start
WiredTiger transaction information
• 64-bit transaction ID
• Isolation level and snapshot information
• Read-uncommitted: everything
• Read-committed: committed updates after start
• Snapshot: committed updates as of start
• Linked list of change records
• For logging on commit, discard on rollback
MongoDB 4.0
• Multi-document transactions in a replica set
• Storage engine support for prepared transactions
• Replica set point-in-time reads
• Recovery to a timestamp
• Performance enhancement so operations only rolled forward
Right the order in getting
... 37 38 39
... 37 39 38
Oplog
WiredTiger Operations
The storage problem is concurrency control
• Engines support lots of concurrency to increase throughput
• Traditionally, the storage layer decides how operations interleave
Well, there’s durability as well
• Engines support lots of concurrency to increase throughput
• Traditionally, the storage layer decides how operations interleave
• The storage layer is also responsible for single-node crash recovery
If the storage layer owns concurrency and durability
… the rest of the system can ignore the details
Future use of timestamps: 4.0++
• Global snapshot reads
• 2-phase commit for transactions that span shards
• Unified oplog and WiredTiger journal
• Reducing pain of write amplification
• Originally 4 data copies (oplog and collection, plus 2 x journal)
Background: majority commits
... 37 38 39
... 37 38 39
... 37 38 39
... 37 38 39
Primary Oplog
Secondary reads
WiredTiger
• Multi-row and multi-table transactions
• Document level locking
• Multi-version concurrency control (MVCC)
FRUIT
MANGO
APPLE
BANANA
Future use of timestamps: 4.0++
• Global snapshot reads
2-phase commit for transactions that span shards
Rollback all changes if any shard cannot commit
Make commits visible at a common timestamp across shards

More Related Content

PDF
MongoDB World 2018: Transactions and Durability: Putting the “D” in ACID
PPTX
MongoDB World 2018: MongoDB for High Volume Time Series Data Streams
PDF
MongoDB .local Bengaluru 2019: New Encryption Capabilities in MongoDB 4.2: A ...
PPT
MongoDB World 2018: From Disruption to Transformation: Document Databases, Do...
PPTX
Securing Your Enterprise Web Apps with MongoDB Enterprise
PPTX
Managing Cloud Security Design and Implementation in a Ransomware World
PDF
MongoDB .local Chicago 2019: Modern Data Backup and Recovery from On-premises...
PPTX
Introducing Stitch
MongoDB World 2018: Transactions and Durability: Putting the “D” in ACID
MongoDB World 2018: MongoDB for High Volume Time Series Data Streams
MongoDB .local Bengaluru 2019: New Encryption Capabilities in MongoDB 4.2: A ...
MongoDB World 2018: From Disruption to Transformation: Document Databases, Do...
Securing Your Enterprise Web Apps with MongoDB Enterprise
Managing Cloud Security Design and Implementation in a Ransomware World
MongoDB .local Chicago 2019: Modern Data Backup and Recovery from On-premises...
Introducing Stitch

What's hot (20)

PDF
Engineering an Encrypted Storage Engine
PPTX
It's a Dangerous World
PPTX
Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB
PDF
MongoDB .local Bengaluru 2019: Using MongoDB Services in Kubernetes: Any Plat...
PPTX
How Thermo Fisher is Reducing Data Analysis Times from Days to Minutes with M...
PPTX
Managing Multi-Tenant SaaS Applications at Scale
PDF
MongoDB .local Bengaluru 2019: The Journey of Migration from Oracle to MongoD...
PDF
MongodB Internals
PDF
Webinar: Schema Patterns and Your Storage Engine
PPTX
Webinar: Compliance and Data Protection in the Big Data Age: MongoDB Security...
PDF
Introducing MongoDB Stitch, Backend-as-a-Service from MongoDB
PDF
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
PDF
MongoDB Ops Manager + Kubernetes
PPTX
Webinar: Enabling Microservices with Containers, Orchestration, and MongoDB
PPTX
Webinar: Choosing the Right Shard Key for High Performance and Scale
PPTX
WiredTiger Overview
PDF
https://docs.google.com/presentation/d/1DcL4zK6i3HZRDD4xTGX1VpSOwyu2xBeWLT6a_...
PPTX
Sizing Your MongoDB Cluster
PPTX
Getting Started with MongoDB Using the Microsoft Stack
PPTX
Cloud Backup Overview
Engineering an Encrypted Storage Engine
It's a Dangerous World
Powering Microservices with Docker, Kubernetes, Kafka, and MongoDB
MongoDB .local Bengaluru 2019: Using MongoDB Services in Kubernetes: Any Plat...
How Thermo Fisher is Reducing Data Analysis Times from Days to Minutes with M...
Managing Multi-Tenant SaaS Applications at Scale
MongoDB .local Bengaluru 2019: The Journey of Migration from Oracle to MongoD...
MongodB Internals
Webinar: Schema Patterns and Your Storage Engine
Webinar: Compliance and Data Protection in the Big Data Age: MongoDB Security...
Introducing MongoDB Stitch, Backend-as-a-Service from MongoDB
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB Ops Manager + Kubernetes
Webinar: Enabling Microservices with Containers, Orchestration, and MongoDB
Webinar: Choosing the Right Shard Key for High Performance and Scale
WiredTiger Overview
https://docs.google.com/presentation/d/1DcL4zK6i3HZRDD4xTGX1VpSOwyu2xBeWLT6a_...
Sizing Your MongoDB Cluster
Getting Started with MongoDB Using the Microsoft Stack
Cloud Backup Overview
Ad

Similar to MongoDB World 2018: Building a New Transactional Model (20)

PPTX
A New Transactional Model - Keith Bostic
PDF
MongoDB and Machine Learning with Flowable
PPTX
MongoDB 101 & Beyond: Get Started in MongoDB 3.0, Preview 3.2 & Demo of Ops M...
PDF
MongoDB Days UK: Scaling MongoDB with Docker and cgroups
PPT
Webinar: High Performance MongoDB Applications with IBM POWER8
PDF
IBM Blockchain Platform - Architectural Good Practices v1.0
PPTX
Running MongoDB 3.0 on AWS
PPTX
What's new in MongoDB 3.6?
PPTX
Agility and Scalability with MongoDB
PPTX
MongoDB vs Scylla: Production Experience from Both Dev & Ops Standpoint at Nu...
PPTX
How Thermo Fisher Is Reducing Mass Spectrometry Experiment Times from Days to...
PPTX
Mastering MongoDB on Kubernetes, the power of operators
PPT
5 Pitfalls to Avoid with MongoDB
PPTX
Novedades de MongoDB 3.6
PDF
MongoDB WiredTiger Internals: Journey To Transactions
PPTX
Conceptos básicos. Seminario web 6: Despliegue de producción
PPT
MongoDB Sharding Webinar 2014
PPTX
MongoDB World 2018: Breaking the Mold - Redesigning Dell's E-Commerce Platform
PDF
MongoDB Europe 2016 - Powering Microservices with Docker, Kubernetes, and Kafka
PDF
Let the Tiger Roar - MongoDB 3.0
A New Transactional Model - Keith Bostic
MongoDB and Machine Learning with Flowable
MongoDB 101 & Beyond: Get Started in MongoDB 3.0, Preview 3.2 & Demo of Ops M...
MongoDB Days UK: Scaling MongoDB with Docker and cgroups
Webinar: High Performance MongoDB Applications with IBM POWER8
IBM Blockchain Platform - Architectural Good Practices v1.0
Running MongoDB 3.0 on AWS
What's new in MongoDB 3.6?
Agility and Scalability with MongoDB
MongoDB vs Scylla: Production Experience from Both Dev & Ops Standpoint at Nu...
How Thermo Fisher Is Reducing Mass Spectrometry Experiment Times from Days to...
Mastering MongoDB on Kubernetes, the power of operators
5 Pitfalls to Avoid with MongoDB
Novedades de MongoDB 3.6
MongoDB WiredTiger Internals: Journey To Transactions
Conceptos básicos. Seminario web 6: Despliegue de producción
MongoDB Sharding Webinar 2014
MongoDB World 2018: Breaking the Mold - Redesigning Dell's E-Commerce Platform
MongoDB Europe 2016 - Powering Microservices with Docker, Kubernetes, and Kafka
Let the Tiger Roar - MongoDB 3.0
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: 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...
PDF
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
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...
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Electronic commerce courselecture one. Pdf
PPT
Teaching material agriculture food technology
PPTX
Cloud computing and distributed systems.
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Machine learning based COVID-19 study performance prediction
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Empathic Computing: Creating Shared Understanding
20250228 LYD VKU AI Blended-Learning.pptx
Programs and apps: productivity, graphics, security and other tools
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Spectroscopy.pptx food analysis technology
Review of recent advances in non-invasive hemoglobin estimation
Mobile App Security Testing_ A Comprehensive Guide.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Encapsulation_ Review paper, used for researhc scholars
Advanced methodologies resolving dimensionality complications for autism neur...
Spectral efficient network and resource selection model in 5G networks
Dropbox Q2 2025 Financial Results & Investor Presentation
The Rise and Fall of 3GPP – Time for a Sabbatical?
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Electronic commerce courselecture one. Pdf
Teaching material agriculture food technology
Cloud computing and distributed systems.
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Machine learning based COVID-19 study performance prediction
NewMind AI Weekly Chronicles - August'25 Week I
Empathic Computing: Creating Shared Understanding

MongoDB World 2018: Building a New Transactional Model