36
Node.js Microservices on Autopilot Wyatt Preul – jsgeek.com/jsconf

Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently

Node.js Microservices on AutopilotWyatt Preul – jsgeek.com/jsconf

Page 2: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

• 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

• 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

• 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://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
Page 22: Wyatt Preul – jsgeek.com/jsconf · Do microservices help? • Hypothetical Steps • Decompose the corn service into many smaller services • Each microservice is independently

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Further Reading:• All links can be found at: jsgeek.com/jsconf

• Autopilot Pattern - autopilotpattern.io

• hapi - hapijs.com

• ContainerPilot – joyent.com

• Seneca – senecajs.org