4. So, how do you
build it?
‣have a common code-base,
‣be service-oriented,
‣use small, independent pieces.
Friday 9 November 2012
5. Web
Mobile Cloud
Services
Web Apps Services
API
Mobile & REST &
Database
Tablet Web JSON
Mobile & Horizontal Third Party
Tablet Apps Scale Services
Desktop Cloud
Monitoring
Web Hosted
Friday 9 November 2012
6. Client-side
Router #! URLs
• Common code-base
• even for hybrid apps!
Models Data, biz logic
• backbone.js
• shims for weak browsers
Views DOM Layout
• browser-targeting: user-
agent & capabilities
• responsive layout
(mostly)
Helpers Shared code
Friday 9 November 2012
7. Running...
1. Load
static 2. Init shared
index.html code, then 3. Init
and assets targeted router, and 4. Wait for
code display as events
per #! URL
Friday 9 November 2012
8. Native Apps
Same code as mobile web versions, ...
... wrapped using PhoneGap to run natively
... plus some native plugins
Friday 9 November 2012
9. Server-side
map /api/ URLs • nginx & Node.js
Router
to functions • Small code volume
API function( req, • Third party modules:
functions res ) { ... } • connect
Shared code
• express
Helpers (some with client) • seneca
Open source
• Deploy with:
Modules heavy-lifting • sudo killall node
Friday 9 November 2012
10. Running...
1. Connect
to databases 2. Route
and listen HTTP 3. Talk to
for HTTP requests to database, 4. Send
API functions wait for JSON back
callback to client
Friday 9 November 2012
11. Callback Style
this is the common language of
Node.js - always use it!
doSomething( input, function( error, output ) {
...
})
Friday 9 November 2012
12. Error Pattern
use functional style avoid
if statements everywhere
function wraperror( success ) {
return function( err, result ) {
if( err ) return handleError( err );
else return success( result );
}
}
database.doQuery( wraperror( function( result ) {
doRealWork( result );
}))
Friday 9 November 2012
28. Lesson:
code volume
4
3
2
1
0
Client JavaScript Server JavaScript
Friday 9 November 2012
29. Lesson:
multi-platform client-side JavaScript is really hard
• a framework is a must • code against ECMA, use shims
to support older browsers
• backbone.js • Code/Test/Debug inside Safari
• business logic must be in • phonegap.github.com/weinre for
common code hard to reach places
• browser-specific code • use error capture in production
• virtual .js files • Finally, use a simple static site as
a fallback (also for Googlebot)
• use jshint to keep IE happy • appgen module helps!
Friday 9 November 2012
30. Lesson:
multi-platform HTML/CSS is really hard
• "structured" CSS is a must • Clean, semantic HTML is not
optional
• sass or less • graceful degradation may
• Be happy with require radically different CSS
• 100% "Responsive" design is tough
• media queries • Responsive within browser
• CSS3 transforms subsets has higher reward/effort
• browser-specific code •appgen module helps!
• virtual .css files
Friday 9 November 2012
31. Lesson:
the app stores are not web sites
• that bug in version one... • you can't deploy hot fixes
• will take two weeks to • make everything
fix via an update configurable!
• some users will never • All prices, text, host
update names, urls, ...
• appears after an OS • On launch, app "checks-in"
update for new configuration
• this will save your life
Friday 9 November 2012
32. Lesson:
Node.js is awesome!
• High performance • callback spaghetti is not a
problem in practice
• High throughput
• Low CPU usage • use functional style
• Constant memory usage • client-side code is far
more difficult
• leaks will kill, but then
• < 100ms startup time • Don't do CPU intensive
stuff
• means you may not
notice! • Node.js is not for that
Friday 9 November 2012
33. Lesson:
Small processes can save your life
• Prevents total failure even if
other systems fail
• Memory leaks are not
a disaster - just restart!
• Easy to scale - just move to • Use queues in
new machines
preference to direct
• Easy to code - you get small, communication
single purpose code bases
• Easy to manage - even • Easy to divide up work
traditional process
between developers
management will get you a
long way
Friday 9 November 2012
34. Thank You!
Richard Rodger
@rjrodger
Friday 9 November 2012