MongoDB Web Architecture

Similar documents
Storage Tier. Mendel Rosenblum. CS142 Lecture Notes - Database.js

Front End Programming

Review. Fundamentals of Website Development. Web Extensions Server side & Where is your JOB? The Department of Computer Science 11/30/2015

welcome to BOILERCAMP HOW TO WEB DEV

Web Application Architectures

Evaluation Guide for ASP.NET Web CMS and Experience Platforms

Topics. History. Architecture. MongoDB, Mongoose - RDBMS - SQL. - NoSQL

Future Web App Technologies

Express.JS. Prof. Cesare Pautasso Modularity

Smashing Node.JS: JavaScript Everywhere

MEAN Stack. 1. Introduction. 2. Foundation a. The Node.js framework b. Installing Node.js c. Using Node.js to execute scripts

Tuesday, January 13, Backend III: Node.js with Databases

JavaScript CS 4640 Programming Languages for Web Applications

The NoPlsql and Thick Database Paradigms

Architectural Styles I

Node.js. Node.js Overview. CS144: Web Applications

About 1. Chapter 1: Getting started with mongoose 2. Remarks 2. Versions 2. Examples 4. Installation 4. Connecting to MongoDB database: 4

Anatomy of a SPA: Client-side MVC

Databases/JQuery AUGUST 1, 2018

SQLite vs. MongoDB for Big Data

Scaling DreamFactory

MongoDB w/ Some Node.JS Sprinkles

Full Stack boot camp

Masters in Web Development

a Very Short Introduction to AngularJS

JavaScript CS 4640 Programming Languages for Web Applications

Simple AngularJS thanks to Best Practices

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Laravel

DATABASE SYSTEMS. Database programming in a web environment. Database System Course, 2016

What is database? Types and Examples

Overview of Web Application Development

Open Source Library Developer & IT Pro

Mongoose for Application Development

Web Engineering (CC 552)

IBM DB2 JSON An overview of DB capabilities as a JSON document store

CLIENT SERVER ARCHITECTURE:

The NoSQL movement. CouchDB as an example

Chapter 11 Outline. A Simple PHP Example Overview of Basic Features of PHP Overview of PHP Database Programming. Slide 11-2

DIGIT.B4 Big Data PoC

Now go to bash and type the command ls to list files. The unix command unzip <filename> unzips a file.

Chapter 10 Web-based Information Systems

Extra Notes - Data Stores & APIs - using MongoDB and native driver

Enterprise Systems & Frameworks

20486-Developing ASP.NET MVC 4 Web Applications

FULL STACK FLEX PROGRAM

today what is this course about? what is this course about? Welcome to CSC309! Programming on the Web APRIL 05

Mobile Device Architecture CS 4720 Mobile Application Development

Security. CSC309 TA: Sukwon Oh

MASTERS COURSE IN FULL STACK WEB APPLICATION DEVELOPMENT W W W. W E B S T A C K A C A D E M Y. C O M

Enterprise Software Architecture & Design

Flash: an efficient and portable web server

Full Stack Developer with Java

Lecture 8. ReactJS 1 / 24

NOSQL EGCO321 DATABASE SYSTEMS KANAT POOLSAWASD DEPARTMENT OF COMPUTER ENGINEERING MAHIDOL UNIVERSITY

CS 142 Final Examination

Serverless Architecture Hochskalierbare Anwendungen ohne Server. Sascha Möllering, Solutions Architect

August, HPE Propel Microservices & Jumpstart

Getting MEAN. with Mongo, Express, Angular, and Node SIMON HOLMES MANNING SHELTER ISLAND

Project Avatar: Server Side JavaScript on the JVM GeeCon - May David Software Evangelist - Oracle

Anti-Patterns in Progress. Sean Overby Senior Technologist, Solvepoint Corporation

Backend Development. SWE 432, Fall 2017 Design and Implementation of Software for the Web

CS193X: Web Programming Fundamentals

SSC - Web applications and development Introduction and Java Servlet (I)

Nevin Dong 董乃文 Principle Technical Evangelist Microsoft Cooperation

Cloud Computing Platform as a Service

Distributed Architectures & Microservices. CS 475, Spring 2018 Concurrent & Distributed Systems

Excel4apps Wands 5 Architecture Excel4apps Inc.

<Insert Picture Here> MySQL Cluster What are we working on

Active Server Pages Architecture

Course Content MongoDB

Overview. * Some History. * What is NoSQL? * Why NoSQL? * RDBMS vs NoSQL. * NoSQL Taxonomy. *TowardsNewSQL

