IBM and Node.js - Old Doge, New Tricks

Post on 03-Jul-2015

849 views 0 download

description

Presentation at Full Stack Toronto Conference, November 23, 2014

transcript

IBM and Node.js: Old Doge, New Tricks

Dejan Glozic, Full-Stack Architect, IBM Bluemix DevOps

Show Us Your Stack

About MeIBM Canada Toronto Lab

Full-Stack ArchitectIBM Bluemix DevOps

@dglozichttp://dejanglozic.com

What I Work On

Part 1Motivation for change

Enterprise productsYearly release cycle, moves at the speed of the slowest component.

Large teamsComplex coordination, large change sets, difficult to get a good stable build.

Products run on premiseManaged by customer admins, limited control over hardware choices.

Enterprise stacksJava Enterprise Something Something, WS*, Apache, SQL

Overindulgence in JavaScript‘Extreme Ajax’ - Dojo/Dijit pushed well beyond sane limits

desktop != server != client

A Need for a Reset

• Complexity and crud built up over time

• Apollo 13: sooner or later you hit 12 amps

• Solution: turn everything off and and start from scratch

Motivators

• New attractive stacks built for humans

• The need to bring the fun back

• The need to built ‘fit for cloud’ software

• The need to ‘do it right this time’

Evolution of Thought

• 12-factors

• Netflix

• Reactive Manifesto

• Micro-services

Part 2From Dojo/Dijit to jQuery/Bootstrap/MV*

JS

Client Side ResetSwapping Dojo/Dijit for jQuery/Bootstrap. No point arguing with gravity.

BootstrapWe love the emphasis on HTML5/CSS and away from JavaScript.

After jQuery?

• Sometimes jQuery is too big

• Alternatives for newer browsers: zepto, jqLite

• Or nothing? http://youmightnotneedjquery.com

Part 3From Java to Node.js

JS

Now The Server SideNothing much wrong with servlets and JSPs, but we wanted more.

Sitting on the Node.js Fence

• We watched cautious companies like Walmart and PayPal jump in.

• After plugging the ‘Walmart leak’, it looked like Node.js was ready.

• We were ready to jump ourselves by January 2014.

‘Control Your Urges’ RuleWe will use a new technology to solve a real problem, not as an excuse to play

with the new hotness.

Our Case for Node.js

• We wanted to build a UI for a delivery pipeline

• The pipeline had a number of moving parts

• We didn’t want to poll the server to the ground

• Solution: Node.js + WebSockets (via Socket.io)

Unlocking New Opportunities

• With Node.js, we could run JavaScript templating engine for the V of MVC

• We chose Dust.js because LinkedIn, PayPal, Yahoo, Netflix

• Bonus: we can now run Dust partials on the client as well (demo spoiler)

Part 4From a monolith to micro-services

Tackling the Hard ProblemsSo far we upgraded our stack but didn’t handle any of our systemic problems.

Architectural ImpasseIf monoliths were pain for on-premise products, they were killing us in the cloud.

Cloud Imposter RuleStanding up a traditional product in a VM does not mean you ‘solved the cloud’.

Putting Manifestos To WorkThis is where the principles of micro-services, reactive manifesto and 12 factors

come into play.

How Micro-Services Help

• Many micro-services instead of a monolith

• Deploy micro-services independently

• Communicate using message queues

• Cluster locally

This Is Not A Micro-Service TalkThere are others at this conference, and tons of material online.

Part 5From REST to REST+Messaging

What Monolith Giveth, Micro-Service Taketh Away

In-process, we just add event listeners to objects. Between processes, we need a distributed event notification.

Event Collaboration• Instead of polling using REST, react to

events

• Instead of peer to peer, publish without knowing your subscribers

• Message broker smooths out throughput mismatches

• Message broker can hold onto messages

REST/MQ Mirroring• Yin and Yang of micro-service communication

• API services own state

• MQ broadcasts stage changes on matching topics

• Example:

• DELETE /v1/projects/ffya14

• Subscribe to: /v1/projects/+ (MQTT)

• Message body:{ “event”: “deleted” }

Messaging and Clustering

Part 6From SQL to, well, NoSQL (duh)

Our Data is AggregateIt is a pain to join data from a number of tables using foreign keys

Our Integration Points Are API Services

Persistance is implementation detail.

JavaScript All The Way DownWith Node.js, JSON-based NoSQL DB like CouchDB is a natural choice.

Pulling It All Together

Part 7No free lunch - micro-services introduce new problems.

Latency Needs MitigationKeeping micro-services in co-located VMs, strategic caching (combined with MQ

invalidation).

Guards Against BrownoutsCircuit breakers, using ‘last good values’, exponential back-off. See Netflix libraries

for ideas.

AuthenticationWe need to stay authenticated as we transition between micro-services.

UI CompositionIncluding page fragments is easy in monoliths using partials. In micro-service

systems, we need distributed solutions.

Part 8Lessons from the trenches

Legal Hates Us

• Hundreds of modules to scan licenses and content

• Torrent is now turning into a trickle (phew!)

• Occasional spike (e.g. express 4, Socket.io 1.0)

Ops Hate Us

• Operational complexity

• Many firewall rules for service to service links

• Many proxy_pass rules

• Unknown new platforms and tools (what is ‘PM2’?)

IaaS Too Low for Micro-Services

• Sweet spot - highly customized back-end systems

• Node.js services are a shoe-in for a PaaS

• DBaaS takes away storage management headaches

• We are moving to a PaaS now (Cloud Foundry/Bluemix)

–Dejan’s Razor (in honour of William of Ockham)

“Use the simplest solution you can get away withTM.”

Dejan’s Razor

• If server-side MVC does the job, use it

• If jQuery + Bootstrap do the job, use them

• If adding Backbone.js helps, do it*

• If you really need Angular.js, use it**

*Use Client-Side MVC

• If highly dynamic behaviour is needed and…

• You promise to use pushState (no # or #!) and…

• You promise to send initial content from the server…

• You promise to watch the client JS size

**Use Angular.js

• If all the rules for client-side MVC apply and…

• You promise not to leave us to maintain 1.3 when 2.0 comes out

Micro-Service BenefitWe can apply Dejan’s Razor on each service independently. Each service can be

only as smart as needed for the task at hand.

DEMO

The Devil Is In The PuddingNginxNginx

HomeHome IsomorphicIsomorphic Server PushServer Push Angular Seed

Angular Seed HeaderHeader

RedisRedis RabbitMQRabbitMQ

//about

/ isomorphic /server-push /angular-seed

/page1/page2

OAuth2 provider

How To Follow

• Source code on GitHub: https://github.com/dglozic/fsto-demo

• Hosted on Bluemix: http://fsto-demo.mybluemix.net

Q/A?

Thank you!Follow me on Twitter: @dglozicRead my blog: dejanglozic.com