Friday, 16 August 2019

Micro Services

What Are Microservices?
  • Microservices small targeted services 
  •  Each service has its own repository 
  •  Microservices are isolated from other services 
  •  Should not be bundled with other services when deployed
  •   Microservices are loosely coupled 
  •  When interacting with other services, should be done in a technology-agnostic manner 
  •  ie - Restful web services - HTTP / JSON

With a Microservice Architecture:
  • Applications are composed using individual microservices 
  • Each service will typically have its own database 
  • Each microservice is independently deployable
  • Scaling of individual services is now possible 
  • CI/CD becomes easier since services are smaller and less complex to deploy 
Benefits of Microservices
  • Agility : one word for microservices
  • Easy to understand & develop - Services are smaller and more targeted  

  • Software Quality - Since services are more targeted and have a limited scope 
  • Scalability - Independent services can be scaled up and down to the application’s demands.
  • Reliability - Software bugs are isolated 
  • Technology flexibility - Services can be developed using any language or technology stack. 

Cons of Microservices
  • Integration testing can be difficult 
  • Deployments are more complex. Rather than one application to deploy, you now have many. Operational cost with each service - Each service is a small application 
  • Needs own repo, own deployment process, own database, etc 
  • Additional hardware resources - Additional services need additional hardware to run on

How ‘Big’ Should a Microservice Be?

  • A microservice can be as small as a single API endpoint  ie - ‘Get Orders’ 
  • A microservice can be several or even dozens of API endpoints 
  • Guideline - Amazon’s Two Pizza Team - A microservice should be able to be supported be a team you can fed with two pizzas. (~12 people) 
  • Scalability - This can also be a consideration in the size of a microservice 
  • The higher the scalability, the more specialized the service should be 
Comparison of Monolithic and MicroSercvices :




Important recipe of a microservices


API

Tracing

Monitoring

Logging

Discovery

Invocation

MyService

VERTX

Authentication

Pipeline

Elasticity

Residence

What is Gateway?


  • Endpoint that is exposed to other services 
  • Can be internet for public APIs 
  • More likely to be internal 
  • Abstracts implementation of services 
  • Client calls URL, is unaware of routing taking place to run the instance 
  • Acts as roughly a proxy for network traffic 
  • Can also act as a load balancer 

About Service Instances
  • Expect to be running N number of services 
  • The exact number depends on reliability and load requirements 
  • Minimum might be 3, for high availability 
  • Some tools allow you to dynamically scale based on load or anticipated load 
  • Think Netflix at night 
  • In evenings, Netflix traffic is 1/3 of US internet traffic 
  • Netflix will scale up and down with the load

About Database Tier
  • Typically one database per microservice 
  • Guideline - not a hard ‘rule’ 
  • Highly scalable services will often have one transactional database 
  • And one or more read database (replicas) 
  • Organizations will often have more than one database technology 
  • Not uncommon to see the mix of SQL and NoSQL database technologies

Messaging
  • A common pattern is to expose an API endpoint via a RESTFul API 
  • Dependent microservices are often message based 
  • Messages follow an event or command pattern 
  • Messaging allows for decoupling and scalability
  •  Messaging can be used to define a work flow 
  • New Order, Validate Order, Charge Credit Card, Allocate Inventory, Ship Order


Monitoring


Monitoring

https://gist.github.com/tyrell/5dOfe1003551dbe05112a64bd51a9c08

Heapster, Hawkular. Cassandra

https://docs.openshift.com/container-platform/3.5/scaling_performance/scaling_cluster_metrics.htmi

If you wish to try it minishift -metrics start



bit.ly/microservicesdeepdive

bit.ly/msa-instructions

bit.ly/javamicroservicesbook

bit.ly/reactivemicroservicesbook

bit.ly/mono2microdb

JVM + Docker FAIL bit.ly/jbcnconfJavaFail

https://github.com/redhat-helloworld-msa/goodbye

https://github.com/burrsutter/kube4docker

https://github.com/burrsutter/javadockerfail


More Advanced Topics

Domain Driven Design: Know your boundaries

HTTP/2 vs HTTP/1

GRPC or AMQP vs HTTP

Feature Toggles

A/B Testing

Sidecars & Service Mesh

CORS & Event Sourcing

Advanced Service Choreography


Logging

https://docs.openshift.com/container-platform/3.5/install_config/aggregate_logging.html

EFK

Elasticsearch - An object store where all logs are stored

Fluentd - Gathers logs from Nodes and feeds them to Elasticsearch

Kibana - A web UI for Elasticsearch




Tracing

Zipkin, Opentracing.io, Jaeger

http://opentracing.io/documentation/pages/supported-tracers

Opentracing.io is where it is all coming together. It gives you a common API to instrument

your code.

Zipkin was open sourced by Twitter (http://zipkin.io) - leverage Brave and Feign

Jaeger by the Uber team

Supported Tracers: http://opentracing.io/documentation/pages/supported-tracers


For more details : https://12factor.net/