The Richest Man in Babylon
The Richest Man in Babylon
LAMP is so yesterday -
MEAN is so tomorrow
1
Knowledge Sharing Session - MEAN architecture
Agenda
Who am I and what am I doing here?
What is LAMP?
Requirements for a modern web
Architecture
What is MEAN?
So why MEAN?
2
Knowledge Sharing Session - MEAN architecture
3
Knowledge Sharing Session - MEAN architecture
Google is founded
Paypal is founded
4
Knowledge Sharing Session - MEAN architecture
HTML/
HTML/
XML/
XML/ SQL
SQL
JSON
JSON
PHP
PHP (or
(or ASP,
ASP, Python,
Python,
JavaScript
JavaScript Perl,…)
Perl,…)
SQL
SQL based
based on
on dialect
dialect
5
Knowledge Sharing Session - MEAN architecture
??
F ?
W T
Source:
http://en.wikipedia.org/wiki/LAMP_(software_bundle)
6
Knowledge Sharing Session - MEAN architecture
7
Knowledge Sharing Session - MEAN architecture
8
Knowledge Sharing Session - MEAN architecture
9
Knowledge Sharing Session - MEAN architecture
What is MEAN?
"MEAN is a fullstack JavaScript platform for modern web
applications“ - Mean.io
JSON
JSON JSON
JSON
JavaScript
JavaScript JavaScript
JavaScript JSON
JSON (BSON)
(BSON)
11
Knowledge Sharing Session - MEAN architecture
So why MEAN?
100% free
100% Open Source
100% Java Script (+JSON and HTML)
100% Web Standards
Huge community
Consistent Models from the backend to the frontend and back
Use a uniform language throughout your stack
JavaScript (the language of the web)
12
Knowledge Sharing Session - MEAN architecture
Source: http://blog.stackoverflow.com/2014/02/2013-stack-overflow-user-survey-results/
13
Knowledge Sharing Session - MEAN architecture
Source: http://blog.stackoverflow.com/2014/02/2013-stack-overflow-user-survey-results/
14
Knowledge Sharing Session - MEAN architecture
Source: http://blog.stackoverflow.com/2014/02/2013-stack-overflow-user-survey-results/
15
Knowledge Sharing Session - MEAN architecture
16
Knowledge Sharing Session - MEAN architecture
17
Knowledge Sharing Session - MEAN architecture
Source: https://docs.angularjs.org/guide/databinding
18
Knowledge Sharing Session - MEAN architecture
Source: https://docs.angularjs.org/guide/databinding
19
Knowledge Sharing Session - MEAN architecture
Source: https://docs.angularjs.org/guide/concepts
20
Knowledge Sharing Session - MEAN architecture
Angular JS – My experience
Source:
http://www.bennadel.com/blog/2
439-my-experience-with-
angularjs-the-super-heroic-
javascript-mvw-framework.htm
21
Knowledge Sharing Session - MEAN architecture
DEMO - Time:
http://jsfiddle.net/m9XKE/4
22
Knowledge Sharing Session - MEAN architecture
23
Knowledge Sharing Session - MEAN architecture
24
Knowledge Sharing Session - MEAN architecture
25
Knowledge Sharing Session - MEAN architecture
Node JS - Architecture
libuv
26
Knowledge Sharing Session - MEAN architecture
// takes 120ms
var contentsPwd = fs.readFileSync('/etc/passwd'); 120ms
// takes 40ms
console.log(contentsPwd); 40ms
– Takes SUM(100,30,120,40) = 290ms
Non-Blocking I/O
//takes 130ms
fs.readFile('/etc/hosts', function(err, contents) { 130ms
console.log(contents);
});
//takes 160ms
fs.readFile('/etc/passwd', function(err, contents) { 160ms
console.log(contents);
});
27
Knowledge Sharing Session - MEAN architecture
Node JS – Callbacks
myCoolFunction(myArguments, function (err,
data) {
if (err) {
// Handle Error
}
// Do something with the result (data).
});
X
!
db.query(userQuery, [id], function (userErr, userResults) {
db.query(activityQuery, function (activityErr, activityResults) {
db.query(leaderBoardQuery, function (leaderBoardErr,
leaderBoardResults) {
// Do something here
});
});
[…]
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(myJavascriptObject.getSomeStatusInfo());
}).listen(1337, "127.0.0.1");
Source: http://www.aaronstannard.com/post/2011/12/14/Intro-to-NodeJS-for-NET-Developers.aspx
29
Knowledge Sharing Session - MEAN architecture
Solutions:
Source: http://bocoup.com/weblog/node-stress-test-analysis
30
Knowledge Sharing Session - MEAN architecture
Source: https://www.paypal-engineering.com/2013/11/22/node-js-at-paypal/
31
Knowledge Sharing Session - MEAN architecture
32
Knowledge Sharing Session - MEAN architecture
33
Knowledge Sharing Session - MEAN architecture
34
Knowledge Sharing Session - MEAN architecture
server.listen(8080, function() {
console.log('%s listening at %s', server.name, server.url);
});
$ bosch-rest>node rest
restify listening at http://0.0.0.0:8080
35
Knowledge Sharing Session - MEAN architecture
36
Knowledge Sharing Session - MEAN architecture
37
Knowledge Sharing Session - MEAN architecture
38
Knowledge Sharing Session - MEAN architecture
39
Knowledge Sharing Session - MEAN architecture
40
Knowledge Sharing Session - MEAN architecture
41
Knowledge Sharing Session - MEAN architecture
42
Knowledge Sharing Session - MEAN architecture
43
Knowledge Sharing Session - MEAN architecture
44
Knowledge Sharing Session - MEAN architecture
45
Knowledge Sharing Session - MEAN architecture
46
Knowledge Sharing Session - MEAN architecture
47
Knowledge Sharing Session - MEAN architecture
MongoDB – Terminology
MongoDB RDBMS
Collection Table
Document Row
Index Index
Embedded Document Join
Reference Foreign Key
Source: http://www.mongodb.com/presentations/building-your-first-mean-app
48
Knowledge Sharing Session - MEAN architecture
MongoDB - Document
Source: http://docs.mongodb.org/manual/core/crud-introduction
49
Knowledge Sharing Session - MEAN architecture
Source: http://www.mongodb.com/presentations/building-your-first-mean-app
50
Knowledge Sharing Session - MEAN architecture
MongoDB - Collection
Source: http://docs.mongodb.org/manual/core/crud-introduction
51
Knowledge Sharing Session - MEAN architecture
Source: http://docs.mongodb.org/manual/core/crud-introduction
52
Knowledge Sharing Session - MEAN architecture
Source: http://docs.mongodb.org/manual/core/crud-introduction
53
Knowledge Sharing Session - MEAN architecture
Source: http://docs.mongodb.org/manual/core/crud-introduction
54
Knowledge Sharing Session - MEAN architecture
Source: http://docs.mongodb.org/manual/core/crud-introduction
55
Knowledge Sharing Session - MEAN architecture
MongoDB – Aggregation
Source: http://docs.mongodb.org/manual/core/crud-introduction
56
Knowledge Sharing Session - MEAN architecture
Source: http://docs.mongodb.org/manual/core/crud-introduction
57
Knowledge Sharing Session - MEAN architecture
Source: http://docs.mongodb.org/manual/core/crud-introduction
58
Knowledge Sharing Session - MEAN architecture
MongoDB – Replication
Source: http://docs.mongodb.org/manual
59
Knowledge Sharing Session - MEAN architecture
Source: http://docs.mongodb.org/manual
60
Knowledge Sharing Session - MEAN architecture
Source: http://docs.mongodb.org/manual
61
Knowledge Sharing Session - MEAN architecture
MongoDB – Sharding
Sharding = horizontal scaling
Method for storing data across multiple machines
divides the data set and distributes the data over multiple
servers, or shards
Each shard is an independent database, and collectively, the
systems
Source: http://docs.mongodb.org/manual
62
Knowledge Sharing Session - MEAN architecture
MongoDB – Sharding
Source: http://docs.mongodb.org/manual
63
Knowledge Sharing Session - MEAN architecture
Do not deploy
production clusters
without 3 config servers!
Source: http://docs.mongodb.org/manual
64
Knowledge Sharing Session - MEAN architecture
Source: http://docs.mongodb.org/manual
65
Knowledge Sharing Session - MEAN architecture
MEAN – Security
It’s as insecure as you code it
It’s JavaScript, so you have to be careful
Always use “strict” mode -> “use strict” in JavaScript file
Always declare variables
Always throw all errors
Always handle all callbacks (e.g. success AND error)
Use patterns for visibility (e.g. module pattern)
Do static code analysis (JSHint/JSLint)
Always encode untrusted data
Angular provides sanitizer
https://docs.angularjs.org/api/ngSanitize/service/$sanitize
Express Framework can help you here
Easily handles CSRF
Helps you sanitize inputs
And of course - never run any application as root! ;)
Test Test Test
66
Knowledge Sharing Session - MEAN architecture
Service Route
Controller Controller
View Model
Source: http://www.mongodb.com/presentations/building-your-first-mean-app
67
Knowledge Sharing Session - MEAN architecture
68
Knowledge Sharing Session - MEAN architecture
Sources
Mean.io
http://www.mean.io
AngularJS
https://angularjs.org
MongoDB
http://mongodb.org
NodeJS
https://nodejs.org
Express
http://expressjs.com
db-expressjs-angularjs-and
69
Knowledge Sharing Session - MEAN architecture
Questions?
70