Sunday, October 6, 2019

The Microservices Design Pattern



Microservice Design Patterns for Performance Monitoring

Monitoring the performance is an important aspect for a successful microservice architecture. It helps calculate the efficiency and understand any drawbacks which might be slowing the system down. Remember the following patterns related to observability for ensuring a robust microservice architecture design.

1. Log Aggregation

When we refer to a microservice architecture we are referring to a refined yet granular architecture where an application is consisting a number of microservices. These microservices run independently and simultaneously as supporting multiple services as well as their instances across various machines. Every service generates an entry in the logs regarding its execution. How can you keep a track for numerous service related logs? This is where log aggregation steps in. As a best practice to prevent from chaos, you should be having a master logging service. This master logging service should be responsible for aggregating the logs from all the microservice instances. This centralized log should be searchable, making it easier to monitor.

2. Synthetic Monitoring a.k.a Semantic Monitoring

As I explained previously, monitoring is a painful but indispensable task for a successful microservice architecture. With simultaneous execution of hundreds of services it becomes troublesome to pinpoint the root area responsible for the failure in log registry. Synthetic monitoring gives a helping hand. When you perform automated test then synthetic monitoring helps to regularly map the results in comparison to the production environment. User gets alerted if a failure is generated. Using Semantic Monitoring you can aim for 2 things using a single arrow
  • Monitoring automated test cases.
  • Detecting Production failures in terms of business requirements.

3. API Health Check

Microservice architecture design promotes services which are independent of each other to avoid any delay in the system. APIs as we know serve as the building blocks of an online connectivity. It is imperative to keep a health check on your APIs on regular basis to realize any roadblock. It is often observed that a microservice is up and running yet incapacitated for handling requests. This can be due to many factors:
  • Server Loads
  • User Adoption
  • Latency
  • Error Logging
  • Market Share
  • Downloads
In order to overcome this scenario we should ensure that every service running must have a specific health check API endpoint. For example: HTTP/health when appended at the end of every service will return the health status for respective service instance. A service registry periodically appeals to the health check API endpoint to perform a health scan. The health check would provide you with the information on the below-mentioned:
  1. A logic that is specific to your application.
  2. Status of the host.
  3. Status of the connections to other infrastructure or connection to any service instance.

Breaking it all down to Business Capability

The process of ‘decomposing’ a monolithic architecture into a microservice needs to follow certain parameters. These parameters have a different basis. Today we will look at the decomposition of the microservice design patterns which leave a lasting impact.

1. Unique Microservice for each Business Capability

A microservice is as successful as its combination of high cohesion and loose coupling. Services need to be loosely coupled while keeping the function of similar interests together. But how do we do it? How do we decompose a software system into smaller independent logical units?
We do so by defining the scope of a microservice to support a specific business capability.
For Example – 
In every organization, there are different departments that come together as one. These include technical, marketing, PR, sales, service, and maintenance. To picture a microservice structure these different domains would each be the microservices and the organization will be the system. 
So an Inventory management is responsible for all the inventories. Similarly, Shipping management will handle all the shipments and so on.
To maintain efficiency and foresee growth, the best solution is to decompose the systems using business capability. This includes classification into various business domains which are responsible to generate value in their own capabilities.

2. Microservices around similar Business Capability

Despite segregating on the basis of business capabilities, microservices often come up with a greater challenge. What about the common classes among the services? Well, decomposing these classes known as ‘God Classes’ needs intervention. For example, in case of an e-commerce system, the order will be common to several services such as order number, order management, order return, order delivery etc. To solve this issue, we turn to a common microservice design principle known as Domain-Driven Design (DDD).
In Domain-Driven Design, we use subdomains. These subdomain models have defined scope of functionality which is known as bounded context. This bounded context is the parameter used to create each microservice thus overcoming the issues of common classes.

3. Strangler Vine Pattern

