Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose...
Transcript of Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose...
![Page 2: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/2.jpg)
One day Chicken-micro was making a request to the corn server when—boom! The request timed out.
![Page 3: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/3.jpg)
Goodness gracious, the servers must be down. I must go and tell
the System Operator.
![Page 4: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/4.jpg)
I’m going to tell the Operator that the servers are down. I made a
request and never got a response!
Chicken-micro went along until she came to boxy-loxy.
Where are you going in such a hurry?
… Oh dear! I’ll go with you.
![Page 5: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/5.jpg)
We’re going to tell the Operator that the servers are down. Chicken-micro made a request and never
got a response!Where are you going in such a hurry?
… I’ll go with you.
Chicken-micro and boxy-loxy went along until they came to robot-rob
![Page 6: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/6.jpg)
Oh chicken-micro, the servers are not down. But the server the load-
balancer sent you to was under heavy load. Please try your request
again. I made a request to the corn
server and the request timed-out. The servers are down!
Chicken-micro, boxy-loxy, and robot-rob made it to the System Operator.
![Page 7: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/7.jpg)
Chicken-micro Postmortem• Overloaded server should have returned 503
• Load-balancer should have taken slow server out of rotation
• How would chicken-micro know that there are other healthy servers and that the next request will succeed?
![Page 8: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/8.jpg)
Do microservices help?• Hypothetical Steps
• Decompose the corn service into many smaller services
• Each microservice is independently deployable
• New microservices are each located behind load balancers
• When microservices are architected the same as the services they replace, they will face the same challenges as the previous services.
![Page 9: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/9.jpg)
What is a Microservice?• Small, decomposed, isolated and independently
deployable services
• Stateless and less fragile when changes are introduced
![Page 10: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/10.jpg)
Benefits of Microservices• Embrace failure, works in spite of external failures
• Iterate quickly - disposable services, independently deployable services
![Page 11: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/11.jpg)
Microservice AntiPatterns• Load balancer between microservices
• Startup order matters
• Load balancers everywhere
• + many others, Microservices AntiPatterns and Pitfalls by Mark Richards
![Page 12: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/12.jpg)
Load balancer between microservices
![Page 13: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/13.jpg)
Load balancer between microservices
![Page 14: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/14.jpg)
Startup order matters
![Page 15: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/15.jpg)
Load balancers everywhere
![Page 16: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/16.jpg)
Goodness gracious, are there any patterns that can help me?
![Page 17: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/17.jpg)
• Apps that can be deployed and scaled with a single click.
• Apps and workflows that work the same on our laptops as in the cloud (public and private cloud).
• Apps and workflows that aren't married to any specific infrastructure or scheduler.
• Further reading at autopilotpattern.io
Autopilot Pattern
![Page 18: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/18.jpg)
• github.com/autopilotpattern - solutions that follow the Autopilot Pattern
• MongoDB, MySQL, InfluxDB, Consul, NATS, Wordpress, Jenkins, …
• Container support through ContainerPilot
Autopilot Applications
![Page 19: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/19.jpg)
• Applications composed of portable docker containers
• Service discovery through consul or another catalog
• Container local health and services respond to service dependency changes
Autopilot in Practice
![Page 20: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/20.jpg)
• https://github.com/autopilotpattern/nodejs-example
• Modules used:
• hapi
• Seneca
• Piloted
• Wreck
Node.js Example
![Page 21: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/21.jpg)
![Page 22: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/22.jpg)
What does it do?
![Page 23: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/23.jpg)
Isolation
![Page 24: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/24.jpg)
Change
![Page 25: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/25.jpg)
ContainerPilot• Automates a container’s service discovery, life cycle
management, and telemetry reporting
• Capabilities
• Container-local health checks
• PID 1 init process
• Service discovery registration and watchers
• Telemetry reporting to Prometheus
• Free & Open Source! github.com/joyent/containerpilot
![Page 26: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/26.jpg)
ContainerPilot Lifecycle
![Page 27: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/27.jpg)
ContainerPilot Watches
![Page 28: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/28.jpg)
ContainerPilot Services
![Page 29: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/29.jpg)
Circuit Breakers• Prevent requests that will fail from taking place and
overburdening a service
• Once a response timeout threshold has been reached block future requests to the service until the service is able to catch-up/recover
• Is this possible to implement with a load balancer?
![Page 30: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/30.jpg)
hapi Circuit Breakers
![Page 31: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/31.jpg)
Balancing in the Client
![Page 32: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/32.jpg)
What about scaling?
![Page 33: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/33.jpg)
Load Balancers at the Edge• Don’t expose microservices directly outside of your
organization
• Setup a load balancer that can use Consul, in our example this is traefik, could be HA Proxy, nginx, or anything else
• API gateways have a place when exposing the business value we created with our microservices
![Page 34: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/34.jpg)
Telemetry Support
![Page 35: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/35.jpg)
hapi Metrics with Toppsy
![Page 36: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently](https://reader034.fdocuments.net/reader034/viewer/2022042303/5ece2d3aee11c142a623dce2/html5/thumbnails/36.jpg)
Further Reading:• All links can be found at: jsgeek.com/jsconf
• Autopilot Pattern - autopilotpattern.io
• hapi - hapijs.com
• ContainerPilot – joyent.com
• Seneca – senecajs.org