Wednesday, January 11, 2017

Microservices for better scale

    

I was reading some article and which triggered the question in my mind w.r.t business services particularly "Microservices":


  • What do I need from CAP theorem, should System be AP system  (consul, eureka, etc) or CP system (zookeeper, etcd, etc). How to decide about it?
  • Figure out how to run, manage, and monitor these systems at scale. How to plan for it?


Some of the points were answered once I built a on the small microservice demo.

Following slide would help:





Download source code from github.

Eureka (Discovery Server/Service):
Eureka developed by Netflix is a REST based service that was primarily used by them in the AWS cloud for locating services for the purpose of load balancing and failover of middle-tier servers.

Eureka also comes with a Java-based client component,the Eureka Client, which makes interactions with the service much easier. The client also has a built-in load balancer that does basic round-robin load balancing.

Zuul (Gateway/Proxy and Load Balancer):
Zuul is a JVM based router and server side load balancer by Netflix. And Spring Cloud has a nice integration with an embedded Zuul proxy.
There are many usages of Zuul I found following would be very helpful:

  • Authentication
  • Dynamic Routing
  • Service Migration
  • Load Shedding
  • Security
For proxyservice have a service and enable zuul proxy @EnableZuulProxy and define the routes.



Routing to be configured in configuration file:


Any request which catalogservice would be routed to serviceId catalogservice which in this case is catalogservice registered with Eureka.

Spring Cloud has created an embedded Zuul proxy to ease the development of a very common use case where a UI application wants to proxy calls to one or more back end services. This feature is useful for a user interface to proxy to the backend services it requires, avoiding the need to manage CORS and authentication concerns independently for all the backends.

There are few pre created filters and custom filter (see PreFilter.java) can also be created easily.

Ribbon (Load Balancer):
Ribbon is a client side load balancer which gives you a lot of control over the behaviour of HTTP and TCP clients. Feign already uses Ribbon

Feign (Web Service Client):
Feing offers a solution to dynamically generate clients from the interface. Additional benefit is that we can keep the signature of the service and client identical. Just declare an interface request mappings :




Above example would be invoking the catalogservice's (CatalogController) getItems().

The Ribbon client above would discover the physical addresses for the "catalogservice" service. If application is a Eureka client then it will resolve the service in the Eureka service registry. If Eureka is not used, than  configuring a list of servers in your external configuration would also help ribbon to find and load balance appropriately.


:-)

Heroku Custom Trust Store for SSL Handshake

  Working with Heroku for deploying apps (java, nodejs, etc..) is made very easy but while integrating one of the service ho...