While we discuss decomposition of a monolithic architecture, we often miss out the struggle of converting a monolithic system to design microservice architecture. Without hampering the working, converting can be extremely tough. And to solve this problem we have the strangler pattern, based on the vine analogy. Here is what the Strangler patterns mean in Martin Fowler’s words:
“One of the natural wonders of this area [Australia] is the huge strangler vines. They seed in the upper branches of a fig tree and gradually work their way down the tree until they root in the soil. Over many years they grow into fantastic and beautiful shapes, meanwhile strangling and killing the tree that was their host.”
Strangler pattern is extremely helpful in case of a web application where breaking down a service into different domains is possible. Since the calls go back and forth, different services live on different domains. So, these two domains exist on the same URI. Once the service has been reformed, it ‘strangles’the existing version of the application. This process is followed until the monolith doesn’t exist.

Microservice Design Patterns for Optimizing Database Storage

For a microservice architecture, loose coupling is a basic principle. This enables deployment and scalability of independent services. Multiple services might need to access data not stored in their unit. But due to loose coupling, accessing this data can be a challenge. Mainly because different services have different storage requirements and access to data is limited in microservice design. So, we look at some major database design patterns as per different requirements.

1. Individual Database per Service

Usually applied in Domain Driven Designs, one database per service articulates the entire database to a specific microservice. Due to the challenges and lack of accessibility, a single database per service needs to be designed. This data is accessible only by the microservice. This database has limited access for any outside microservices. The only way for others to access this data is through microservice API gateways.

2. Shared Database per Service

In Domain Driven Design, a separate database per service is feasible, but in an approach where you decompose a monolithic architecture to microservice, using a single database can be tough. So while the process of decomposition goes on, implementing a shared database for a limited number of service is advisable. This number should be limited to 2 or 3 services. This number should stay low to allow deployment, autonomy, and scalability.

3. Event Sourcing Design Pattern

According to Martin Fowler
Event Sourcing ensures that all changes to application state are stored as a sequence of events. Not just can we query these events, we can also use the event log to reconstruct past states, and as a foundation to automatically adjust the state to cope with retroactive changes.
The problem here lies with reliability. How can you rely on the architecture to make a change or publish a real-time event with respect to the changes in state of the application?
Event sourcing helps to come up from this situation by appending a new event to the list of the events every time a business entity changes its state. Entities like Customer may consist of numerous events. It is thus advised that an application saves a screenshot of the current state of an entity in order to optimize the load.

3. Command Query Responsibility Segregation (CQRS)

In a database-per-service model, the query cannot be implemented because of the limited access to only one database. For a query, the requirements are based on joint database systems. But how do we query then?
Based on the CQRS, to query single databases per service model, the application should be divided into two parts: Command and Query. In this model, command handles all requests related to create, update and delete while queries are taken care of through a materialized view. These views are updated through a stream of events. These events, in turn, are created using an event sourcing pattern which marks any changes in the data. These changes eventually become events.

Microservice Design Patterns for Seamless Deployment

When we implement microservices, there are certain issues which come up during the call of these services. When you design microservice architecture, certain cross-cutting patterns can simplify the working.

1. Service Discovery

The use of containers leads to dynamic allocation of the IP address. This means the address can change at any moment. This causes a service break. In addition to this, the users have to bear the load of remembering every URL for the services, which become tightly coupled.
To solve this problem and give users the location of the request, a registry needs to be used. While initiation, a service instance can register in the registry and de-register while closing. This enables the user to find out the exact location which can be queried. In addition, a health check by the registry will ensure the availability of only working instances. This also improves the system performance.

2. Blue-Green Deployment

In a microservice design pattern, there are multiple microservices. Whenever updates are to be implemented or newer versions deployed, one has to shut down all the services. This leads to a huge downtime thus affecting productivity. To avoid this issue, when you design microservice architecture, you should use the blue-green deployment pattern.
In this pattern, two identical environments run parallelly, known as blue and green. At a time only one of them is live and processing all the production traffic. For example, blue is live and addressing all the traffic. In case of new deployment, one uploads the latest version onto the green environment, switches the router to the same and thus implement the update.

