Saturday, May 19, 2018
Cloud ready application
Architecture must implement service discovery and externalized configuration as
key design patterns in addition to other key design tenets such as isolation,
security, idempotency etc.
A cloud ready
application architecture
must follow certain
design principles – few
of them being
loose coupling between application components and properties. Whether
the application is built
using RESTful micro
services architecture or asynchronous
pub/sub or another design
pattern, ultimately the
application components must have the capability to
discover each other and must be configured and orchestrated using common set of
properties. This enforces the need of a service discovery mechanism and
methodologies to decouple
the application properties
from actual application components.
2. Abstract /
Business Case
A cloud ready
application should not
have any infrastructure dependency.
The application developers should
not assume that the components will run on particular hosts or even ports. The
developers can orchestrate the order in which services will be called but they
cannot assume the physical location of those services. This leads to the need of
“service discovery” design pattern.
Service discovery is needed so that
application components can discover each other. Also all the business
components should get registered as services in a centralized manner for
monitoring and control purpose.
Externalized configuration may store the information about how the services need to be
orchestrated along with other common application properties. This information
must be externalized to be able to dynamically update at runtime and not impact
any deployed application components.
Similarly the
component/service
orchestration details and
other configurations must
be abstracted and isolated
from deployed components.
Any changes to
application configuration
should be propagated to only the impacted components
and should be transparent to rest of the application components.
While there are several out of box
solutions for service discovery namely Consul, Zookeeper, and Eureka
etc. this paper
focuses on achieving
these design principles
using Zookeeper and Spring Netflix Eureka.
For externalized configuration, this paper will focus
on Zookeeper and Spring Cloud Config.
3. Problem Statement
Some of the
key tenets of
cloud ready application
are service discovery
and externalized
configuration. This paper
does not aim
to cover all
the design principles
of a cloud
ready architecture but focuses only on service discovery and
externalized configuration.
The paper describes case studies of how the author
applied these design principles using some out of the box solutions namely
Zookeeper and Eureka and Spring cloud config.
The case studies
referenced below refer
to a cloud
ready application consisting
of individual
components/services. These components
are wired using
message broker and
RESTful endpoints. Service discovery
deals with the scenario of
inter application communication. Externalized configuration deals
with the scenario
of dynamic update
to application configuration in
a single place without restarting the application components.
4. Proposed Solution(s)
4.1.First
Solution – Eureka/Spring cloud config
4.1.1. Introduction of Solution
The first solution described here uses:
Spring Netflix Eureka for
service discovery
Ribbon for load balancing
Spring cloud config to
externalize the topology configuration
Spring actuator endpoints for
environment details
Eureka dashboard to view all
the deployed component instances and the status
Further elaboration on Ribbon and actuator is out of
scope for this paper.
4.1.2. Application of Solution
The application configuration/properties are stored
GIT repository and application accesses the properties via
Spring Cloud config
server. Multiple instances
of Eureka server
run in load balanced
mode for resilience.
Application components register
themselves as services
with Eureka which is monitored at instance level using Eureka dashboard.
Components use Ribbon load balancer to for intra application communication.
Application
configuration/properties are externalized
in GIT repository
so that they
can be independently updated
without the need for restarting the components.
4.1.3.
Advantages of Solution
Eureka
server can be
made highly available
by deploying multiple
instances replicating state about the registered services to the
others.
Eureka uses the client heartbeat to determine if a
client is up. The Eureka server
replicates the heart beat info across all its instances and does not
have a backend store. The service registration cache is maintained at both
server and client and it adds further to the resilience.
Major advantages here are strong resilience to
failures and lesser turnaround time. Eureka clients use their in-memory cache
of eureka registrations, so they don’t have to go to the registry for every
single request to a service.
Another advantage is that in case of failure of heart
beat replications between peers, the server has
the intelligence to
detect this situation
and in such
cases, it enters
into a self-preservation mode protecting the current
state.
One out of the key features provided by Eureka is a
built in dashboard which displays all the registered services along with
additional details.
Sample
Eureka Dashboards
Spring Cloud Config provides server and client-side
support for externalized configuration in a distributed system.
Default server storage
back end uses
GIT and can
load the configuration based on different labels from
GIT.
The configuration data formats can be YAML, Properties
file or even plain text. Configuration change
in GIT repository
is propagated to
Config Server automatically. However
specific implementation is needed to propagate config changes from
Spring cloud server to all its clients.
On
startup, Spring config
client binds to
the Spring config
server and initializes
spring environment with remote property sources. Clients can discover Spring
config server via Eureka service.
4.2.Second Solution - Zookeeper
4.2.1. Introduction of Solution
The second solution
primarily uses Spring
Cloud Zookeeper for
service registration and externalizing configuration. It also uses
Spring Boot actuator endpoints for environment details.
4.2.2. Application of Solution
Application
configuration/properties are stored
in Zookeeper znodes.
Components register themselves as
services in Zookeeper.
A component use Zookeeper to discover another
component/service. Application configuration is refreshed automatically
whenever the configuration gets updated in Zookeeper.
Spring
Boot actuator endpoints
are used to
check the health
and other environment
details of components.
As in case of previous solution, application
configuration is externalized with Zookeeper so that it can be independently
updated without the need for restarting the application component.
4.2.3. Advantages of solution
Zookeeper is used as the centralized service for
maintaining both configuration information and service registration.
Zookeeper allows distributed processes to coordinate
with each other through a shared hierarchal namespace. The name space is made
up of data registers - called znodes. The znodes are very much similar to files
and directories but znodes are kept in memory.
Zookeeper is replicated over a set of nodes that make
up an ensemble. If one node fails, other nodes
can serve client
requests as long
as majority of
nodes are up.
Due to this
Zookeeper provides high performance and availability.
All write requests from clients are forwarded to a
single server called leader who propagates the same to rest of the nodes called
followers.
5. Results
/ Conclusion
Zookeeper
and Eureka are
equally good for
service discovery. However,
we need to
consider various factors while considering one solution over the other
which are described below.
While Zookeeper has a leader node which leads the
quorum; there is no such dependency in case of Eureka. In case of network failure amongst nodes, Eureka nodes can still operate normally whereas Zookeeper may
need to deal with leader re-election.
Eureka
services can be monitored with a readily
available out of box dashboard.
Service
discovery is the primary use case for Eureka and externalized configuration is
the primary use case for Spring Cloud Config. Though these use cases apply to
Zookeeper as well, it can also be used for host of other reasons such as
message queue, event broadcasting etc.
However Zookeeper znodes can only be monitored via a
command line interface or JMX console.
Any
changes to configuration are automatically propagated to
the application components in
Zookeeper. However for Spring
Cloud config, the
configuration changes in GIT are propagated only to
Spring Config server not to the application components. To
propagate the changes
further to application
components, the refresh
actuator endpoint of Spring config server must be used.
Another advantage of Zookeeper is that a single
Zookeeper cluster can provide both features - service registration
and application configuration. However
separate servers are
needed for Eureka and for config
server.
With respect to externalized configuration, Spring
cloud config can load files in any format (e.g. YAML) and transform
automatically to object model using Spring framework. Whereas in case of
Zookeeper, specific implementation is needed to load the configuration or needs
to be done manually using command line interface.
Both these solutions have their own advantages and
disadvantages. If service dashboard is not a priority and
the services are
deployed in a
datacenter, Zookeeper may
be a good
choice. However, if service
dashboard is a
priority and services
are deployed in
cloud environment, Eureka and
String Cloud Config combination scores over Zookeeper.
In our case, the advantages of Eureka and Spring cloud
config outweighed Zookeeper and hence we developed the solution with the first
approach. We are yet to ascertain how these solutions behave in actual
production environment.
6. References
http://cloud.spring.io/spring-cloud-netflix/spring-cloud-netflix.html https://cloud.spring.io/spring-cloud-config/spring-cloud-config.html
Subscribe to:
Posts (Atom)