To Kill a Monolith: Slaying the Demons of a Monolith with Node.js Microservices on CloudFoundry. Tony Erwin,

Input and Validation. Mendel Rosenblum. CS142 Lecture Notes - Input

Online Multimedia Winter semester 2015/16

Modern Web Application Development. Sam Hogarth

Getting Mean. Practical Perspective. Prof. Dr. Alejandro Zunino, Prof. Dr. Alfredo Teyseyre. ISISTAN Department of Computer Science UNICEN

PROCE55 Mobile: Web API App. Web API.

Ten good practices for ASP.NET MVC applications

DATABASE SYSTEMS. Database programming in a web environment. Database System Course,

Web Software Model CS 4640 Programming Languages for Web Applications

SEEM4570 System Design and Implementation Lecture 03 JavaScript

Whitepaper. 4 Ways to Improve ASP.NET Performance. Under Peak Loads. Iqbal Khan. Copyright 2015 by Alachisoft

Azure Development Course

NoSQL & Firebase. SWE 432, Fall Web Application Development

Distributed Multitiered Application

Serverless and APIs: Rethinking Curriculum in Higher Education. Munir Mandviwalla and Jeremy Shafer Temple University

Architectural Styles I

Web Applications. Software Engineering 2017 Alessio Gambi - Saarland University

REST Easy with Infrared360

Sessions. Mendel Rosenblum. CS142 Lecture Notes - Sessions

Application Design and Development: October 30

SYMFONY2 WEB FRAMEWORK

Chris Bailey Bailey. Emerging Web Application Architectures With Java and Node.js

TDDD05: Application frameworks

MySQL & NoSQL: The Best of Both Worlds

MongoDB Schema Design

NoSQL Databases Analysis

Advance Mobile& Web Application development using Angular and Native Script

Backend Development. SWE 432, Fall Web Application Development

PROBLEMS IN PRACTICE: THE WEB MICHAEL ROITZSCH

Transcription:

MongoDB Web Architecture

MongoDB MongoDB is an open-source, NoSQL database that uses a JSON-like (BSON) document-oriented model. Data is stored in collections (rather than tables). - Uses dynamic schemas rather than a predefined structure. Fields can be added/removed at will. - Works with many programming languages. - Caching: Most recent kept in RAM. - No transactions, but allows atomic operations.

Example Relational data model Data as documents From: MongoDB_Architecture_Guide.pdf https://www.mongodb.com/json-and-bson

BSON? BSON is Binary JSON MongoDB encodes JSON documents in binary format behind the scenes BSON extends JSON to provide additional data types (int, long, date, floating point)

Schema Enforcement? JSON blobs provide flexibility but not what is always wanted Consider: <h1>hello {{person.informalname}}</h1> - Good: typeof person.informalname == 'string' and length < something - Bad: Type is 1GB object, or undefined, or null, or... Would like to enforce a schema on the data - Can be implemented as validators on mutating operations Mongoose - Object Definition Language (ODL) - Take familiar usage from ORMs and map it onto Mongoose - Effectively masks the lower level interface to MongoDB with something that is friendlier

Document validation Dynamic schemas provide great flexibility Controls to maintain data quality are also important MongoDB provides document validation within the database

