SlideShare a Scribd company logo
JavaScript Everywhere
            From Nose To Tail




            Carl Husselbee - Sensis
Cliffano Subagio (@cliffano) - Shine Technologies
Citysearch.com.au
New Platform

  Improved application performance
  Better memory usage
  Improved content publishing reliability
  Zero content duplication
  Improved user experience

(project is still ongoing...)
The Three Amigos



 +         +
One JavaScript To Rule Them All
In A Nutshell
CouchDB
         Document oriented

             Schema free

    Design document in JavaScript

        Incremental replication

              HTTP API
Document

Simply a JSON object
{
    "_id": "listing-123",
    "_rev": "D1C946B7",
    "business_name": "Wolfgang Puck",
    "desc": "Fine dining and casual dining...",
    "rating": 5,
    "city": "Melbourne"
}

Stays as JSON on all layers
Replication


 Content publishing - replication rule
 curl -X POST "http://host/_replicate"
 -d '{"source": "db-src", "target": "db-target", "continuous": true}'
 -H "Content-Type: application/json"

 Content indexing - continuous changes feed
 curl -X GET "http://host/db/_changes?feed=continuous&since=123"
Design Document
A simple map reduce
"views": {
   "melbourne_rating": {
     "map": function (doc) {
         if (doc.city === 'Melbourne') { emit(null, doc.rating); }
     },
     "reduce": function (key, values, rereduce) {
         return sum(values);
     }}}

Highly testable
Easy to mock up
Cradle


CouchDB client for Node.js
Uses CouchDB REST API
Asynchronous
Built-in caching
Node.js

          Server-side JavaScript


              Based on V8


             Single Threaded


            Non-blocking I/O
Single Threaded
No more thread deadlock
More predictable app server memory usage
Like Nginx vs Apache
Non-blocking I/O

I/O is expensive
Traditional web app wastes time on I/O
 // blocking                      // non-blocking
 var listings = db.getListings(); var callback = function
 render(listings);                (listings) {
                                      render(listings);
                                  }
                                  db.getListings(callback);


Node.js provides non-blocking API
The Callback Trap
Nested Callbacks
var util = require(‘util’), listingId = 'listing-123';
function commentsCb(err, result) {
   if (err) {
   } else {
       console.log('Comments: ' + util.inspect(result));
   }
}
function listingCb(err, result) {
   if (err) {
   } else {
       console.log('Listing: ' + util.inspect(result));
       db.getComments(listingId, commentsCb)
   }
}
db.getListing(listingId, listingCb);
A Better Way
Use control flow module
var async = require('async'), listingId = 'listing-123';
function getComments(cb) {
    db.getComments(listingId, cb);
}
function getListing(cb) {
    db.getListing(listingId, cb);
}
async.parallel({ comments: getComments, listing: getListing },
function (err, results) {
    // results gives { listing: listingResult, comments: commentsResult }
});

Lots of other solutions: TameJS, Step, Seq, etc
Async In A Loop

This looks innocent

for (var i = 0; i < 1000000; i++) {
   console.log('Meditate on this, you must!');
}
Async In A Loop


console.log is asynchronous
Node.js is faster than terminal display
Library Changes

Within the past one year:
 Homegrown web framework >> Express
 node-couch >> Cradle
 Various template engines >> Jazz
 Promises >> Callbacks + Async
Testing

Insanely fast even on slow PC
15,000 SLOC
100% test coverage
34 seconds
YUITest, JSCoverage, nodelint
Homegrown Modules
Jazz - template engine
{foreach doc in widget.docs}
   {if (doc.type eq 'video')}
       <span><a href="{doc.videourl}">{doc.title}</a></span>
   {else}
       <a href="{helper.createUrl(doc.key)}">
          <h3>{doc.title}</h3>
       </a>
   {end}
{end}

No business logic
Synchronous compilation, asynchronous evalua
More Homegrown Modules


Log4js-node - logging framework
Severity level and rolling log file
Couchtato - CouchDB document utility tool
Doesn’t require CouchDB design doc knowledge
Continuous Integration


 Jenkins Node.js Plugin
 Nestor - Jenkins Node.js CLI
Conclusion




      CouchDB rocks! Node.js rocks!
       JavaScript web stack rocks!
Questions?
Resources
CouchDB - http://couchdb.apache.org

Node.js - http://nodejs.org

Jazz - http://github.com/shinetech/jazz

log4js-node - http://github.com/csausdev/log4js-node

Couchtato - http://github.com/cliffano/couchtato

