Slide 1

Slide 1 text

Joe Karlsson An Gentle Introduction to Building Serverless Apps with MongoDB Stitch @JoeKarlsson1

Slide 2

Slide 2 text

How’s this talk going to work? @JoeKarlsson1

Slide 3

Slide 3 text

{ name: “Joe Karlsson”, company: “MongoDB”, title: [ “Developer Advocate”, “Software Engineer” ], twitter: “@JoeKarlsson1”, website: “joekarlsson.com”, }

Slide 4

Slide 4 text

Agenda ▪ Quick MongoDB overview ▪ Intro to Serverless ▪ Guided Serverless tutorial with Stitch @JoeKarlsson1

Slide 5

Slide 5 text

MongoDB Overview *I promise this will be fast and hopefully actually useful @JoeKarlsson1

Slide 6

Slide 6 text

Scale cheaper! As the size of your database grows, scale horizontally. @JoeKarlsson1

Slide 7

Slide 7 text

Program faster! Documents map to data structures in most popular languages. Update Your Profile @JoeKarlsson1 { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] }

Slide 8

Slide 8 text

SQL MongoDB Query faster! Stop doing expensive joins to get your data. ID a ... 1 b ... 2 ... ... 3 ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... { ...
 a: “b”,
 ... c: {
 d: “e”
 ...
 },
 ... } @JoeKarlsson1

Slide 9

Slide 9 text

Pivot easier! Easily change the shape of your data as your app evolves. SQL MongoDB {
 a: “b”,
 c: “one”,
 e: “f” } {
 a: “b”,
 c: 1,
 new: “no biggee” } ALTER TABLE `mydb`.`letters_table` DROP COLUMN `e`, ADD COLUMN `New` VARCHAR(45) NULL AFTER `C`, CHANGE COLUMN `C` `C` INT NULL DEFAULT NULL ; @JoeKarlsson1

Slide 10

Slide 10 text

Term mapping summary Row Column Table Database Index Join Join Left Outer Join Recursive Common Table Expressions View Transaction Document Field Collection Database Index Embedding Database References $lookup $graphLookup View Transaction @JoeKarlsson1

Slide 11

Slide 11 text

Did you know that? • MongoDB supports distributed ACID transactions? • MongoDB added field level encryption? • MongoDB is now PCI compliant? • MongoDB now has schema validation? @JoeKarlsson1

Slide 12

Slide 12 text

@JoeKarlsson1

Slide 13

Slide 13 text

Agenda ▪ Quick MongoDB overview ▪ Intro to Serverless ▪ Guided Serverless tutorial with Stitch @JoeKarlsson1

Slide 14

Slide 14 text

What is Serverless? @JoeKarlsson1

Slide 15

Slide 15 text

Devs don’t manage anything, except for their application code @JoeKarlsson1

Slide 16

Slide 16 text

@JoeKarlsson1

Slide 17

Slide 17 text

▪ No managing of infrastructure whatsoever. ▪ No provisioning. ▪ No patching. ▪ No capacity planning. ▪ No scaling. @JoeKarlsson1

Slide 18

Slide 18 text

77% 
 increase in delivery speed Serverless Survey: +77% Delivery Speed, 4 Dev Workdays/Mo Saved & -26% AWS Monthly Bill by Annika Helendi @JoeKarlsson1

Slide 19

Slide 19 text

@JoeKarlsson1

Slide 20

Slide 20 text

@JoeKarlsson1

Slide 21

Slide 21 text

@JoeKarlsson1

Slide 22

Slide 22 text

What is
 MongoDB Stitch? @JoeKarlsson1

Slide 23

Slide 23 text

A serverless platform that makes it easy to build modern, cross-platform apps with MongoDB @JoeKarlsson1

Slide 24

Slide 24 text

What is MongoDB Stitch? QueryAnywhere Functions Triggers Mobile Sync
 @JoeKarlsson1

Slide 25

Slide 25 text

MongoDB Cloud Architecture @JoeKarlsson1 Mobile App Frontend App Frontend App MongoDB Mobile Backend Monolith or Microservice(s) REST API or SDKs for iOS/Android/JavaScript Stitch Connection String (any driver) Stitch Triggers Stitch Atlas Cloud Infrastructure Coming 2020 Mobile Sync (beta)

Slide 26

Slide 26 text

MongoDB Stitch Architecture @JoeKarlsson1

Slide 27

Slide 27 text

API ELB Stitch Core Request Processing Atlas Stitch Metadata 1 Stitch Architecture (Single Region) Services Stitch requests first hit a load balancer which distributes them across available capacity within a region. 1 Load Balancer

Slide 28

Slide 28 text

API ELB Stitch Core Request Processing Atlas Stitch Metadata 2 Services Stitch requests are processed by a set of multi-tenant Go servers. Each request is run within a goroutine. All JavaScript is run by Otto. 2 Request Processor Stitch Architecture (Single Region)

Slide 29

Slide 29 text

API ELB Stitch Core Request Processing Atlas Stitch Metadata 3 Services During the request Stitch coordinates with a metadata instance used for: application definition, authentication, end-user information, and logs. 3 Stitch Metadata Stitch Architecture (Single Region)

Slide 30

Slide 30 text

