Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Gentle Introduction to Building Serverless Apps with MongoDB Stitch

A Gentle Introduction to Building Serverless Apps with MongoDB Stitch

Do you want to crank out features the business wants, or spend a lot of time writing code and capacity planning for authentication, authorization, and complicated data access? Of course we all know the answer.

In this session will begin a beginner friendly introduction to Serverless computing. We will then do a quick overview of the MongoDB ecosystem in the 3 major cloud providers for rapid application building. Then we will walk through a guided tutorial of how to use the MongoDB Stitch serverless platform to build your elastically scalable microservices based app within minutes, complete with end-user authentication and access rules, on a fully managed MongoDB cluster in your favorite cloud platform.

Joe Karlsson

August 26, 2019
Tweet

More Decks by Joe Karlsson

Other Decks in Programming

Transcript

  1. { name: “Joe Karlsson”, company: “MongoDB”, title: [ “Developer Advocate”,

    “Software Engineer” ], twitter: “@JoeKarlsson1”, website: “joekarlsson.com”, }
  2. Agenda ▪ Quick MongoDB overview ▪ Intro to Serverless ▪

    Guided Serverless tutorial with Stitch @JoeKarlsson1
  3. 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 } ] }
  4. SQL MongoDB Query faster! Stop doing expensive joins to get

    your data. ID a ... 1 b ... 2 ... ... 3 ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... { ...
 a: “b”,
 ... c: {
 d: “e”
 ...
 },
 ... } @JoeKarlsson1
  5. 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
  6. 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
  7. 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
  8. Agenda ▪ Quick MongoDB overview ▪ Intro to Serverless ▪

    Guided Serverless tutorial with Stitch @JoeKarlsson1
  9. ▪ No managing of infrastructure whatsoever. ▪ No provisioning. ▪

    No patching. ▪ No capacity planning. ▪ No scaling. @JoeKarlsson1
  10. 77% 
 increase in delivery speed Serverless Survey: +77% Delivery

    Speed, 4 Dev Workdays/Mo Saved & -26% AWS Monthly Bill by Annika Helendi @JoeKarlsson1
  11. A serverless platform that makes it easy to build modern,

    cross-platform apps with MongoDB @JoeKarlsson1
  12. 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)
  13. 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
  14. 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)
  15. 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)
  16. 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)
  17. 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
  18. 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)
  19. 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
  20. 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
  21. Agenda ▪ Quick MongoDB overview ▪ Intro to Serverless ▪

    Guided Serverless tutorial with Stitch @JoeKarlsson1
  22. App Architecture @JoeKarlsson1 Stitch MongoDB Atlas Journal.entries Trigger onSharedItems Function

    notifyUsersOfShare Services Amazon SES React Journal App Amazon SES
  23. 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
  24. 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
  25. @JoeKarlsson1 ▪ Familiar query language. ▪ find, insert, update, aggregate


    ▪ Database access from client code (front-end)
 ▪ User level database access control. QueryAnywhere
  26. We need to create a Stitch Service to enable our

    function to send emails to a recipient using AWS SES @JoeKarlsson1
  27. @JoeKarlsson1 ▪ Fire in Response to Data Changes
 ▪ Built

    on MongoDB Change Streams
 ▪ Pass Change Events to Functions
 ▪ Use Multiple Triggers per Collection Triggers
  28. Stitch Logs @JoeKarlsson1 Useful for auditing any events in your

    application Can also be invaluable in root cause analysis for any other issues
  29. 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
  30. @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
  31. MongoDB Community • MongoDB University: • university.mongodb.com • MongoDB Community

    Slack Channel: • https://mongo-db.slack.com/ @JoeKarlsson1
  32. Additional Resources • http://bit.ly/serverlessMN • $200 in free credits •

    university.mongodb.com • mongodb.com/cloud/stitch @JoeKarlsson1
  33. { name: “Joe Karlsson”, company: “MongoDB”, title: [ “Developer Advocate”,

    “Software Engineer” ], twitter: “@JoeKarlsson1”, website: “joekarlsson.com”, }