Jenkins Node.js Plugin - https://wiki.jenkins-ci.org/display/JENKINS/NodeJS
+Plugin

Nestor - http://github.com/cliffano/nestor
Credits


 http://www.flickr.com/photos/daveaustria/2654190796/ by Dave Austria

 http://www.flickr.com/photos/38485387@N02/3580728177/ by flickrfavorites

 http://www.housecontainer.nl/blog/about-me/127-dj-yoda-from-star-wars.html

 http://www.miccicohan.net/blog/studio-antics-and-of-coursethe-rolling-stones/

More Related Content

PDF
Scalable Angular 2 Application Architecture
PDF
Benchx: An XQuery benchmarking web application
ODP
BaseX user-group-talk XML Prague 2013
PDF
Будь первым
PDF
Redux. From twitter hype to production
PPT
Mobile webapplication development
PDF
MLBlock
PDF
A real-world Relay application in production - Stefano Masini - Codemotion Am...
Scalable Angular 2 Application Architecture
Benchx: An XQuery benchmarking web application
BaseX user-group-talk XML Prague 2013
Будь первым
Redux. From twitter hype to production
Mobile webapplication development
MLBlock
A real-world Relay application in production - Stefano Masini - Codemotion Am...

What's hot (20)

PDF
AWS user group September 2017 - Rob Ribeiro "Seeking Solutions for Debugging ...
PDF
Functional Web Development
PDF
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
ODP
Event Loop in Javascript
PDF
Flask and Angular: An approach to build robust platforms
PDF
«От экспериментов с инфраструктурой до внедрения в продакшен»​
PDF
Google App Engine Developer - Day4
PDF
"Service Worker: Let Your Web App Feel Like a Native "
KEY
Playing With Fire - An Introduction to Node.js
PDF
Cutting Edge Data Processing with PHP & XQuery
PDF
Server Side Event Driven Programming
PDF
Docker in Action
PPT
Mssql to mysql - Anton Ivanov
PPT
Headless drupal + react js Oleksandr Linyvyi
PPTX
OpenStreetMap is Data
PPTX
Scalable network applications, event-driven - Node JS
PDF
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API
PDF
Umleitung: a tiny mochiweb/CouchDB app
PDF
LAMP Stack (Reloaded) - Infrastructure as Code with Terraform & Packer
PDF
非同期javascriptの過去と未来
AWS user group September 2017 - Rob Ribeiro "Seeking Solutions for Debugging ...
Functional Web Development
Going fullstack React(ive) - Paulo Lopes - Codemotion Amsterdam 2017
Event Loop in Javascript
Flask and Angular: An approach to build robust platforms
«От экспериментов с инфраструктурой до внедрения в продакшен»​
Google App Engine Developer - Day4
"Service Worker: Let Your Web App Feel Like a Native "
Playing With Fire - An Introduction to Node.js
Cutting Edge Data Processing with PHP & XQuery
Server Side Event Driven Programming
Docker in Action
Mssql to mysql - Anton Ivanov
Headless drupal + react js Oleksandr Linyvyi
OpenStreetMap is Data
Scalable network applications, event-driven - Node JS
[Kotlin Serverless 工作坊] 單元 3 - 實作 JSON API
Umleitung: a tiny mochiweb/CouchDB app
LAMP Stack (Reloaded) - Infrastructure as Code with Terraform & Packer
非同期javascriptの過去と未来
Ad

Viewers also liked (7)

KEY
5 Tips for Writing Better JavaScript
PDF
Using Node.js for everything or what it is to write a book about it
PDF
Developing large scale JavaScript applications
PDF
jQquerysummit - Large-scale JavaScript Application Architecture
PDF
Reactjs - the good, the bad and the ugly
PPTX
Unidirectional data flow
PDF
Modern Web Applications
5 Tips for Writing Better JavaScript
Using Node.js for everything or what it is to write a book about it
Developing large scale JavaScript applications
jQquerysummit - Large-scale JavaScript Application Architecture
Reactjs - the good, the bad and the ugly
Unidirectional data flow
Modern Web Applications
Ad

Similar to Javascript Everywhere From Nose To Tail (20)