API ELB Stitch Core Request Processing Atlas Stitch Metadata 4 Services When Stitch works with Atlas it keeps connections alive and pools whenever possible. Other service interactions are done over standard HTTPS. 4 Service Coordination Stitch Architecture (Single Region)

Slide 31

Slide 31 text

Stitch Architecture (Multi-region) 5 To distribute: Stitch deploys request processing across major regions; keeps data in sync with an Atlas Global Cluster; and routes requests via a global load balancer. 5 Distributing Stitch

Slide 32

Slide 32 text

5 To distribute: Stitch deploys request processing across major regions; keeps data in sync with an Atlas Global Cluster; and routes requests via a global load balancer. 5 Distributing Stitch Stitch Architecture (Multi-region)

Slide 33

Slide 33 text

ELB 5 Stitch Architecture (Multi-region) To distribute: Stitch deploys request processing across major regions; keeps data in sync with an Atlas Global Cluster; and routes requests via a global load balancer. 5 Distributing Stitch

Slide 34

Slide 34 text

Stitch Architecture (Multi-region) ELB In Global application, Stitch matches region on authentication so end-users process nearly all requests on the closest region. 6 Global Applications 6

Slide 35

Slide 35 text

How does Stitch compare to other Serverless providers? @JoeKarlsson1

Slide 36

Slide 36 text

Agenda ▪ Quick MongoDB overview ▪ Intro to Serverless ▪ Guided Serverless tutorial with Stitch @JoeKarlsson1

Slide 37

Slide 37 text

React Journal Serverless Demo @JoeKarlsson1

Slide 38

Slide 38 text

@JoeKarlsson1

Slide 39

Slide 39 text

App Architecture @JoeKarlsson1 Stitch MongoDB Atlas Journal.entries Trigger onSharedItems Function notifyUsersOfShare Services Amazon SES React Journal App Amazon SES

Slide 40

Slide 40 text

First, we need to setup an Atlas MongoDB Cluster @JoeKarlsson1

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Connect our app to Atlas with the MongoDB Stitch Browser SDK @JoeKarlsson1

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

Authentication is Mandatory! @JoeKarlsson1 Providers ▪ Simple Login API ▪ Pluggable Authentication Providers ▪ Email/Password ▪ OAuth (Facebook/Google)
 ▪ Custom Authentication using JSON Web Token(JWT)
 ▪ Multiple Providers per App

Slide 46

Slide 46 text

Authentication is Mandatory! @JoeKarlsson1 Providers ▪ Simple Login API ▪ Pluggable Authentication Providers ▪ Email/Password ▪ OAuth (Facebook/Google)
 ▪ Custom Authentication using JSON Web Token(JWT)
 ▪ Multiple Providers per App

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

@JoeKarlsson1 ▪ Familiar query language. ▪ find, insert, update, aggregate
 ▪ Database access from client code (front-end)
 ▪ User level database access control. QueryAnywhere

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Stitch Services @JoeKarlsson1 * Includes more than 20 services

Slide 53

Slide 53 text

We need to create a Stitch Service to enable our function to send emails to a recipient using AWS SES @JoeKarlsson1

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

@JoeKarlsson1 Functions

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

@JoeKarlsson1 ▪ Fire in Response to Data Changes
 ▪ Built on MongoDB Change Streams
 ▪ Pass Change Events to Functions
 ▪ Use Multiple Triggers per Collection Triggers

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

Stitch Logs @JoeKarlsson1 Useful for auditing any events in your application Can also be invaluable in root cause analysis for any other issues

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

@JoeKarlsson1 Done!

Slide 62

Slide 62 text

Future of Serverless @JoeKarlsson1

Slide 63

Slide 63 text

FAQ @JoeKarlsson1 ▪ Can I use this for free? ▪ Yes! Stitch provides a free tier: ▪ The first 25 GB of data transfer per month is free. ▪ The minimum of 1,000,000 requests and 100,000 GB-seconds compute per month are free.
 ▪ Do I have to use the GUI? ▪ No, There is a CLI available ▪ https://docs.mongodb.com/stitch/deploy/ stitch-cli-reference/
 ▪ Do I have to use JS to write serverless functions? ▪ Yes
 ▪ How can I get started? ▪ $200 in free credits at: ▪ http://bit.ly/serverlessMN

Slide 64

Slide 64 text

@JoeKarlsson1 •Configured our app to connect to Stitch using the Stitch SDK •Enabled a Stitch Authentication Provider •Executed MongoDB commands from the front- end with QueryAnywhere •Create content sharing (ACL) with a couple of rules •Created a service linked to Amazon AWS SES •Created triggers that use functions to send emails

Slide 65

Slide 65 text

MongoDB Community • MongoDB University: • university.mongodb.com • MongoDB Community Slack Channel: • https://mongo-db.slack.com/ @JoeKarlsson1

Slide 66

Slide 66 text

Additional Resources • http://bit.ly/serverlessMN • $200 in free credits • university.mongodb.com • mongodb.com/cloud/stitch @JoeKarlsson1

Slide 67

Slide 67 text

@JoeKarlsson1 Thank you!

Slide 68

Slide 68 text

{ name: “Joe Karlsson”, company: “MongoDB”, title: [ “Developer Advocate”, “Software Engineer” ], twitter: “@JoeKarlsson1”, website: “joekarlsson.com”, }