Microservice Design Patterns for Performance Monitoring

Monitoring the performance is an important aspect for a successful microservice architecture. It helps calculate the efficiency and understand any drawbacks which might be slowing the system down. Remember the following patterns related to performance monitoring for ensuring a robust microservice architecture design.

1. Log Aggregation

When we refer to a microservice architecture we are referring to a refined yet granular architecture where an application is consisting a number of microservices. These microservices run independently and simultaneously as supporting multiple services as well as their instances across various machines. Every service generates an entry in the logs regarding its execution. How can you keep a track for numerous service related logs? This is where log aggregation steps in. As a best practice to prevent from chaos, you should be having a master logging service. This master logging service should be responsible for aggregating the logs from all the microservice instances. This centralized log should be searchable, making it easier to monitor.

2. Synthetic Monitoring a.k.a Semantic Monitoring

With the increase in load and microservices, it becomes important to keep a constant check on system performance. This includes any patterns which might be formed or addressing issues that come across. But more importantly, how is the data collected?
The answer lies with the use of a metric service. This metrics service is either in the Push form or the Pull form. As the name suggests, a Push service such as AppDynamics pushes the metrics to the service while a Pull service such as Prometheus pulls the data from the service.

3. Running a Health Check

Microservice architecture design promotes services which are independent of each other to avoid any delay in the system. But, there are times when the system is up and running but it fails to handle transactions due to faulty services. To avoid requests to these faulty services, a load balancing pattern has to be implemented.
To achieve this, we use ‘/health’ at the end of every service. This check is used to find out the health of the service. It includes the status of the host, its connection and the algorithmic logic.

Tuesday, July 24, 2018

A Complex Enterprise Change: AWS Cloud Transformation Management




“When it comes to cloud adoption, the biggest challenge isn't technology - it's the people and processes that must change and adapt” - Forbes
The impact of cloud adoption will affect not only your application workloads but also your organization, business models, HR and procurement processes. Organizations need to examine the influence cloud adoption has on its people, culture, and processes. Culture can be defined as the values, beliefs, and practices that exist in an organization. Culture is critical when it comes to cloud adoption because it will affect an organization’s management and the economics of its IT services.
“Cultural issues are at the root of many failed business transformations, yet most organizations do not assign explicit responsibility for culture” - Gartner
The first step in influencing cultural change is to identify the values required for the organization’s cloud adoption. Once these values are defined, it is crucial to communicate the new operating behaviors and reinforce them explicitly and implicitly by using a reward system. The last step then becomes hiring or selecting the right individuals that are excited to embrace the change and would align the values that you want to drive.
The obstacles that organizations might face as they embark on the journey to the cloud are:
●      Lack of visible and active leadership
●      Lack of change management resourcing
●      Resistance from project teams, middle-level management and fellow employees resulting from the organization’s inertia to change.
Many IT organizations are not used to driving projects with change management in mind. Organizational change management can be defined as applying tools & processes to the people side of change, to transition from a current state to a future state to successfully achieve a particular outcome.
Successful change across an enterprise does not just happen organically. Organizational change first requires individual changes and its normal to experience some reluctance and resistance to change across an organization. The scope and type of change should inform your change management plan, which comes down to selecting the appropriate toolsets for the job at hand.
There are three types of change efforts, namely:
  1. Improvement: Focuses in on the changing toolsets.
  2. Transitional: This change effort focuses mainly on changing both the toolsets and skillsets.
  3. Transformational: The key difference here is that we are looking at the impact and effect changing toolsets & skillsets has on the changing mindsets.
