Serverless_with_MongoDB
- 1. S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
- 2. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T
Server-less with MongoDB
T J Tang
jianfa.tang@mongodb.com
Principal Solutions Architect
Mongo DB
- 3. MongoDB at a glance
Rapidly Growing Company
FY17 FY18 FY19
• Headquartered in New York, NY
• 1,200+ global employees
• 13,400+ customers in over 100 countries
• 60MM+ total downloads of MongoDB
Community Server
Note: Fiscal year ending January 31
- 4. Massive adoption of MongoDB
MongoDB vs. NoSQL skills on LinkedIn Activity index on Stack Overflow
-
20,000
40,000
60,000
80,000
100,000
120,000
2012 2013 2014 2015 2016
Other
HBase
Cassandra
Redis
More developers want to work with MongoDB this year than any other database
– Stack Overflow Developer Survey (2018)
Source: 451 Research Source: StackOverkill
Neo4j
HBase
Cassandra
Redis
- 5. Modern general purpose database
Customer
Single View
Digital
Platform Mobile Banking
Digital
Transformation Core Gaming Mgmt Digital Insurance
Mode 2 Applications Digital Transformation
Trading
Platform Digital Transformation
Customer
Analytics Customer Single View
Digital
Transformation eComm Platform Flight Info OTT Service eComm Platform
Media
Platform
Genetic
Analysis
Online
Lending
Swap Equities
Management
E-Commerce
Personalization Online Tax Returns
Marketing
Cloud Social Media
Log Metadata
Store
Creative
Cloud
Order
Capture
Cryptocurrency
Platform Gaming Platform Real-Time Analytics
Subscriber
QoS
E-Commerce
System
Online Media
Mobile Banking
Product
Catalogue
- 7. MongoDB Atlas — Global Cloud Database
Self-service & elastic
Deploy, modify, and upgrade on demand with
best-in-class operational automation
Automated database maintenance
Database and infrastructure resources as code
Scale up, out, or down in a few clicks or API calls
Global & cloud-agnostic
Available in 60+ regions across globe
Global clusters for read/write anywhere
deployments and multi-region fault tolerance
Easy migrations with a consistent experience
across cloud providers
Enterprise-grade security & SLAs
Network isolation, VPC peering, end-to-end
encryption, and role-based access controls
Encryption key management, LDAP integration,
granular database auditing
SOC 2 / Privacy Shield / HIPAA
Guaranteed reliability with SLAs
Comprehensive monitoring
Deep visibility into 100+ KPIs with proactive
alerting
Real-time performance tracking and
Performance Advisor
APIs to integrate with monitoring dashboards
Managed backup
Point-in-time data recovery
Queryable backup snapshots
Consistent snapshots of sharded deployments
Cloud data mobility
Stitch: Serverless platform services
Simple, serverless functions for backend logic,
service integrations, and APIs
Database access from your frontend secured by
straightforward, field-level access rules
Database and authentication triggers to react to
changes in real time
- 8. MongoDB as a service on AWS
MongoDB Atlas is currently available in 17 AWS regions.
• us-east-1 (N. Virginia)
• us-east-2 (Ohio)
• us-west-2 (Oregon)
• us-west-1 (N. California)
• ca-central-1 (Canada)
• sa-east-1 (São Paulo)
Americas
• ap-east-1 (Hong Kong)
• ap-southeast-1 (Singapore)
• ap-southeast-2 (Sydney)
• ap-northeast-1 (Tokyo)
• ap-northeast-2 (Seoul)
• ap-south-1 (Mumbai)
Asia
• eu-west-1 (Dublin)
• eu-west-2 (London)
• eu-west-3 (Paris)
• eu-north-1 (Stockholm)
• eu-central-1 (Frankfurt)
Europe
- 9. MongoDB Atlas Full Text Search (Beta)
● Adds Full Text Search as a fully managed service to
your Atlas cluster
○ Power of Lucene 8, without provisioning and running a
separate search platform
○ Integrated with MongoDB Query Language, so no separate
APIs to learn
○ Dynamic and static indexing supporting fuzzy & wildcard
search, Boolean & compound queries, language analyzers,
scoring and snippets
○ Configured via Atlas Data Explorer or API
- 10. MongoDB Atlas Data Lake
Multiple Formats,
No Schema
Analyze data in any format on S3 using the MongoDB Query Language
Auto-Scale,
At Any Scale
Best Tools,
High Productivity
Integrated with Atlas, Single
UI, Billing, Permissioning
Serverless, No
Infrastructure Management
On-Demand, Usage-
Based Pricing
- 12. Use Cases
Data Lake Analytics Data Products and
Services
Active Archives
➔ explore all of your rich data
naturally
➔ get to data as it lands via
streams or microservices
➔ democratize access across
diverse user groups
➔ monetize data
➔ market research, data-
and insight-as-a-service
➔ snapshots, time series
analysis, predictive
analytics to innovate faster
➔ historical analysis against
data assets retained in long
term cold storage
➔ cost-effective data strategy
- 13. Cross-region replication
● Ensure uptime in the unlikely event of a multi-
zone or total region outage
● Get improved performance for local reads by
geographically distributing read-only replica set
members that do not participate in the failover
process
● Available for Atlas deployments running on
dedicated instances in AWS
- 14. Fine-grained monitoring and alerts
● Monitoring and alerts provide full metrics on the
state of your cluster’s database and server
usage
● Automatic notifications when your database
operations or server usage reach defined
thresholds that affect your cluster's performance
● Combining our automated alerting with the
flexible scale-up-and-out options in MongoDB
Atlas, we can keep your database-supported
applications always performing as well as they
should
- 15. Continuous backup
• MongoDB Atlas continuously backs up your data, ensuring
your backups are typically just a few seconds behind the
operational system
• Point-in-time backup of replica sets and consistent, cluster-
wide snapshots of sharded clusters. With MongoDB Atlas,
you can easily and safely restore to precisely the moment
you need
• Compression and block-level deduplication technology
keeps your backup processes as efficient as possible
• Backups are securely stored in North America, Ireland,
Germany, United Kingdom, or Australia*. For more location
flexibility of your backup data, you can utilize MongoDB’s
mongodump / mongorestore tools
*Additional regions for continuous backup coming soon
- 16. Global Clusters
Distribute your fully automated database across multiple
geographically distributed zones made up of one or
more cloud regions
● Read and write locally to provide single-digit
millisecond latency for your distributed applications
● Ensure that data from certain geographies lives in
predefined zones
● Easily deploy using prebuilt zone templates or
build your own zones by choosing cloud regions in
an easy-to-use, visual interface
- 18. App Backend Infrastructure
Core Database Functionality
Storage
Service integrations, data access control
Code that moves the business forward
Managing OS, Scale, Security, Backups, etc.
Typical Technology Stack
- 19. App Backend Infrastructure
Core Database Functionality
Storage
Service integrations, data access control
Code that moves the business forward
Managing OS, Scale, Security, Backups, etc.
Utilize Database-as-a-Service
DBaaS
- 20. App Backend Infrastructure
Core Database Functionality
Storage
Service integrations, data access control
Code that moves the business forward
Managing OS, Scale, Security, Backups, etc.
Add Backend-as-a-Service
DBaaS
BaaS
- 21. App Backend Infrastructure
Core Database Functionality
Storage
Service integrations, data access control
Code that moves the business forward
Managing OS, Scale, Security, Backups, etc.
DBaaS
BaaS
You should focus here
And Focus Your Energy Where You Can Make a Difference
- 22. App Backend Infrastructure
Core Database Functionality
Storage
Service integrations, data access control
Code that moves the business forward
Managing OS, Scale, Security, Backups, etc.
And Focus Your Energy Where You Can Make a Difference
MongoDB
Atlas
MongoDB
Stitch
You should focus here
Fully managed
Elastic scale
Highly Available
Secure
- 24. Basic Blog Tutorial
<html>
<head>
</head>
<body>
<h3>This is a great blog post</h3>
<div id="content">
I like to write about technology because I want to get on
the front page of hacker news. (In a good way)
</div>
<hr>
<div id="comments"></div>
</body>
</html>
Nothing Special with the first step. Its basic HTML.
Save the file as BasicBlogDemo.html and double click the file, it
will open in your browser.
You can see the header, the content and the hard rule at the
bottom
- 25. Basic Blog Tutorial
<html>
<head>
<script src="https://s3.amazonaws.com/stitch-sdks/js/bundles/4.0.0/stitch.js"></script>
</head>
<body>
<h3>This is a great blog post</h3>
<div id="content">
I like to write about technology because I want to get on the front page of hacker news. (In a good way)
</div>
<hr>
<div id="comments"></div>
</body>
</html>
Ok, we just now included the stitch client browser SDK!
- 26. Basic Blog Tutorial
<html>
<head>
<script src="https://s3.amazonaws.com/stitch-sdks/js/bundles/4.0.0/stitch.js"></script>
<script>
// Initialize the App Client
const client = stitch.Stitch.initializeDefaultAppClient("<your-app-id>");
// Get a MongoDB Service Client
const mongodb = client.getServiceClient(stitch.RemoteMongoClient.factory,"mongodb-
atlas");
// Get a reference to the blog database
const db = mongodb.db("blog");
</script>
</head>
<body>
<h3>This is a great blog post</h3>
<div id="content">
I like to write about technology because I want to get on the front page of hacker news.
(In a good way)
</div>
<hr>
<div id="comments"></div>
</body>
</html>
Stitch client browser SDK
Stitch APP ID
Stitch Client
Connection
Stitch Database
We now have
everything we need to
connect to the Atlas
database instance for
our Application!
- 27. Basic Blog Tutorial<html>
<head>
<script src="https://s3.amazonaws.com/stitch-sdks/js/bundles/4.0.0/stitch.js"></script>
<script>
// Initialize the App Client
const client = stitch.Stitch.initializeDefaultAppClient("<your-app-id>");
// Get a MongoDB Service Client
const mongodb = client.getServiceClient(stitch.RemoteMongoClient.factory,"mongodb-
atlas");
// Get a reference to the blog database
const db = mongodb.db("blog");
function displayComments() {
db.collection('comments').find({}, {limit: 1000}).asArray()
.then(docs => {
const html = docs.map(c => "<div>" + c.comment +
"</div>").join("");
document.getElementById("comments").innerHTML = html;
});
}
</script>
</head>
<body>
<h3>This is a great blog post</h3>
<div id="content">
I like to write about technology because I want to get on the front page of hacker news.
(In a good way)
</div>
<hr>
<div id="comments"></div>
</body>
</html>
Our first real function!
Then we display them
in the comments div
as html for the user to
view
We specify the
comments collection
We find the
documents, and
specify a limit of 1,000
We Loop through the
array of documents
and store them in a
variable called html.
- 28. Basic Blog Tutorial<html>
<head>
<script src="https://s3.amazonaws.com/stitch-sdks/js/bundles/4.0.0/stitch.js"></script>
<script>
// Initialize the App Client
const client = stitch.Stitch.initializeDefaultAppClient("<your-app-id>");
// Get a MongoDB Service Client
const mongodb = client.getServiceClient(stitch.RemoteMongoClient.factory,"mongodb-
atlas");
// Get a reference to the blog database
const db = mongodb.db("blog");
function displayComments() {
db.collection('comments').find({}, {limit: 1000}).asArray()
.then(docs => {
const html = docs.map(c => "<div>" + c.comment +
"</div>").join("");
document.getElementById("comments").innerHTML = html;
});
}
function displayCommentsOnLoad() {
client.auth
.loginWithCredential(new stitch.AnonymousCredential())
.then(displayComments)
.catch(console.error);
}
</script>
</head>
<body>
<h3>This is a great blog post</h3>
<div id="content">
I like to write about technology because I want to get on the front page of hacker news.
(In a good way)
</div>
<hr>
<div id="comments"></div>
</body onload="displayCommentsOnLoad()">
</html>
Our next function logs
us into our database
We have connected to
the database and run
our first query! Check
the stitch console logs.
It calls the display
comments function
after logging in.
The function to
connect to the
database is called in
the body onload...
Save the changes and
refresh the browser.
- 29. Basic Blog Tutorial...
function addComment() {
const newComment = document.getElementById("new_comment");
console.log("add comment", client.auth.user.id)
db.collection("comments")
.insertOne({ owner_id : client.auth.user.id, comment: newComment.value })
.then(displayComments);
newComment.value = "";
}
function displayComments() {
db.collection('comments').find({}, {limit: 1000}).asArray()
.then(docs => {
const html = docs.map(c => "<div>" + c.comment +
"</div>").join("");
document.getElementById("comments").innerHTML = html;
});
}
...
</script>
</head>
<body>
<h3>This is a great blog post</h3>
<div id="content">
I like to write about technology because I want to get on the front page of hacker news.
(In a good way)
</div>
<hr>
Add comment:
<input id="new_comment"><BR>
<input type="submit" onClick="addComment()">
<hr>
<div id="comments"></div>
</body onload="displayCommentsOnLoad()">
</html>
Now we insert a
comment into our
Atlas database
through the stitch API,
and then retrieve it for
display
The value we insert is
obtained from an input
field added here.
The add comment
function is called from
the submit button
Our first stitch App is
complete!
- 30. Basic Blog Tutorial
Play with it, add more comments.
Add new fields, see what happens.
You are well on your way to being
able to start writing a new
application.
You now have a basic
understanding and are ready for
more.
- 31. The Server-less Architecture Accelerates Everything
Cloud Infrastructure
Services and APIs
Application Logic
MongoDB Atlas
Rapidly deploy, dynamically scale, and distribute
databases across regions and cloud providers
MongoDB Stitch
Serverless platform that allows developers to focus
on innovation rather than plumbing, services
orchestration, and boilerplate code
2-5x increase in productivity by leveraging the MongoDB Atlas + Stitch/Realm
Client Application or Service
Application Logic
DataData generated from your application is sent and retrieved
through the Stitch Client SDK