How does it work? Using: var mongoose = require( mongoose'); 1. Connect to the MongoDB instance mongoose.connect('mongodb://localhost/myproject'); 2. Wait for connection to complete: Mongoose exports an EventEmitter mongoose.connection.on('open', function () { }); // Can start processing model fetch requests mongoose.connection.on('error', function (err) { }); Can also listen for connecting, connected, disconnecting, disconnected, etc.

Schema defines collections String, Number, Date, Buffer, Boolean Array - e.g. comments: [ObjectId] ObjectId - Reference to another object Mixed - Anything var userschema = new mongoose.schema({ first_name: String, last_name: String, emailaddresses: [String], location: String });

Schema allows secondary indexes and defaults Simple index first_name: {type: 'String', index: true} Index with unique enforcement user_name: {type: 'String', index: {unique: true} } Defaults date: {type: Date, default: Date.now }

Secondary Indexes Performance and space trade-off - Faster queries: Eliminate scans - database just returns the matches from the index - Slower mutating operations: Add, delete, update must update indexes - Uses more space: Need to store indexes and indexes can get bigger than the data itself When to use - Common queries spending a lot of time scanning - Need to enforce uniqueness

Make model from schema A Model in Mongoose is a constructor of objects A collection may or may not correspond to a model of the MVC var User = mongoose.model('user', userschema); Create objects from Model User.create({ first_name: 'Amy', last_name: 'Pond'}, donecallback); function donecallback(err, newuser) { assert (!err); console.log('created object with ID', newuser._id); }

Query collection Returning the entire User collection User.find(function (err, users) { /*users is an array of objects*/ }); Returning a single user object for user_id User.findOne({_id: user_id}, function (err, user) { /*... */ }); Updating a user object for user_id User.findOne({_id: user_id}, function (err, user) { // Update user object user.save(); });

Other query operations var query = User.find({}); Projections Sorting query.select( first_name last_name ).exec(donecallback); query.sort("first_name").exec(donecallback); Limits query.limit(50).exec(donecallback); query.sort("-location")

Deleting objects from collection Deleting a single user with id user_id User.remove({_id: user_id}, function (err) { } ); Deleting all the User objects User.remove({}, function (err) { } )

Web Architectures Higher level structures underlying a web ap Made up of elements, their properties and the relationships among elements

n-tier Separate the components of a web app into different tiers or layers - Components of a web application are presentation, processing logic, and data management - Benefit of separating into tiers is all the good software engineering properties

1-tier All three layers are on the same machine and presentation, logic and data are tightly connected. - Scalability: Single processor, no separation, hard to scale - Portability: moving to a new machine, or changing anything may mean major re-writes - Maintenance: Changing one layer requires changing other layers

2-tier Database runs on a server separate from application Presentation and logic layers are tightly coupled Can easily switch to a different database Coupling of presentation and logic can lead to heavy server load and network congestion.

3-tier Each tier is separate with a clear interface between them. Each tier can potentially run on a different machine Client-server Each tier is independent Unconnected tiers should not communicate Change in platform affects only that tier

Presentation layer Provides user interface and interactions Client-view or front-end Shouldn t contain business logic or data access code

Logic Layer Set of rules for processing the data and accommodates many individual users No presentation or access code

Data Layer Physical storage for data persistence Manages access to the DB or file system Also called the back-end No presentation or business logic

The presentation layer is the static or dynamically generated content rendered by the browser (front- end). The logic layer is responsible for dynamic content processing and generation, e.g. using Node.js, PHP, Java EE, ASP.NET (middleware). The data layer is the database, comprising the data sets and data management system (back-end).

The main benefit of 3-tier is the independence of layers, which means: - Easier maintenance - Reusable components - Faster development (division of work)

Model View Controller uses Controller manipulates User Model seen View updates

state query Model change notification view selection state change View Controller user action The model manages application state by responding to requests for information about it state (from the view) or instructions to change state (from the controller)

state query Model change notification view selection state change View Controller user action The view renders the model into a form suitable for interaction (user interface). Multiple views can exist for a single model given different contexts.

state query Model change notification view selection state change View Controller user action The controller receives user input and initiates a response by making updates to the state of objects in the model and selecting a view for the response.

In practice The model is made up of the database (tables or documents), session information (current state), and rules governing transactions. The view is the front-end website, made up of HTML, CSS, and server-side templates. The controller is any client-side scripting that manages user interactions, HTTP request processing, and business logic/preprocessing.

Benefits Clarity of design, e.g., model methods providing an API for data and state management. Separation of concerns, where any component can be easily used, replaced, or updated individually. Parallel development, with construction and maintenance based around adding parts in a modular fashion and separation of concerns. Distributable, ie., re-use of parts in different apps.

3-tier vs MVC Communication: While in 3-tier the presentation layer never communicates directly to the data layer (only through the logic layer), in MVC all layers communicate directly (triangle topology). Usage: In 3-tier, the client, middleware, and data tiers are on physically separate platforms, but in MVC the model, view, and controller are together.

Other Architectures SOA - Service Oriented Architecture - everything has a clear interface - service is a black box - https://apievangelist.com/2012/01/12/the-secret-toamazons-success-internal-apis/ Microservices - UNIX philosophy for the web - decoupled - https://martinfowler.com/articles/microservices.html

SPA vs MPA Single page architecture - load all html, css, and javascript on the first load - use javascript to modify page - request data from APIs and/or server Multipage architecture - changing views means requesting new html and new data from the server Pros and Cons? https://medium.com/@neotericeu/single-page-application-vs-multiple-page-application-2591588efe58

Bottom Line Applications need to persist data somewhere (model) Applications need to display information to users (view) The layer in between is where much of the complexity lies Designers and developers continue to explore different ways of thinking about how to describe the way in which the models and views are updated and managed.