Across the three change efforts, communication, change & project management, training & change leadership are all required solution drivers. Elements such as training & orientation, organization design, HR strategy & support are necessary elements required for a more robust transformational change.
There are 3 phases to tactically applying change management approach to accelerate your cloud transformation.
In the first phase, your team and senior leadership have to be mobilized. The team to lead the change and build the momentum is formed and referred to as the Cloud Center of Excellence (CCoE). The CCoE can consist of a cloud engineering team and a cloud business office team. The program governance structure is shaped, and it is essential to assess and align the change leadership roles.
The second phase is about defining your vision and engaging your organization. The third and final phase is about implementing your changes. After the selection process, the leaders need to articulate and communicate the vision & roadmap for transitioning into the cloud. At this phase, it is essential for leaders to address how the change would affect the employees in the organizations.
Finally, the last phase is about enabling the capacity and ensuring successful cloud transition into the cloud. The objective of this phase is to align IT organization structure, roles, and processes with the AWS platform and too also ensure that cloud benefits and goals are achieved.  

Friday, July 20, 2018

10 Tips for Managing Cloud Costs

1. Monitor spending on a daily basis.
2. Shut down unused or unnecessary instances.
3. Require tags company-wide.
4. Rely on automation rather than manual processes.
5. Consider a standalone cloud cost management tool.
6. Invest in a hybrid cloud management tool if your needs are more complex.
7. Look for a solution with machine learning capabilities.
8. Take a systematic approach to cloud cost management.
9. Watch out for vendor lock-in.
10. Optimize private cloud costs.

Evaluation of Cloud Cost Optimization Tools

We’ve looked at a number of cloud cost optimization tools in house and for customers.  This is a brief breakdown of some of the characteristics and features of the programs.  Please realize that this is a very fast moving part of the industry.  If you decision hinges on a single feature, it’s availability may have changed by the time you read this sentence.
package
direct cloud support
import data support
deployment method
cost aggregation
shared access
RI calcs.
cap. planning
general monitoring
project breakdown
price basis
AWS, GCE
no, on roadmap for enterprise
SaaS
yes
 
yes
yes- premium product
cost monitoring only
AWS and GCE tags
free, premium $240 up to $200k spend
AWS, Google, Azure
yes, using Dropbox
SaaS, AWS install
yes
yes, via email
yes
no
cost report/daily email
yes,can split cost as well as gather
free for the basic cost monitor with a tiered pricing for more functions.
AWS, Rackspac, Azure, more...
 
SaaS
yes
 
yes
yes
 
organization, application, environment (production, test, development)
free basic tier
EC2, CloudStack, Eucalyptus, HP, Logicworks, OpenStack, RackSpace, Terremark, vCloud Director
no
Saas, on-premise
 
yes
 
yes
yes
  
AWS/EC2
 
SaaS
yes
yes
yes
yes
no
yes by tag
three tiers, free/pro/ent - pro based on cloud spend tracked
AWS, Heroku, VMWare private clouds
VMware Vsphere, Citrix XenServer, Microsoft HyperV or Private Cloud platforms like vCloud Director, OpenStack or CloudStack
SaaS
in enterprise
in enterprise
  
alerts
yes
scales on spend tracked
AWS, AWS GovCloud
no
SaaS
yes
yes
yes
yes
alerts based on thresholds, regualr scans of "best-practices"
yes
tiered fixed cost based on total spend tracked
Column key:
package - Name of the package.
URL - click the name of the package (link)
direct cloud support - The clouds that it can track costs on it’s own without any data munging by you.
import data support - Can it import records from outside sources, such as munged data or private clouds which might not be directly accessible.
deployment method - Where does the code run?
cost aggregation - Does it aggregate basic costs?
shared access - Does it support more than one user logging in? DOes it support reporting to more than one person?
RI calculations - Does it do modeling to determine where Reserved Instances would save money? (RIs are pre-purchased computing available in AWS).
cap. planning
general monitoring - Does the product do any type of alerting other than cost based? (on example: unused but paid for storage)
project breakdown - Can the product do cost breakdown by projects or groups of resources?
price basis - What is the basic concept by which they charge?