MongoDB Stitch is a serverless platform designed to help you easily and securely build an application on top of MongoDB Atlas. It lets developers focus on building applications rather than on managing data manipulation code, service integration, or backend infrastructure. MongoDB Stitch also makes it simple to respond to backend changes immediately, allowing you to simplify client side code and build complex flows more easily. This talk will cover ways that MongoDB Stitch helps you respond to changes in your database and take your applications to the next level.
9. #MDBlocal
“We set out to build a database that we would want to use, so that
whenever developers wanted to build an application, they could
focus on the application, not on working around the database.”
- Eliot Horowitz
14. #MDBlocal
OPLOGOPLOG OPLOG
Application
W
db.users.insert({,,,})
PRIMARY SECONDARY SECONDARY
db.users.insert({,,,})
A
C
K
db.users.insert({,,,})
W
db.users.update({,,,}) db.users.update({,,,})
A
C
K
db.users.update({,,,})
Monitor
R R
If (insert) {
aws.s3.insertObject(…);
}
Responding to change via tailing the OpLog
TAILING THE OPLOG
15. #MDBlocal
Responding to Database Changes in the Past
Before Change Streams: Oplog
{
"ts" : Timestamp(1395663575, 1),
"h" : NumberLong("-5862498903080440015"),
"v" : 2,
"op" : "i",
"ns" : ”music.songs",
"o" : {
"_id" : ObjectId("533024470d7e2c31d4443d22"),
"author" : ”David Bowie",
"title" : ”Changes"
}
}
19. #MDBlocal
Change Streams Implementation
Apps register for notifications via API
Change streams are:
• Flexible: deltas or the full document, filter on specific events only
• Consistent: total ordering of data across shards
• Secure: enforces collection’s user access privileges
• Reliable: only notifies once write committed on majority of replicas
• Resumable: from node failure
• Concurrent: up to 1,000 changes streams per MongoDB instance
• Familiar: use regular MongoDB query language and drivers
21. #MDBlocal
Adding Triggers to Stitch
Reduce Time to Market
Functions as a Service: No waiting on
infrastructure
Reduce boilerplate: Save code
Cross-Platform: Develop once
Existing Apps Untouched: No reverse-
engineering
Reduce Ops costs
Serverless: Zero wasted capacity
Payment: No up-front cost
Capacity on Demand: No need to over-
provision in advance
Secure by Default: Less operational effort
Reduce Dev Effort
Backend Integration Built in: No generic
backend code
HA & Scalability Built in: Hard and time
consuming to build Orchestrate Services:
Reuse what's out there
Faster Cheaper Easier
24. #MDBlocal
When do we want functions to execute?
AUTHENTICATION
WEBHOOK/
INTEGRATION
DATABASE EVENTS
3 Contexts Where Functions
Execute
25. #MDBlocal
Event Driven Life-cycle
Pending SucceededOwned
Failed Dead
Event is …
Waiting for a ConsumerAttempting ExecutionCompletedAwaiting RetriesRe-Attempting ExecutionUnable to Execute
(Trigger Disabled)
26. #MDBlocal
What do change events look like?
Event Subscription (Trigger) Event Source (Actual event document)
27. #MDBlocal
Example Trigger
Name of the Trigger
Type: DATABASE, AUTHENTICATION
Type of Operation to Trigger
Database
Collection
Match Criteria
Full Document or Partial
Function to be called on Trigger