i know it was mean but i cut the cord to lamp anyway

42
I Know it was MEAN but I Cut the Cord to LAMP Anyway

Upload: brianhyder

Post on 21-Aug-2015

271 views

Category:

Technology


1 download

TRANSCRIPT

I Know it was MEAN

but I Cut the Cord to LAMP Anyway

The Next Milestone in Web Development

[email protected]

@GetPencilBlue

Planning Development Deployment

Actually do it Managing the flexibility What are my options?

Do I need a framework? The Basics The Upgrade

Dealing with SEO Simplifying Client Code Server Options

Finding the Right Talent Promise vs. Callback Choosing a Cloud

Follow along at:

pencilblue.org/presentation

MongoDB

Planning - Failing to Plan

Pros ConsEasy Install Not good for inter object relationships

Flexible

Quick Development

Development - Prototyping vs. Production

Development - Flexible Base Service

+ save+ delete+ load

Widget Service

+ save+ delete+ load

Widget Service

+ save

Sprocket Service

+ save

{ object_type: “widget”, name: “”, description: “”}:

Development - Too Flexible?

Document with Strings{ object_type: “event”, type: “startup”, location: { lat: “35.7806”, lon: “78.6389” }}

Document with Floats{ object_type: “event”, type: “startup”, location: { lat: 35.7806, lon: 78.6389 }}

● Valid JSON● Pases non-strict validation (JS)● Geospatial index fails on insert

Development - Schema Documentation

Development - Common Data Fields

{ “first_name”: “Charlie”, “last_name”: “Daniels”, ...

“doc_type”: “user”, “doc_version”: 1, “created”: “2014-09-11 15:01:07.602Z”, “last_modified”: “2014-09-11 15:01:07.602Z”, “created_by”: "5411b9334572668410000fd0”, “last_modified_by”: "5411b9334572668410000fd0”}

Development - Geospatial Indexing

The $geoWithin operator does not return sorted results. As a result MongoDB can return $geoWithin queries more quickly than geospatial $near or $nearSphere queries, which sort results.

db.places.find( { loc : { $near : [50,50] , $maxDistance : 5 } } );

db.places.find( { "loc": { "$geoWithin": { "$center": [[50, 50, 5] } } });

==

Deployment - Expense at Scale

Deployment Cost Managed

AWS m1.large $0.20/hr NO

Mongo HQ $18/GB* YES

Mongo Lab $15/GB* YES

Linode Medium $20/mo NO

* Other base fees may apply

Deployment - MMS & Getting to Scale

Routing & Frameworks

Planning - Do I need a framework?

● IS IT OPEN SOURCE?● How often will I need to upgrade?● If the project goes stagnant does that affect me?● If the project gets bought by a company I don’t like does that affect me?● What kind of custom functionality do I need to inject?● Will packages be sufficient or will I need to fork so I can experiment?● Do I want to maintain something custom?● Can I do as well as or better than what is already out there?

Planning - Rube Goldberg of Software

Planning - The Forum Conundrum

Development - The Basic Example

var express = require('express')var app = express()

app.get('/', function (req, res) { res.send('Hello World!')})

var server = app.listen(3000, function () {

var host = server.address().address var port = server.address().port console.log('Example app listening at http://%s:%s', host, port)})

Deployment - Upgrading

What happens when I try to upgrade?

Chance of Conflict

Time

Angular

Planning - Google did it!

Planning - Weighing In

Planning - Documentation

Pros ConsLarge Documentation Site API Documentation assumes

understanding of Angular

Support Groups Error handling can be cryptic

Guided Tutorials & Example Projects

Planning - Crawlers and Javascript

Pros Cons

Server Rendered Landing Pages

SEO becomes easier because it is the traditional model.

Even mediocre crawlers can navigate your site

Mix and match of SPA and traditional model

Tracking which pages need to be rendered server-side

Single Page App Consistent SEO implementation

Metadata data changes based on page context

Google is only search engine boasting javascript execution.

Development - A Simple Example

<ol> <li ng-repeat="user in users" ng-bind="user"></li></ol>

//service codeangular.module('myservices', []).service('simpleService', function(){ this.getUsers = function() { return ['John', 'James', 'Jake']; }});

//controller codeangular.module('myapp', ['myservices']).controller('SimpleController', function($scope, simpleService) { $scope.users = simpleService.getUsers();});

Development - A Growing Stack

Data Access

Service Layer and Business Logic

API Controller

Angular Service

Angular ControllerClient

Server

Separation of Concern => Testability

describe("Unit Testing Examples", function() {

beforeEach(angular.mock.module('App'));

it('should have a LoginCtrl controller', function() { expect(App.LoginCtrl).toBeDefined(); });

it('should have a working LoginService service', inject(['LoginService', function(LoginService) { expect(LoginService.isValidEmail).not.to.equal(null); }]) );});

Deployment - Serving a Single Page App?

Considerations:

● How much data do I need to persist?● Is my application solely a SPA?

Possible Options:

● Apache / PHP● Python● Rails● Node.js

Node.js

Planning - Resource Management

Now that I use the same language across the entire stack hiring just got simpler.

Planning - Resource Management

Planning - Adoption

Big names are jumping on board:

● Linkedin● Walmart Labs● PencilBlue

http://nodejs.org/industry/

Development - Promise vs. Callback

//Promise examplefunction fs_readFile (file, encoding) { var deferred = Q.defer() fs.readFile(file, encoding, function (err, data) { if (err) { deferred.reject(err) // rejects the promise with `er` as the reason } else { deferred.resolve(data) // fulfills the promise with `data` as the value } }) return deferred.promise // the promise is returned}

fs_readFile('myfile.txt').then(console.log, console.error)Courtesy of StrongLoop

Development - Promise vs. Callback

//Callback examplefunction fs_readFile (file, encoding, cb) {

fs.readFile(file, encoding, cb);}

fs_readFile('myfile.txt', function (err, data) { if (err) { console.error(err) // outputs error } else { console.log(data) // output result } });

Courtesy of StrongLoop

Development - Node Inspector

Development - Clustering

if (cluster.isMaster) System.onMasterRunning();else onChildRunning();

System.onMasterRunning = function() { //spawn workers var workerCnt = os.cpus().length; for (var i = 0; i < workerCnt; i++) { cluster.fork(); } cluster.on('disconnect', System.onWorkerDisconntect);

pb.log.info('System[%s]: %d workers spawned. Listening for disconnects.', System.getWorkerId(), workerCnt);};

Core 1 Core 2 Core 3 Core 4 Core 5 Core 6 Core 7

MW W W W W W W

Development - Error Handling

var http = require(‘http’); var domain = require(‘domain’);

http.createServer(function(req, res){

var d = domain.create(); d.add(req); d.add(res); d.on(‘error’, handleError);

d.run(function() { handleRequest(req, res); });

}).listen(8080);

Deployment - Shooting for the Cloud

Elastic Beanstalk OpenShift Nodejitsu Bluemix

Linode Heroku

Deployment - Starting Simple

LB

M

W

M

W

W

W

Use SSL Termination

Pay for the backup service

Write a procedure for creating these nodes

Pros Cons

Extremely FlexibleRapid Development

Expensive at Scale

Fast “Good Enough” HTTP Server Upgrades cause code changes

A battle tank that can do anything Error messages are a bit obfuscated

Fast and efficient Hard to debug

To Recap...

The choice is yours but...