Sunday 6 December 2015

Understanding of Various Components Provided by Netflix OSS Sack

In this post we will try to understand various components of the Netfix OSS Stack while building bespoke E-commerce shopping application based on microservices & REST principles. 

Various Components provided by Netflix OSS stack:

Spring Cloud integrates the Netflix components in the spring environment in a very nice way using auto configuration and convention over configuration similar to how Spring Boot works.

The table below maps the generic components in the operations model to the actual components that can be used to build a microservice based application:

Operation Component
Netflix, Spring
Service Discovery
Eureka (Netflix)
Dynamic Routing, Client-side load balancing
Ribbon (Netflix)
Circuit Breaker
Hystrix (Netflix)
Monitoring the services
Netflix Hystrix Dashboard and Turbine
Router/Filter/Server-side load balancing
Zuul (Netflix)
External Configuration Management
Archaius (Netflix), Sping cloud config server
OAuth 2.0 protected API*
Spring Security OAuth2


* Protecting service API with OAuth is not specific to microservices and can be applied to any service based architecture.

Eureka

Eureka is Service Discovery component provided by Netflix. Service discovery is one of the important and key needs in a microservices based architecture. It will be tough and error prone to do manual service discovery. Eureka provides a server and a client component. The server component can be configured and deployed to highly available with servers replicating state about the registered services to the others.

Service Discovery: Eureka Client:

When a client i.e. a microservice API registers with Eureka client it provides the basic meta-data in terms of host, port, health-check URL, home page URL etc. Eureka tries to get connected with the client by receiving heartbeat. If the server doesn’t receive heartbeat from a specific client (configurable) the instance is removed from the registry.

Service Discovery: Eureka Server:

The Eureka server does not have a backend store, but the service instances in the registry all have to send heartbeats to keep their registrations up to date (so this can be done in memory). Clients also have an in-memory cache of eureka registrations (so they don’t have to go to the registry for every single request to a service).

By default every Eureka server is also a Eureka client and requires (at least one) service URL to locate a peer. If you don’t provide it the service will run and work, but it will shower your logs with a lot of noise about not being able to register with the peer.

Netflix Ribbon - Dynamic Routing and Load Balancer

Netflix Ribbon can be used by service consumers to lookup services at runtime. Ribbon uses the information available in Eureka to locate appropriate service instances. If more than one instance is found, Ribbon will apply load balancing to spread the requests over the available instances. Ribbon does not run as a separate service but instead as an embedded component in each service consumer.

Netflix Zuul – Filter/Router/Server-side (Edge Server)

Zuul is (of course) our gatekeeper to the outside world, not allowing any unauthorized external requests pass through. Zulu also provides a well-known entry point to the microservices in the system landscape. Using dynamically allocated ports is convenient to avoid port conflicts and to minimize administration but it makes it of course harder for any given service consumer. Zuul uses Ribbon to lookup available services and routes the external request to an appropriate service instance. In this blog post we will only use Zuul to provide a well-known entry point, leaving the security aspects for coming blog posts.

Hystrix – Circuit Breaker:

Netflix Hystrix provides a framework for fault handling using a circuit breaker pattern. If some composite services depend on other core services, then failure of any of the core service can jeopardize the whole composite system if faults are not handled properly.

Netflix Hystrix provides circuit breaker capabilities to a service consumer. If a service doesn’t respond (e.g. due to a timeout or a communication error), Hystrix can redirect the call to an internal fallback method in the service consumer. If a service repeatedly fails to respond, Hystrix will open the circuit and fast fail (i.e. call the internal fallback method without trying to call the service) on every subsequent call until the service is available again. To determine wether the service is available again Hystrix allow some requests to try out the service even if the circuit is open. Hystrix executes embedded within its service consumer.

Netflix Hystrix dashboard and Netflix Turbine - Monitor Dashboard

Hystrix dashboard can be used to provide a graphical overview of circuit breakers and Turbine can, based on information in Eureka, provide the dashboard with information from all circuit breakers in a system landscape.

Archaius: External Configuration Management:

Archaius is the Netflix client side configuration library. It is the library used by all of the Netflix OSS components for configuration. Archaius is an extension of the Apache Commons Configuration project. It allows updates to configuration by either polling a source for changes or for a source to push changes to the client. Archaius uses Dynamic<Type>Property classes as handles to properties.
Archaius has its own set of configuration files and loading priorities. Spring applications should generally not use Archaius directly, but the need to configure the Netflix tools natively remains. Spring Cloud has a Spring Environment Bridge so Archaius can read properties from the Spring Environment.

Following is the diagram depicts the overall ecosystem with various Netflix component interactions.

 

The above diagram explains a microservice based architecture for an e-commerce portal. We have elaborated one main service which deals with product information. The whole service based architecture can be divided into 3 layers logically. The core services are the unique services producing unit information like item information, price information and ratings and review. The main product composite service consumes these core services and produces full set of information related to a product. All the services are registered with Eureka.

Ribbon is responsible to load balance across multiple instances of the core services. To avoid service outage due to a failing service or temporary network problems it is very common to have more than one service instance of the same type running and using a load balancer to spread the incoming calls over the instances. Since we are using dynamic allocated ports and a service discovery server it is very easy to add a new instance. For example simply start a new review service and it will allocate a new port dynamically and register it to the service discovery server.

The service product-composite is also enhanced with a Hystrix based circuit breaker so that if any of the core services fails it will fall back to some default (static) source. The Hystrix dashboard is also configured to monitor the status of the core services.

Similar to composite service we have created one more API service layer for the same to protect the service with OAuth2. So this layer also has circuit breaker and load balancer in order to handle fault tolerance and load balancing for product composite service. The corresponding OAuth client should be configured in the service consumer.

All the components are maintaining their configuration data thru Archaius configuration management component.

No comments:

Post a Comment