Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are...
Transcript of Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are...
![Page 1: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/1.jpg)
![Page 2: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/2.jpg)
Node.js Micro-Services: The Water is Fine, Jump In!
Dr. Dejan Glozic, IBM
![Page 3: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/3.jpg)
About me
• IBM Canada, Toronto Lab
• Full-stack architect
• IBM DevOps Services
• @dglozic
• http://dejanglozic.com
![Page 4: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/4.jpg)
GIVING YOU SOME CONTEXT Part 1
![Page 5: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/5.jpg)
IBM and me
Planet IBM Software Group IBM Rational IBM DevOps Services
Me (hi!)
![Page 6: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/6.jpg)
IBM DevOps Services for Bluemix • Integrated task tracking,
agile planning, source control
• Optimized for Bluemix
• Use your favorite tools or work from the Web IDE
• Hosted SCM Jazz or Git or link to GitHub
• Continuous Integration and Deployment
• Mobile quality and application performance monitoring (coming)
http://jazzhub.com
![Page 7: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/7.jpg)
Humble beginnings
• Skunkworks project to host Rational Team Concert for academic users (JazzHub)
• Generous use of duct tape
• JEE container, SQL, Dojo/Digit, extreme Ajax
![Page 8: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/8.jpg)
Challenge
• From hosting RTC to ‘Rational as a Service’
• Convert one-engine Cesna into a jet airliner
• Apply solid architectural principles
• Do it mid-air
![Page 9: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/9.jpg)
Wish list
• Grow the system without sinking it
• Allow parallel development
• Many deployments per day
• Zero-downtime deployment
• A/B testing
• Web scale
• World peace
![Page 10: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/10.jpg)
MEANWHILE, IN A PARALLEL EFFORT…
Part 2
![Page 11: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/11.jpg)
Rethinking apps
• Lessons from monolithic applications on premise
• Need to avoid: – Stack lock-in
– Lock-step development
• Client-side reset – embrace HTML5 – jQuery, Bootstrap instead of
Dojo, Dijit
• The 12-factor app
![Page 12: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/12.jpg)
What about the server?
• From extreme Ajax to a more balanced approach
• Simple, straightforward servlets and JSPs
• Lightweight containers (Jetty, WebSpere Liberty Profile)
• Still sitting on the Node.js fence
![Page 13: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/13.jpg)
Dec 2013 Node.js flood
• The Walmart memory leak
• Walmart Thanksgiving
• NodeSummit 2013
• Groupon: Dismantling the monoliths
• PayPal: Project Kraken.js
![Page 14: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/14.jpg)
TAKING THE PLUNGE Part 3
![Page 15: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/15.jpg)
Convincing ourselves
• Felix Geisendörfer - Node.js Convincing the Boss Guide
• Never mind the boss, what do we think?
• It had to be something hard to do in JEE
• Perfect use case: DevOps Pipeline Web app
![Page 16: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/16.jpg)
Server push
• A lot happening on the server
• Polling would not scale
• WebSockets to the rescue
• Server push is the ‘killer app’ of Node.js
• We got our ‘foot in the door’, now what?
![Page 17: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/17.jpg)
Coping with success
• One is easy, multiple requires architecture
• Luckily, Node.js didn’t leave us a lot of options
• A classic case of ‘The Medium is the Message’
• The medium influences and becomes a part of the message itself
![Page 18: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/18.jpg)
Example
• This is Billy Corgan. He is my guitar hero.
• He has a signature Fender guitar, but he started with one that was not very good.
• It had no sustain to speak of.
![Page 19: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/19.jpg)
What he wanted
• Billy always wanted to sound like this guy – Frank “Tony” Iommi from Black Sabbath.
![Page 20: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/20.jpg)
What he got
• Unfortunately, due to the lack of sustain, Billy had to play a lot of short notes to fill in.
• He ended up sounding like this guy – Robert James Smith from The Cure.
• The medium (no sustain guitar) changed Billy’s message.
![Page 21: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/21.jpg)
Good match
• So what is Node.js good for?
• Tasks with a lot of waiting for I/O
• Small services that do one thing well
• DIRT apps with server push
• JavaScript all the way down: – Storing data in JSON-based NoSQL
DBs
– Rendering pages using JavaScript templating engines
![Page 22: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/22.jpg)
Micro-services
• Building blocks of modern distributed systems in the cloud
• Do one thing well
• Is this SOA? Maybe SOA done right.
• Node.js fits like a glove.
![Page 23: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/23.jpg)
Medium revisited
• ‘The medium is the message’ applies both ways.
• If you want to use Node.js: – It will force you into micro-service
architecture – There are no big monolithic Node apps.
• If you want micro-service architecture: – You can use other technologies, but… – They have more overhead – Node recommends itself as a great fit – For fairness: Netty-based Scala apps (see
Reactive Manifesto) – Fairness #2: Go
![Page 24: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/24.jpg)
THE MASTER PLAN Part 4
![Page 25: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/25.jpg)
North star
Load balancing, routing, proxy
Jenkins UCD RTC Docker Git/Gerrit
Composition
Activities
MQTT Broker
Web UI services
API services
Backend
services Integration services
Storage services
(NoSQL)
Native mobile clients
Single Sign On
(affects all services)
Desktop, mobile Web
Metering
API docs
Loggin
g
![Page 26: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/26.jpg)
REST/MQTT mirroring
• Micro-services make messaging a ‘must have’ • Prevents micro-service ‘chatter’ and polling • Works harmoniously with WebSockets • Protocol of choice – MQTT (lightweight
pub/sub) • We devised a technique we call ‘REST/MQTT
mirroring’ • REST CRUD is mirrored by messages for C, U
and D • Message broker of choice – RabbitMQ for now
(polyglot broker) • Not a hard dependency – we may swap an
IBM-provided MQ in the future
![Page 27: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/27.jpg)
Pipeline revisited
• Revisiting server push
• MQTT event flow between micro-services
• ‘Last mile’ in the Node.js app
• MQTT to WebSockets
![Page 28: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/28.jpg)
Web services
• Serve one or more Web pages • Good pattern – federation of SPAs • Proxy pass of routes to services • Our template library choice – Dust.js
(LinkedIn fork) • Server rendering for fast initial page
and headless clients • Client side rendering for user
interactions • Lazy loading of JS via Require.js • Responsive design
![Page 29: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/29.jpg)
API docs
• APIs not an afterthought in micro-services
• Ball of mud without strong contracts
• Internal APIs first • External APIs:
– Different Auth – Subset of endpoints – Rate limiting – MQ to WebSockets/event
streaming
• API docs served by micro-services
• Aggregation and rendering
![Page 30: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/30.jpg)
HA and scaling
• With micro-services, clustering decisions are local
• Cluster hotspots • 2 nodes enough for HA
unless hotspot • Node.js clustering for
vertical scaling • Load balancing for
horizontal scaling • Worker queues for MQ
events
![Page 31: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/31.jpg)
Social micro-services
• Events are good for state synchronization
• Social events need more information
• Dedicated activity stream service
• Uses Activity Stream draft 2.0 spec
• User and project streams
{ "verb": "post", "published": "2011-02-10T15:04:55Z", "language": "en", "actor": { "objectType": "person", "id": "urn:example:person:jane", "displayName": "Jane Doe", "url": "http://example.org/jane", "image": { "url": "http://example.org/jane/image.jpg", "mediaType": "image/jpeg", "width": 250, "height": 250 } }, "object" : { "objectType": "picture", "id": "urn:example:picture:abc123/xyz" "url": "http://example.org/pictures/2011/02/pic1", "displayName": "Jane jumping into water" }, "target" : { "objectType": "album", "id": "urn:example:albums:abc123", "displayName": "Jane's Vacation", "url": "http://example.org/pictures/albums/janes_vacation/" } }
![Page 32: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/32.jpg)
FROM THE TRENCHES Part 5
![Page 33: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/33.jpg)
We are not done
• Not a rear-view mirror story
• We are far from done
• We didn’t yet forget the bad
• You can learn from us and steel yourself
![Page 34: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/34.jpg)
Legal will hate you
• Entire dependency chain needs to be vetted by legal
• Sometimes it will give them a heart attack
• Eventually the torrent will subside
• Prominent modules: – Express.js – Web service middleware
– Dust.js – server/client templating (LinkedIn fork)
– Socket.io – server push using Web Sockets
– Nano.js – for Cloudant DB
– Mqtt.js – for messaging
– Kraken.js – Express-based app suite for security, i18n, code structure, configuration, testing
![Page 35: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/35.jpg)
Ops will hate you
• You are upsetting the routine • NoSQL, Node.js, MQ • You want how many VMs again? • Easily hundreds:
– Dozens of micro-services x HA x DEV/QA/PROD stages
– You can cheat with vertical scaling
• Each VM needs to: – Know other VMs it will talk to (firewalls) – List the ports it will use
• Partial mitigation: automate, use DevOps • Makes you seriously get PaaS
![Page 36: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/36.jpg)
Learning curve
• You cannot do it alone
• You need to sell the whole story to the team
• Surprisingly little resistance
• Node.js is cool, it is an easy sell
• Our North Star is a compelling story
![Page 37: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/37.jpg)
Chipping away
• Mothership in active use is a hard thing to evolve
• Baseline what exists, define fault lines
• Plan micro-services along the fault lines
• Rule #1: Write all new code as micro-services
• Rule #2: For substantial refactoring, extract a micro-service
• Continue until Mothership is no more
![Page 38: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/38.jpg)
Step 1: baseline
Load balancing, routing, proxy
Composition
Activities
Web UI services
API services
Mothership
![Page 39: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/39.jpg)
Step 2: Web services
Load balancing, routing, proxy
Composition
Activities
Web UI services
API services
Mothership
![Page 40: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/40.jpg)
Step 3: Web UI done
Load balancing, routing, proxy
Composition
Activities
Web UI services
API services
Mothership (headless)
![Page 41: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/41.jpg)
Step 4: API services
Load balancing, routing, proxy
Composition
Activities
Web UI services
API services
Mothership (headless)
![Page 42: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/42.jpg)
Step 5: all done
Load balancing, routing, proxy
Composition
Activities
Web UI services
API services
![Page 43: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/43.jpg)
Conclusion
• Our journey continues
• We have no regrets
• Despite difficulties, we are having fun
• I am documenting it along the way
• Follow me on twitter, drop me a line, read my blog and you will be in the know
![Page 44: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/44.jpg)
Q and A
![Page 45: Node.js Micro-Services: The Water - TMCnet · PDF fileSocial micro-services •Events are good for state synchronization •Social events need more information •Dedicated activity](https://reader034.fdocuments.us/reader034/viewer/2022051720/5a7814077f8b9a1b688e71b4/html5/thumbnails/45.jpg)
Thank You!