KEY
Practical Use of MongoDB for Node.js
PPTX
Intro to node and mongodb 1
PDF
Nodejs - A quick tour (v6)
PPTX
Node.js and MongoDB from scratch, fully explained and tested
PPTX
NodeJS
PPT
Node js
PDF
Writing RESTful web services using Node.js
PDF
Nodejs - A quick tour (v5)
PPTX
Building and Scaling Node.js Applications
PPTX
Getting Started with MongoDB and NodeJS
PPTX
Introduction to Node.js
PPTX
Intro To Node.js
PDF
Nodejs - A quick tour (v4)
PDF
Introduction to Node.js
PDF
Intro to node.js - Ran Mizrahi (27/8/2014)
PDF
Intro to node.js - Ran Mizrahi (28/8/14)
ZIP
From Java To Node.js
PDF
Nodejs - Should Ruby Developers Care?
KEY
Writing robust Node.js applications
PDF
Node.js Introduction
Practical Use of MongoDB for Node.js
Intro to node and mongodb 1
Nodejs - A quick tour (v6)
Node.js and MongoDB from scratch, fully explained and tested
NodeJS
Node js
Writing RESTful web services using Node.js
Nodejs - A quick tour (v5)
Building and Scaling Node.js Applications
Getting Started with MongoDB and NodeJS
Introduction to Node.js
Intro To Node.js
Nodejs - A quick tour (v4)
Introduction to Node.js
Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (28/8/14)
From Java To Node.js
Nodejs - Should Ruby Developers Care?
Writing robust Node.js applications
Node.js Introduction

More from Cliffano Subagio (20)

PDF
Cross-Workloads Resource-Level Relationship in AWS
PDF
AEM OpenCloud Delivery Practices
PDF
OpenAPI Generator The Babel Fish of The API World - apidays Live Paris
PDF
OpenAPI Generator The Babel Fish of The API World - apidays Live Australia
PDF
A Journey to Improve Infrastructure Compliance With InSpec
PDF
How to Fit an Infrastructure Platform into Multiple Enterprise Environments
PDF
Swagger AEM - An OpenAPI Specification for AEM
PDF
Introducing AEM OpenCloud
PDF
A Quick Look at Accessibility in the World of DevOps
PDF
Conversation With Your Application Using DialogFlow and CloudFunctions
PDF
Let's Build Voice Assistant Learning Games For Kids
PDF
Having A Talk With Jenkins
PDF
AEM Open Cloud - The First Two Years
PDF
AEM OpenCloud - What's New Since 2.0.0
PDF
Beyond AEM Curl Commands
PDF
AEM OpenCloud
PDF
Open Source AEM Platform: A Short Intro
PDF
How To Play Music On A Vacuum Cleaner
PDF
Bringing Jenkins Remote Access API To The Masses
PDF
Application Deployment Using Ansible
Cross-Workloads Resource-Level Relationship in AWS
AEM OpenCloud Delivery Practices
OpenAPI Generator The Babel Fish of The API World - apidays Live Paris
OpenAPI Generator The Babel Fish of The API World - apidays Live Australia
A Journey to Improve Infrastructure Compliance With InSpec
How to Fit an Infrastructure Platform into Multiple Enterprise Environments
Swagger AEM - An OpenAPI Specification for AEM
Introducing AEM OpenCloud
A Quick Look at Accessibility in the World of DevOps
Conversation With Your Application Using DialogFlow and CloudFunctions
Let's Build Voice Assistant Learning Games For Kids
Having A Talk With Jenkins
AEM Open Cloud - The First Two Years
AEM OpenCloud - What's New Since 2.0.0
Beyond AEM Curl Commands
AEM OpenCloud
Open Source AEM Platform: A Short Intro
How To Play Music On A Vacuum Cleaner
Bringing Jenkins Remote Access API To The Masses
Application Deployment Using Ansible

Recently uploaded (20)

PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Understanding_Digital_Forensics_Presentation.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Spectroscopy.pptx food analysis technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
KodekX | Application Modernization Development
PDF
Empathic Computing: Creating Shared Understanding
PDF
Encapsulation theory and applications.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Approach and Philosophy of On baking technology
Reach Out and Touch Someone: Haptics and Empathic Computing
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
MYSQL Presentation for SQL database connectivity
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Understanding_Digital_Forensics_Presentation.pptx
The AUB Centre for AI in Media Proposal.docx
Spectroscopy.pptx food analysis technology
20250228 LYD VKU AI Blended-Learning.pptx
sap open course for s4hana steps from ECC to s4
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
KodekX | Application Modernization Development
Empathic Computing: Creating Shared Understanding
Encapsulation theory and applications.pdf
Big Data Technologies - Introduction.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Approach and Philosophy of On baking technology

