IBM and Node.js - Old Doge, New Tricks

59
IBM and Node.js: Old Doge, New Tricks Dejan Glozic, Full-Stack Architect, IBM Bluemix DevOps

description

Presentation at Full Stack Toronto Conference, November 23, 2014

Transcript of IBM and Node.js - Old Doge, New Tricks

Page 1: IBM and Node.js - Old Doge, New Tricks

IBM and Node.js: Old Doge, New Tricks

Dejan Glozic, Full-Stack Architect, IBM Bluemix DevOps

Page 2: IBM and Node.js - Old Doge, New Tricks

Show Us Your Stack

Page 3: IBM and Node.js - Old Doge, New Tricks

About MeIBM Canada Toronto Lab

Full-Stack ArchitectIBM Bluemix DevOps

@dglozichttp://dejanglozic.com

Page 4: IBM and Node.js - Old Doge, New Tricks

What I Work On

Page 5: IBM and Node.js - Old Doge, New Tricks

Part 1Motivation for change

Page 6: IBM and Node.js - Old Doge, New Tricks

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

Page 7: IBM and Node.js - Old Doge, New Tricks

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

Page 8: IBM and Node.js - Old Doge, New Tricks

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

Page 9: IBM and Node.js - Old Doge, New Tricks

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

Page 10: IBM and Node.js - Old Doge, New Tricks

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

desktop != server != client

Page 11: IBM and Node.js - Old Doge, New Tricks

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

Page 12: IBM and Node.js - Old Doge, New Tricks

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’

Page 13: IBM and Node.js - Old Doge, New Tricks

Evolution of Thought

• 12-factors

• Netflix

• Reactive Manifesto

• Micro-services

Page 14: IBM and Node.js - Old Doge, New Tricks

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

JS

Page 15: IBM and Node.js - Old Doge, New Tricks

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

Page 16: IBM and Node.js - Old Doge, New Tricks

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

Page 17: IBM and Node.js - Old Doge, New Tricks

After jQuery?

• Sometimes jQuery is too big

• Alternatives for newer browsers: zepto, jqLite

• Or nothing? http://youmightnotneedjquery.com

Page 18: IBM and Node.js - Old Doge, New Tricks

Part 3From Java to Node.js

JS

Page 19: IBM and Node.js - Old Doge, New Tricks

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

Page 20: IBM and Node.js - Old Doge, New Tricks

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.

Page 21: IBM and Node.js - Old Doge, New Tricks

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

with the new hotness.

Page 22: IBM and Node.js - Old Doge, New Tricks

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)

Page 23: IBM and Node.js - Old Doge, New Tricks

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)

Page 24: IBM and Node.js - Old Doge, New Tricks

Part 4From a monolith to micro-services

Page 25: IBM and Node.js - Old Doge, New Tricks

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

Page 26: IBM and Node.js - Old Doge, New Tricks

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

Page 27: IBM and Node.js - Old Doge, New Tricks

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

Page 28: IBM and Node.js - Old Doge, New Tricks

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

come into play.

Page 29: IBM and Node.js - Old Doge, New Tricks

How Micro-Services Help

• Many micro-services instead of a monolith

• Deploy micro-services independently

• Communicate using message queues

• Cluster locally

Page 30: IBM and Node.js - Old Doge, New Tricks

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

Page 31: IBM and Node.js - Old Doge, New Tricks

Part 5From REST to REST+Messaging

Page 32: IBM and Node.js - Old Doge, New Tricks

What Monolith Giveth, Micro-Service Taketh Away

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

Page 33: IBM and Node.js - Old Doge, New Tricks

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

Page 34: IBM and Node.js - Old Doge, New Tricks

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” }

Page 35: IBM and Node.js - Old Doge, New Tricks

Messaging and Clustering

Page 36: IBM and Node.js - Old Doge, New Tricks

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

Page 37: IBM and Node.js - Old Doge, New Tricks

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

Page 38: IBM and Node.js - Old Doge, New Tricks

Our Integration Points Are API Services

Persistance is implementation detail.

Page 39: IBM and Node.js - Old Doge, New Tricks

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

Page 40: IBM and Node.js - Old Doge, New Tricks

Pulling It All Together

Page 41: IBM and Node.js - Old Doge, New Tricks

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

Page 42: IBM and Node.js - Old Doge, New Tricks

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

invalidation).

Page 43: IBM and Node.js - Old Doge, New Tricks

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

for ideas.

Page 44: IBM and Node.js - Old Doge, New Tricks

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

Page 45: IBM and Node.js - Old Doge, New Tricks

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

systems, we need distributed solutions.

Page 46: IBM and Node.js - Old Doge, New Tricks

Part 8Lessons from the trenches

Page 47: IBM and Node.js - Old Doge, New Tricks

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)

Page 48: IBM and Node.js - Old Doge, New Tricks

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’?)

Page 49: IBM and Node.js - Old Doge, New Tricks

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)

Page 50: IBM and Node.js - Old Doge, New Tricks

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

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

Page 51: IBM and Node.js - Old Doge, New Tricks

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**

Page 52: IBM and Node.js - Old Doge, New Tricks

*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

Page 53: IBM and Node.js - Old Doge, New Tricks

**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

Page 54: IBM and Node.js - Old Doge, New Tricks

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.

Page 55: IBM and Node.js - Old Doge, New Tricks

DEMO

Page 56: IBM and Node.js - Old Doge, New Tricks

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

Page 57: IBM and Node.js - Old Doge, New Tricks

How To Follow

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

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

Page 58: IBM and Node.js - Old Doge, New Tricks

Q/A?

Page 59: IBM and Node.js - Old Doge, New Tricks

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