SlideShare a Scribd company logo
1 of 40
#MDBlocal
Using Change Streams to
Keep Up With Your Data
Asya Kamsky, Lead Product Manager
#MongoDB @MDBLocal @asya999 #askAsya
#MDBlocal
Using Change Streams to
Keep Up With Your Data
Asya Kamsky, Lead Product Manager
#MongoDB @MDBLocal @asya999 #askAsya
#MDBlocal
“TIME IS MONEY.”
B E N J A M I N F R A N K L I NW A R R E N B U F F E T
#MDBlocal
REAL-TIME IS AN EXPECTATION
#MDBlocal
MongoD
B
Action
Handler
#MDBlocal
const changeStream=
db.collection('temperature').watch();
c h a n g e S t r e a m . o n ( ' c h a n g e ' , f u n c t i o n ( c h a n g e ) {
c o n s o l e . l o g ( c h a n g e ) ;
} ) ;
#MDBlocal
CHANGE STREAM
CHARACTERISTICS
#MDBlocal
5 OPERATION TYPES
INSERT
DELETE
REPLACE
UPDATE
INVALIDATE
#MDBlocal
CHANGE STREAMS PRESENT A DEFINED
API
#MDBlocal
CHANGE STREAMS PRESENT A DEFINED
API, UTILIZE COLLECTION ACCESS
CONTROLS
#MDBlocal
CHANGE STREAMS PRESENT A DEFINED
API, UTILIZE COLLECTION ACCESS
CONTROLS, SHOW ONLY DURABLE
CHANGES
#MDBlocal
CHANGE STREAMS PRESENT A DEFINED
API, UTILIZE COLLECTION ACCESS
CONTROLS, SHOW ONLY DURABLE
CHANGES, AND ENABLE SCALING
ACROSS ALL YOUR NODES.
#MDBlocal
TOTAL ORDERING OF CHANGES
ACROSS SHARDS
mongos
3 1
2Shard
1
Shard
2
Shard
3
#MDBlocal
PS
CHANGES ARE DURABLE
P
S
#MDBlocal
SP
CHANGE STREAMS ARE RESUMABLE
P
S
{_id: <resumeToken>,
operationType: ‘update’,
ns: {db: ‘data’, coll: ‘temperature’},
documentKey: {_id: ‘room12345’},
updateDescription: {updatedFields: {temperature: 70},
removedFields: [‘humidity’]}
}
var newChangeStream = coll.watch({ resumeAfter: <cachedResumeToken> });
#MDBlocal
CHANGE STREAMS UTILIZE THE POWER
OF THE AGGREGATION FRAMEWORK
$match $project $addFields $replaceRoot $redact
var changeStream = coll.watch([{ $match: {$or: [{operationType: 'delete' }, {operationType:'replace'}]}}]);
#MDBlocal
1. DEFINED API
2. COLLECTION ACCESS CONTROLS
3. ENABLE SCALING
4. TOTAL ORDERING
5. DURABLE
6. RESUMABLE
7. POWER OF AGGREGATION
#MDBlocal
OPERATION TYPES
#MDBlocal
DELETEREPLACEUPDATEINVALIDATE5 OPERATION TYPES
{ _id: (resumeToken),
operationType: ‘insert’,
ns: {db: ‘test’, coll: ‘foo’},
documentKey: {userName: ‘alice123’,
_id: ObjectId("58a4eb4a30c75625e00d2820")
},
fullDocument: {_id: ObjectId("58a4eb4a30c75625e00d2820"),
userName: ‘alice123’,
name: ‘Alice’
}
}
INSERT
{_id: (resumeToken),
operationType: ‘delete’,
ns: {db: ‘test’, coll: ‘foo’},
documentKey: {userName: ‘alice123’,
_id: ObjectId("58a4eb4a30c75625e00d2820")
}
}
{_id: (resumeToken),
operationType: ‘replace’,
ns: {db: ‘test’, coll: ‘foo’},
documentKey: {userName: ‘alice123’,
_id: ObjectId("58a4eb4a30c75625e00d2820")
},
fullDocument: {_id: ObjectId("58a4eb4a30c75625e00d2820"),
userName: ‘alice123’,
name: ‘Alice’
}
}
{_id: (resumeToken),
operationType: ‘update’,
ns: {db: ‘test’, coll: ‘foo’},
documentKey: {userName: ‘alice123’,
_id: ObjectId("58a4eb4a30c75625e00d2820")
},
updateDescription: {updatedFields: {email: ‘alice@10gen.com’},
removedFields: [‘phoneNumber’]}
}
{_id: (resumeToken),
operationType: ‘invalidate’,
ns: {db: ‘test’, coll: ‘foo’}}
#MDBlocal
{_id: (resumeToken),
operationType: ‘update’,
ns: {db: ‘test’, coll: ‘foo’},
documentKey: {userName: ‘alice123’,
_id: ObjectId("58a4eb4a30c75625e00d2820")},
updateDescription: {updatedFields: {email: ‘alice@10gen.com’},
removedFields: [‘phoneNumber’]}
}
UPDATE
var changeStream = coll.watch({ fullDocument: 'updateLookup' });
UPDATE fullDocument: updateLookup
{_id: (resumeToken),
operationType: ‘update’,
ns: {db: ‘test’, coll: ‘foo’},
documentKey: {userName: ‘alice123’,
_id: ObjectId("58a4eb4a30c75625e00d2820")},
updateDescription: {updatedFields: {email: ‘alice@10gen.com’},
removedFields: [‘phoneNumber’]},
fullDocument: { _id: ObjectId("58a4eb4a30c75625e00d2820"),
name: ‘Alice’,
userName: ‘alice123’,
email: ‘alice@10gen.com’,
team: ‘replication’}
}
#MDBlocal
1 . S H AR D K E Y I S U S E D ( B Y T H E M O N G O S ) T O R O U T E
O P E R AT I O N S
2 . _ I D I S U S E D T O U N I Q U E L Y I D E N T I F Y A D O C U M E N T
mongos
3 1
2Shard
1
Shard
2
Shard
3
DEFINING THE documentKey
#MDBlocal
BACK TO
THE USE CASE
#MDBlocal
#MDBlocal
{_id: (resumeToken),
operationType: 'insert',
ns: {db: 'data', coll: 'temperature'},
documentKey: {_id: 'orangeRoom123'},
fullDocument: {_id: 'orangeRoom123',
temperature: 76,
username: 'eliot_horowitz' }
}
{_id: (resumeToken),
operationType: 'update',
ns: {db: 'data', coll: 'temperature'},
documentKey: {_id: 'greenRoom123'},
updateDescription: {updatedFields: {temperature: 68},
fullDocument: {_id: 'greenRoom123',
temperature: 68,
username: 'aly_cabral'}
}
{_id: (resumeToken),
operationType: 'insert',
ns: {db: 'data', coll: 'temperature'},
documentKey: {_id: 'greenRoom123'},
fullDocument: {_id: 'greenRoom123',
temperature: 75,
username: 'aly_cabral'}
}
Action Handler
var changeStream = coll.watch(
[{$match: {'fullDocument.temperature': {$gte : 70 }}}],
{fullDocument: 'updateLookup'});
temperature: 75
username: aly_cabral
#MDBlocal
IF YOUR APPLICATION REQUIRES STATE
ALWAYS MATCH ON UNCHANGING
FIELDS
#MDBlocal
{_id: (resumeToken),
operationType: 'replace',
ns: {db: 'data', coll: 'temperature'},
documentKey: {_id: 'blueRoom123'},
fullDocument: {_id: 'blueRoom123',
temperature: 71,
username: 'asya_kamsky'}
}
{_id: (resumeToken),
operationType: 'insert',
ns: {db: 'data', coll: 'temperature'},
documentKey: {_id: 'blueRoom123'},
fullDocument: {_id: 'blueRoom123',
temperature: 85,
username: 'aly_cabral'}
}
Action Handler
var changeStream = coll.watch([{ $match: {'fullDocument.username': 'aly_cabral'}}],
{fullDocument: 'updateLookup'});
temperature: 75
username: aly_cabral
temperature: 85
username: aly_cabral
{_id: (resumeToken),
operationType: 'delete',
ns: {db: 'data', coll: 'temperature'},
documentKey: {_id: 'blueRoom123'}
}
#MDBlocal
IF YOUR APPLICATION NEEDS TO NOTIFY ON DELETED
DATA
ALWAYS HANDLE DELETES AND
REPLACES APPROPRIATELY
#MDBlocal
var changeStream = coll.watch([{ $match: {$or:
[ { 'fullDocument.username': 'aly_cabral' },
{ operationType: 'delete' },
{ operationType: 'replace' }
]}}],
{fullDocument: 'updateLookup'});
Insert Update Delete
In the update notification fullDocument: null
updateLookup
{_id: (resumeToken),
operationType: 'update',
ns: {db: 'data', coll: 'temperature'},
documentKey: {userName: 'greenRoom123'},
updateDescription: {updatedFields: {temperature: 78}},
fullDocument: null
}
#MDBlocal
IF YOU NEED TO SEE EVERY CHANGE (EVEN OUTDATED
CHANGES) TO A DOCUMENT
HAVE MATCHING FIELDS IN THE
DOCUMENT KEY
#MDBlocal
{_id: (resumeToken),
operationType: 'insert',
ns: {db: 'data', coll: 'temperature'},
documentKey: {_id: 'blueRoom123',
username: 'aly_cabral'},
fullDocument: {_id: ‘blueRoom123’,
temperature: 85,
username: 'aly_cabral'}
}
{_id: (resumeToken),
operationType: 'delete',
ns: {db: 'data', coll: 'temperature'},
documentKey: {_id: 'blueRoom123',
username: 'aly_cabral'}}
{_id: (resumeToken),
operationType: 'replace',
ns: {db: 'data', coll: 'temperature'},
documentKey: {_id: 'greenRoom123',
username: 'aly_cabral'},
fullDocument: {_id: 'greenRoom123',
temperature: 71,
username: “asya_kamsky”}
}
Action Handler
var changeStream = coll.watch([{ $match: {'documentKey.username': 'aly_cabral'}}],
{fullDocument: 'updateLookup'});
temperature: 75
username: aly_cabral
temperature: 85
username: aly_cabral
#MDBlocal
{_id: (resumeToken),
operationType: 'replace',
ns: {db: 'data', coll: 'temperature'},
documentKey: {_id: 'greenRoom123'},
fullDocument: {_id: 'greenRoom123',
temperature: 71,
username: “asya_kamsky”}
}
{_id: (resumeToken),
operationType: 'insert',
ns: {db: 'data', coll: 'temperature'},
documentKey: {_id: 'blueRoom123'},
fullDocument: {_id: ‘blueRoom123’,
temperature: 85,
username: 'aly_cabral'}
}
{_id: (resumeToken),
operationType: 'delete',
ns: {db: 'data', coll: 'temperature'},
documentKey: {_id: 'blueRoom123'}
}
Action Handler
var changeStream = coll.watch([{ $match: {'documentKey._id':
{$in:['greenRoom123','blueRoom123']}
}}],
{fullDocument: 'updateLookup'});
temperature: 75
username: aly_cabral
temperature: 85
username: aly_cabral
#MDBlocal
TO SEE EVERY CHANGE TO A DOCUMENT
CONSIDER ALL EDGE CASES
#MDBlocal
UNDERLYING
TECHNOLOGY
#MDBlocal
P
S
S
S
S
#MDBlocal
1234
#MDBlocal
RESUMABLE
304 270 233 208 201 190
C AC H E D R E S U M E T O K E N : 2 0 8
N E W E S T O L D E S T
D E L E T E D
#MDBlocal
304 270 233 208 201 190
C AC H E D R E S U M E T O K E N : 1 9 0
N E W E S T O L D E S T
D E L E T E D
NON-RESUMABLE
#MDBlocal
#MDBlocal
1. DEFINED API
2. COLLECTION ACCESS CONTROLS
3. ENABLE SCALING
4. TOTAL ORDERING
5. DURABLE
6. RESUMABLE
7. POWER OF AGGREGATION
#MDBlocal
You're Ready!

More Related Content

What's hot

#Gophercon Talk by Smita Vijayakumar - Go's Context Library
#Gophercon Talk by Smita Vijayakumar - Go's Context Library#Gophercon Talk by Smita Vijayakumar - Go's Context Library
#Gophercon Talk by Smita Vijayakumar - Go's Context LibraryExotel
 
Py spark cheat sheet by cheatsheetmaker.com
Py spark cheat sheet by cheatsheetmaker.comPy spark cheat sheet by cheatsheetmaker.com
Py spark cheat sheet by cheatsheetmaker.comLam Hoang
 
2018 02-22 React, Redux & Building Applications that Scale | Redux
2018 02-22 React, Redux & Building Applications that Scale | Redux2018 02-22 React, Redux & Building Applications that Scale | Redux
2018 02-22 React, Redux & Building Applications that Scale | ReduxCodifly
 
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraDeependra Ariyadewa
 
Correcting Common Async/Await Mistakes in .NET
Correcting Common Async/Await Mistakes in .NETCorrecting Common Async/Await Mistakes in .NET
Correcting Common Async/Await Mistakes in .NETBrandon Minnick, MBA
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsMongoDB
 
Google apps script database abstraction exposed version
Google apps script database abstraction   exposed versionGoogle apps script database abstraction   exposed version
Google apps script database abstraction exposed versionBruce McPherson
 
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTRT3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTRDavid Gómez García
 
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Cliff Seal
 
JavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerJavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerBruce McPherson
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeMongoDB
 
Cassandra Summit 2015
Cassandra Summit 2015Cassandra Summit 2015
Cassandra Summit 2015jbellis
 
Implementing Server Side Data Synchronization for Mobile Apps
Implementing Server Side Data Synchronization for Mobile AppsImplementing Server Side Data Synchronization for Mobile Apps
Implementing Server Side Data Synchronization for Mobile AppsMichele Orselli
 
Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2Bruce McPherson
 
Bangun datar dan bangun ruang
Bangun datar dan bangun ruangBangun datar dan bangun ruang
Bangun datar dan bangun ruangSanSan Yagyoo
 
Tools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionTools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionJesus Manuel Olivas
 
Dynamically Evolving Systems: Cluster Analysis Using Time
Dynamically Evolving Systems: Cluster Analysis Using TimeDynamically Evolving Systems: Cluster Analysis Using Time
Dynamically Evolving Systems: Cluster Analysis Using TimeMagnify Analytic Solutions
 
Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots DeepAnshu Sharma
 

What's hot (19)

#Gophercon Talk by Smita Vijayakumar - Go's Context Library
#Gophercon Talk by Smita Vijayakumar - Go's Context Library#Gophercon Talk by Smita Vijayakumar - Go's Context Library
#Gophercon Talk by Smita Vijayakumar - Go's Context Library
 
Py spark cheat sheet by cheatsheetmaker.com
Py spark cheat sheet by cheatsheetmaker.comPy spark cheat sheet by cheatsheetmaker.com
Py spark cheat sheet by cheatsheetmaker.com
 
2018 02-22 React, Redux & Building Applications that Scale | Redux
2018 02-22 React, Redux & Building Applications that Scale | Redux2018 02-22 React, Redux & Building Applications that Scale | Redux
2018 02-22 React, Redux & Building Applications that Scale | Redux
 
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and Cassandra
 
Correcting Common Async/Await Mistakes in .NET
Correcting Common Async/Await Mistakes in .NETCorrecting Common Async/Await Mistakes in .NET
Correcting Common Async/Await Mistakes in .NET
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.js
 
Google apps script database abstraction exposed version
Google apps script database abstraction   exposed versionGoogle apps script database abstraction   exposed version
Google apps script database abstraction exposed version
 
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTRT3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
 
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
Temporary Cache Assistance (Transients API): WordCamp Birmingham 2014
 
JavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primerJavaScript client API for Google Apps Script API primer
JavaScript client API for Google Apps Script API primer
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
 
Scala on Your Phone
Scala on Your PhoneScala on Your Phone
Scala on Your Phone
 
Cassandra Summit 2015
Cassandra Summit 2015Cassandra Summit 2015
Cassandra Summit 2015
 
Implementing Server Side Data Synchronization for Mobile Apps
Implementing Server Side Data Synchronization for Mobile AppsImplementing Server Side Data Synchronization for Mobile Apps
Implementing Server Side Data Synchronization for Mobile Apps
 
Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2Do something in 5 with gas 9-copy between databases with oauth2
Do something in 5 with gas 9-copy between databases with oauth2
 
Bangun datar dan bangun ruang
Bangun datar dan bangun ruangBangun datar dan bangun ruang
Bangun datar dan bangun ruang
 
Tools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 EditionTools and Projects Dec 2018 Edition
Tools and Projects Dec 2018 Edition
 
Dynamically Evolving Systems: Cluster Analysis Using Time
Dynamically Evolving Systems: Cluster Analysis Using TimeDynamically Evolving Systems: Cluster Analysis Using Time
Dynamically Evolving Systems: Cluster Analysis Using Time
 
Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots Dpilot Source Code With ScreenShots
Dpilot Source Code With ScreenShots
 

Similar to Using Change Streams to Keep Up with Your Data

[MongoDB.local Bengaluru 2018] Using Change Streams to Keep Up With Your Data
[MongoDB.local Bengaluru 2018] Using Change Streams to Keep Up With Your Data[MongoDB.local Bengaluru 2018] Using Change Streams to Keep Up With Your Data
[MongoDB.local Bengaluru 2018] Using Change Streams to Keep Up With Your DataMongoDB
 
How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6Maxime Beugnet
 
Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片cfc
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesDesarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesLuis Curo Salvatierra
 
MongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB World 2018: Using Change Streams to Keep Up with Your DataMongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB World 2018: Using Change Streams to Keep Up with Your DataMongoDB
 
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
[Pgday.Seoul 2021] 2. Porting Oracle UDF and OptimizationPgDay.Seoul
 
¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?jaespinmora
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web servicesMichelangelo van Dam
 
Having issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfHaving issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfrajkumarm401
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSMongoDB
 
Cdr stats-vo ip-analytics_solution_mongodb_meetup
Cdr stats-vo ip-analytics_solution_mongodb_meetupCdr stats-vo ip-analytics_solution_mongodb_meetup
Cdr stats-vo ip-analytics_solution_mongodb_meetupchristkv
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of ControlChad Hietala
 
Angular js - 4developers 12 kwietnia 2013
Angular js - 4developers 12 kwietnia 2013Angular js - 4developers 12 kwietnia 2013
Angular js - 4developers 12 kwietnia 2013Marcin Wosinek
 
R57shell
R57shellR57shell
R57shellady36
 
Function Procedure Trigger Partition.pdf
Function Procedure Trigger Partition.pdfFunction Procedure Trigger Partition.pdf
Function Procedure Trigger Partition.pdfSanam Maharjan
 
CDR-Stats : VoIP Analytics Solution for Asterisk and FreeSWITCH with MongoDB
CDR-Stats : VoIP Analytics Solution for Asterisk and FreeSWITCH with MongoDBCDR-Stats : VoIP Analytics Solution for Asterisk and FreeSWITCH with MongoDB
CDR-Stats : VoIP Analytics Solution for Asterisk and FreeSWITCH with MongoDBAreski Belaid
 
Implementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDBImplementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDBOren Eini
 

Similar to Using Change Streams to Keep Up with Your Data (20)

[MongoDB.local Bengaluru 2018] Using Change Streams to Keep Up With Your Data
[MongoDB.local Bengaluru 2018] Using Change Streams to Keep Up With Your Data[MongoDB.local Bengaluru 2018] Using Change Streams to Keep Up With Your Data
[MongoDB.local Bengaluru 2018] Using Change Streams to Keep Up With Your Data
 
Grails UI Primer
Grails UI PrimerGrails UI Primer
Grails UI Primer
 
How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6How to leverage what's new in MongoDB 3.6
How to leverage what's new in MongoDB 3.6
 
Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesDesarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móviles
 
Graphql, REST and Apollo
Graphql, REST and ApolloGraphql, REST and Apollo
Graphql, REST and Apollo
 
MongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB World 2018: Using Change Streams to Keep Up with Your DataMongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB World 2018: Using Change Streams to Keep Up with Your Data
 
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
 
¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web services
 
Having issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfHaving issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdf
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJS
 
Cdr stats-vo ip-analytics_solution_mongodb_meetup
Cdr stats-vo ip-analytics_solution_mongodb_meetupCdr stats-vo ip-analytics_solution_mongodb_meetup
Cdr stats-vo ip-analytics_solution_mongodb_meetup
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Control
 
Angular js - 4developers 12 kwietnia 2013
Angular js - 4developers 12 kwietnia 2013Angular js - 4developers 12 kwietnia 2013
Angular js - 4developers 12 kwietnia 2013
 
R57shell
R57shellR57shell
R57shell
 
Function Procedure Trigger Partition.pdf
Function Procedure Trigger Partition.pdfFunction Procedure Trigger Partition.pdf
Function Procedure Trigger Partition.pdf
 
CDR-Stats : VoIP Analytics Solution for Asterisk and FreeSWITCH with MongoDB
CDR-Stats : VoIP Analytics Solution for Asterisk and FreeSWITCH with MongoDBCDR-Stats : VoIP Analytics Solution for Asterisk and FreeSWITCH with MongoDB
CDR-Stats : VoIP Analytics Solution for Asterisk and FreeSWITCH with MongoDB
 
Backbone Basics with Examples
Backbone Basics with ExamplesBackbone Basics with Examples
Backbone Basics with Examples
 
Implementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDBImplementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDB
 

Recently uploaded

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 

Recently uploaded (20)

E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 

Using Change Streams to Keep Up with Your Data

  • 1. #MDBlocal Using Change Streams to Keep Up With Your Data Asya Kamsky, Lead Product Manager #MongoDB @MDBLocal @asya999 #askAsya
  • 2. #MDBlocal Using Change Streams to Keep Up With Your Data Asya Kamsky, Lead Product Manager #MongoDB @MDBLocal @asya999 #askAsya
  • 3. #MDBlocal “TIME IS MONEY.” B E N J A M I N F R A N K L I NW A R R E N B U F F E T
  • 6. #MDBlocal const changeStream= db.collection('temperature').watch(); c h a n g e S t r e a m . o n ( ' c h a n g e ' , f u n c t i o n ( c h a n g e ) { c o n s o l e . l o g ( c h a n g e ) ; } ) ;
  • 10. #MDBlocal CHANGE STREAMS PRESENT A DEFINED API, UTILIZE COLLECTION ACCESS CONTROLS
  • 11. #MDBlocal CHANGE STREAMS PRESENT A DEFINED API, UTILIZE COLLECTION ACCESS CONTROLS, SHOW ONLY DURABLE CHANGES
  • 12. #MDBlocal CHANGE STREAMS PRESENT A DEFINED API, UTILIZE COLLECTION ACCESS CONTROLS, SHOW ONLY DURABLE CHANGES, AND ENABLE SCALING ACROSS ALL YOUR NODES.
  • 13. #MDBlocal TOTAL ORDERING OF CHANGES ACROSS SHARDS mongos 3 1 2Shard 1 Shard 2 Shard 3
  • 15. #MDBlocal SP CHANGE STREAMS ARE RESUMABLE P S {_id: <resumeToken>, operationType: ‘update’, ns: {db: ‘data’, coll: ‘temperature’}, documentKey: {_id: ‘room12345’}, updateDescription: {updatedFields: {temperature: 70}, removedFields: [‘humidity’]} } var newChangeStream = coll.watch({ resumeAfter: <cachedResumeToken> });
  • 16. #MDBlocal CHANGE STREAMS UTILIZE THE POWER OF THE AGGREGATION FRAMEWORK $match $project $addFields $replaceRoot $redact var changeStream = coll.watch([{ $match: {$or: [{operationType: 'delete' }, {operationType:'replace'}]}}]);
  • 17. #MDBlocal 1. DEFINED API 2. COLLECTION ACCESS CONTROLS 3. ENABLE SCALING 4. TOTAL ORDERING 5. DURABLE 6. RESUMABLE 7. POWER OF AGGREGATION
  • 19. #MDBlocal DELETEREPLACEUPDATEINVALIDATE5 OPERATION TYPES { _id: (resumeToken), operationType: ‘insert’, ns: {db: ‘test’, coll: ‘foo’}, documentKey: {userName: ‘alice123’, _id: ObjectId("58a4eb4a30c75625e00d2820") }, fullDocument: {_id: ObjectId("58a4eb4a30c75625e00d2820"), userName: ‘alice123’, name: ‘Alice’ } } INSERT {_id: (resumeToken), operationType: ‘delete’, ns: {db: ‘test’, coll: ‘foo’}, documentKey: {userName: ‘alice123’, _id: ObjectId("58a4eb4a30c75625e00d2820") } } {_id: (resumeToken), operationType: ‘replace’, ns: {db: ‘test’, coll: ‘foo’}, documentKey: {userName: ‘alice123’, _id: ObjectId("58a4eb4a30c75625e00d2820") }, fullDocument: {_id: ObjectId("58a4eb4a30c75625e00d2820"), userName: ‘alice123’, name: ‘Alice’ } } {_id: (resumeToken), operationType: ‘update’, ns: {db: ‘test’, coll: ‘foo’}, documentKey: {userName: ‘alice123’, _id: ObjectId("58a4eb4a30c75625e00d2820") }, updateDescription: {updatedFields: {email: ‘alice@10gen.com’}, removedFields: [‘phoneNumber’]} } {_id: (resumeToken), operationType: ‘invalidate’, ns: {db: ‘test’, coll: ‘foo’}}
  • 20. #MDBlocal {_id: (resumeToken), operationType: ‘update’, ns: {db: ‘test’, coll: ‘foo’}, documentKey: {userName: ‘alice123’, _id: ObjectId("58a4eb4a30c75625e00d2820")}, updateDescription: {updatedFields: {email: ‘alice@10gen.com’}, removedFields: [‘phoneNumber’]} } UPDATE var changeStream = coll.watch({ fullDocument: 'updateLookup' }); UPDATE fullDocument: updateLookup {_id: (resumeToken), operationType: ‘update’, ns: {db: ‘test’, coll: ‘foo’}, documentKey: {userName: ‘alice123’, _id: ObjectId("58a4eb4a30c75625e00d2820")}, updateDescription: {updatedFields: {email: ‘alice@10gen.com’}, removedFields: [‘phoneNumber’]}, fullDocument: { _id: ObjectId("58a4eb4a30c75625e00d2820"), name: ‘Alice’, userName: ‘alice123’, email: ‘alice@10gen.com’, team: ‘replication’} }
  • 21. #MDBlocal 1 . S H AR D K E Y I S U S E D ( B Y T H E M O N G O S ) T O R O U T E O P E R AT I O N S 2 . _ I D I S U S E D T O U N I Q U E L Y I D E N T I F Y A D O C U M E N T mongos 3 1 2Shard 1 Shard 2 Shard 3 DEFINING THE documentKey
  • 24. #MDBlocal {_id: (resumeToken), operationType: 'insert', ns: {db: 'data', coll: 'temperature'}, documentKey: {_id: 'orangeRoom123'}, fullDocument: {_id: 'orangeRoom123', temperature: 76, username: 'eliot_horowitz' } } {_id: (resumeToken), operationType: 'update', ns: {db: 'data', coll: 'temperature'}, documentKey: {_id: 'greenRoom123'}, updateDescription: {updatedFields: {temperature: 68}, fullDocument: {_id: 'greenRoom123', temperature: 68, username: 'aly_cabral'} } {_id: (resumeToken), operationType: 'insert', ns: {db: 'data', coll: 'temperature'}, documentKey: {_id: 'greenRoom123'}, fullDocument: {_id: 'greenRoom123', temperature: 75, username: 'aly_cabral'} } Action Handler var changeStream = coll.watch( [{$match: {'fullDocument.temperature': {$gte : 70 }}}], {fullDocument: 'updateLookup'}); temperature: 75 username: aly_cabral
  • 25. #MDBlocal IF YOUR APPLICATION REQUIRES STATE ALWAYS MATCH ON UNCHANGING FIELDS
  • 26. #MDBlocal {_id: (resumeToken), operationType: 'replace', ns: {db: 'data', coll: 'temperature'}, documentKey: {_id: 'blueRoom123'}, fullDocument: {_id: 'blueRoom123', temperature: 71, username: 'asya_kamsky'} } {_id: (resumeToken), operationType: 'insert', ns: {db: 'data', coll: 'temperature'}, documentKey: {_id: 'blueRoom123'}, fullDocument: {_id: 'blueRoom123', temperature: 85, username: 'aly_cabral'} } Action Handler var changeStream = coll.watch([{ $match: {'fullDocument.username': 'aly_cabral'}}], {fullDocument: 'updateLookup'}); temperature: 75 username: aly_cabral temperature: 85 username: aly_cabral {_id: (resumeToken), operationType: 'delete', ns: {db: 'data', coll: 'temperature'}, documentKey: {_id: 'blueRoom123'} }
  • 27. #MDBlocal IF YOUR APPLICATION NEEDS TO NOTIFY ON DELETED DATA ALWAYS HANDLE DELETES AND REPLACES APPROPRIATELY
  • 28. #MDBlocal var changeStream = coll.watch([{ $match: {$or: [ { 'fullDocument.username': 'aly_cabral' }, { operationType: 'delete' }, { operationType: 'replace' } ]}}], {fullDocument: 'updateLookup'}); Insert Update Delete In the update notification fullDocument: null updateLookup {_id: (resumeToken), operationType: 'update', ns: {db: 'data', coll: 'temperature'}, documentKey: {userName: 'greenRoom123'}, updateDescription: {updatedFields: {temperature: 78}}, fullDocument: null }
  • 29. #MDBlocal IF YOU NEED TO SEE EVERY CHANGE (EVEN OUTDATED CHANGES) TO A DOCUMENT HAVE MATCHING FIELDS IN THE DOCUMENT KEY
  • 30. #MDBlocal {_id: (resumeToken), operationType: 'insert', ns: {db: 'data', coll: 'temperature'}, documentKey: {_id: 'blueRoom123', username: 'aly_cabral'}, fullDocument: {_id: ‘blueRoom123’, temperature: 85, username: 'aly_cabral'} } {_id: (resumeToken), operationType: 'delete', ns: {db: 'data', coll: 'temperature'}, documentKey: {_id: 'blueRoom123', username: 'aly_cabral'}} {_id: (resumeToken), operationType: 'replace', ns: {db: 'data', coll: 'temperature'}, documentKey: {_id: 'greenRoom123', username: 'aly_cabral'}, fullDocument: {_id: 'greenRoom123', temperature: 71, username: “asya_kamsky”} } Action Handler var changeStream = coll.watch([{ $match: {'documentKey.username': 'aly_cabral'}}], {fullDocument: 'updateLookup'}); temperature: 75 username: aly_cabral temperature: 85 username: aly_cabral
  • 31. #MDBlocal {_id: (resumeToken), operationType: 'replace', ns: {db: 'data', coll: 'temperature'}, documentKey: {_id: 'greenRoom123'}, fullDocument: {_id: 'greenRoom123', temperature: 71, username: “asya_kamsky”} } {_id: (resumeToken), operationType: 'insert', ns: {db: 'data', coll: 'temperature'}, documentKey: {_id: 'blueRoom123'}, fullDocument: {_id: ‘blueRoom123’, temperature: 85, username: 'aly_cabral'} } {_id: (resumeToken), operationType: 'delete', ns: {db: 'data', coll: 'temperature'}, documentKey: {_id: 'blueRoom123'} } Action Handler var changeStream = coll.watch([{ $match: {'documentKey._id': {$in:['greenRoom123','blueRoom123']} }}], {fullDocument: 'updateLookup'}); temperature: 75 username: aly_cabral temperature: 85 username: aly_cabral
  • 32. #MDBlocal TO SEE EVERY CHANGE TO A DOCUMENT CONSIDER ALL EDGE CASES
  • 36. #MDBlocal RESUMABLE 304 270 233 208 201 190 C AC H E D R E S U M E T O K E N : 2 0 8 N E W E S T O L D E S T D E L E T E D
  • 37. #MDBlocal 304 270 233 208 201 190 C AC H E D R E S U M E T O K E N : 1 9 0 N E W E S T O L D E S T D E L E T E D NON-RESUMABLE
  • 39. #MDBlocal 1. DEFINED API 2. COLLECTION ACCESS CONTROLS 3. ENABLE SCALING 4. TOTAL ORDERING 5. DURABLE 6. RESUMABLE 7. POWER OF AGGREGATION

Editor's Notes

  1. who am I – what do I do, talk about new feature in 3.6 but first some background.
  2. Simple definition. Change streams allow you to watch all the changes against a collection. So, when you open change streams against a collection you will see all of the changes applied to documents that belong to that collection. On each change a listening application will be notified with a document describing the change. Imagine this scenario, I have a smart thermometer within my apartment. Every second it inserts a document into MongoDB with temperature data. Change streams can then notify any listening application to every change in my temperature collection. So as the thermometer inserts new data, change streams will inform my listening action handler. In this case, the action handler is an application I built to turn on a fan every time the temperature goes above 70 degrees. Don’t let the simplicity of this example fool you, this concept can be applied to back-office management applications to end user applications. Change streams are extremely powerful
  3. So, this slide is to show you how incredibly simple it is to implement change streams in your application. This example happens to be in node. Here, I am defining a change stream. Then starting it where every change gets printed out. It’s extremely simple and incredibly powerful. With change stream, you get a real-time feed of the changes to your data, enabling your application to react to these changes immediately.
  4. what type of operations can you "watch"? Basically write operations on documents. you cannot see queries or commands, nor meta-data events, but you can see any write that changes a document – I'll go into specifics of how each of these looks a bit later. change streams provide certain guarantees to make it easier for you to implement powerful functionality STABLE API
  5. API access control
  6. access control guarantee durable data
  7. scaling ordered (even sharded) are resumable aggregation syntax
  8. scaling well ordered (even sharded) resumable aggregation syntax for more advanced features
  9. sharding – mongos routes data to shards, so what's the order of operations of shards relative to each other? open change stream against mongos guaranteed ordering Lamport clock or logical cluster time that all components of the cluster know about – if they fall behind they get "latest cluster time" and increment relative to that.
  10. durable – no changes shown that can be rolled back what is rollback? only when committed to majority of the nodes in replica set (no change streams against standalone)
  11. resumable – what does that mean? if you lose your place re-try from where you were last. driver takes care of most details similar to retryable writes only certain errors can be "resumed" from. If your application crashes or is stopped for some reason, you are responsible for storing the resume token to pass it to watch method when you restart (if not then you will start with "now") and may possibly miss changes during the time application was down.
  12. familiar syntax for additional processing of change stream data – you get to provide an aggregation pipeline, and documents returned stream through it. hence only some stages are allowed. SUMMARY
  13. SUMMARY
  14. look closer at different operation types and what details they provide
  15. Now we are going to move into some of the characteristics of change streams.
  16. NOW you should close the change stream and re-open it with a different list of watched rooms, and you should probably add an $or watching for fullDocument.username *you* in case there's a change there.
  17. The oplog is an internal mechanism that tracks all changes across the entire cluster, whether they are data or system changes. primary accepts all writes records them into oplog secondaries tail the oplog – meaning they watch it, sort of like watching a change stream(!) in fact that was a way you could do it yourself in the past
  18. why not tail the oplog yourself?
  19. No guarantees! SUMMARY