Javascript Everywhere From Nose To Tail

  • 1. JavaScript Everywhere From Nose To Tail Carl Husselbee - Sensis Cliffano Subagio (@cliffano) - Shine Technologies
  • 3. New Platform Improved application performance Better memory usage Improved content publishing reliability Zero content duplication Improved user experience (project is still ongoing...)
  • 5. One JavaScript To Rule Them All
  • 7. CouchDB Document oriented Schema free Design document in JavaScript Incremental replication HTTP API
  • 8. Document Simply a JSON object { "_id": "listing-123", "_rev": "D1C946B7", "business_name": "Wolfgang Puck", "desc": "Fine dining and casual dining...", "rating": 5, "city": "Melbourne" } Stays as JSON on all layers
  • 9. Replication Content publishing - replication rule curl -X POST "http://host/_replicate" -d '{"source": "db-src", "target": "db-target", "continuous": true}' -H "Content-Type: application/json" Content indexing - continuous changes feed curl -X GET "http://host/db/_changes?feed=continuous&since=123"
  • 10. Design Document A simple map reduce "views": { "melbourne_rating": { "map": function (doc) { if (doc.city === 'Melbourne') { emit(null, doc.rating); } }, "reduce": function (key, values, rereduce) { return sum(values); }}} Highly testable Easy to mock up
  • 11. Cradle CouchDB client for Node.js Uses CouchDB REST API Asynchronous Built-in caching
  • 12. Node.js Server-side JavaScript Based on V8 Single Threaded Non-blocking I/O
  • 13. Single Threaded No more thread deadlock More predictable app server memory usage Like Nginx vs Apache
  • 14. Non-blocking I/O I/O is expensive Traditional web app wastes time on I/O // blocking // non-blocking var listings = db.getListings(); var callback = function render(listings); (listings) { render(listings); } db.getListings(callback); Node.js provides non-blocking API
  • 16. Nested Callbacks var util = require(‘util’), listingId = 'listing-123'; function commentsCb(err, result) { if (err) { } else { console.log('Comments: ' + util.inspect(result)); } } function listingCb(err, result) { if (err) { } else { console.log('Listing: ' + util.inspect(result)); db.getComments(listingId, commentsCb) } } db.getListing(listingId, listingCb);
  • 17. A Better Way Use control flow module var async = require('async'), listingId = 'listing-123'; function getComments(cb) { db.getComments(listingId, cb); } function getListing(cb) { db.getListing(listingId, cb); } async.parallel({ comments: getComments, listing: getListing }, function (err, results) { // results gives { listing: listingResult, comments: commentsResult } }); Lots of other solutions: TameJS, Step, Seq, etc
  • 18. Async In A Loop This looks innocent for (var i = 0; i < 1000000; i++) { console.log('Meditate on this, you must!'); }
  • 19. Async In A Loop console.log is asynchronous Node.js is faster than terminal display
  • 20. Library Changes Within the past one year: Homegrown web framework >> Express node-couch >> Cradle Various template engines >> Jazz Promises >> Callbacks + Async
  • 21. Testing Insanely fast even on slow PC 15,000 SLOC 100% test coverage 34 seconds YUITest, JSCoverage, nodelint
  • 22. Homegrown Modules Jazz - template engine {foreach doc in widget.docs} {if (doc.type eq 'video')} <span><a href="{doc.videourl}">{doc.title}</a></span> {else} <a href="{helper.createUrl(doc.key)}"> <h3>{doc.title}</h3> </a> {end} {end} No business logic Synchronous compilation, asynchronous evalua
  • 23. More Homegrown Modules Log4js-node - logging framework Severity level and rolling log file Couchtato - CouchDB document utility tool Doesn’t require CouchDB design doc knowledge
  • 24. Continuous Integration Jenkins Node.js Plugin Nestor - Jenkins Node.js CLI
  • 25. Conclusion CouchDB rocks! Node.js rocks! JavaScript web stack rocks!
  • 27. Resources CouchDB - http://couchdb.apache.org Node.js - http://nodejs.org Jazz - http://github.com/shinetech/jazz log4js-node - http://github.com/csausdev/log4js-node Couchtato - http://github.com/cliffano/couchtato Jenkins Node.js Plugin - https://wiki.jenkins-ci.org/display/JENKINS/NodeJS +Plugin Nestor - http://github.com/cliffano/nestor
  • 28. Credits http://www.flickr.com/photos/daveaustria/2654190796/ by Dave Austria http://www.flickr.com/photos/38485387@N02/3580728177/ by flickrfavorites http://www.housecontainer.nl/blog/about-me/127-dj-yoda-from-star-wars.html http://www.miccicohan.net/blog/studio-antics-and-of-coursethe-rolling-stones/

Editor's Notes