Friday, November 15, 2019

Microservice


from guru 99

What are Microservices?

Microservices is a service-oriented architecture pattern wherein applications are built as a collection of various smallest independent service units. It is a software engineering approach which focuses on decomposing an application into single-function modules with well-defined interfaces. These modules can be independently deployed and operated by small teams who own the entire lifecycle of the service.
The term "micro" refers to the sizing of a microservice which must be manageable by a single development team ( 5 to 10 developers). In this methodology, big applications are divided into smallest independent units.
In this beginners training course, you will learn-

What is Monolithic Architecture?

In layman terms, you can say that Monolithic architecture is like a big container in which all the software components of an application are clubbed into a single package.
Let's discuss an example of an eCommerce store in context of a Monolithic architecture.
In any e-commerce application, there are some standard features like Search, Review & Ratings, and Payments. These features are accessible to customers using their browser or apps. When the developer of the eCommerce site deploys the application, it is a single Monolithic unit. The code for different features like Search, Review & Ratings, and Payments are on the same server. To scale the application, you need to run multiple instances(servers) of these applications.

What is Microservice Architecture?

Microservice Architecture is an architectural development style which allows building an application as a collection of small autonomous services developed for a business domain.
Let's take an example of e-commerce application developed with microservice architecture. In this example, each microservice is focused on single business capability. Search, Rating & Review and Payment each have their instance (server) and communicate with each other.
Microservices Architecture Example
In this Monolithic Architecture, all the components coalesce into a single module. But, in Microservices Architecture they are spread into individual modules(microservice) which communicate with each other.
The communication between microservices is a stateless communication where each pair of request and response is independent. Hence, Microservices can communicate effortlessly. In the Microservice Architecture, the Data is federated. Each Microservice has its separate data store.

Microservices vs. Monolithic Architecture

Microservices
Monolithic Architecture
Every unit of the entire application should be the smallest, and it should be able to deliver one specific business goal.
A single code base for all business goals
Service Startup is relatively quick
Service startup takes more time
Fault isolation is easy. Even if one service goes down, other can continue to function.
Fault isolation is difficult. If any specific feature is not working, the complete system goes down. In order to handle this issue, the application needs to re-built, re-tested and also re-deployed.
All microservices should be loosely coupled so that changes made in one does not affect the other.
Monolithic architecture is tightly coupled. Changes in one module of code affect the other
Businesses can deploy more resources to services that are generating higher ROI-return on investment
Since services are not isolated, individual resource allocation not possible
More hardware resources could be allocated to the service that is frequently used. In the e-commerce example above, more number of users check the product listing and search compared to payments. So, more resources could be allocated to the search and product listing microservice.
Application scaling is challenging as well as wasteful.
Microservices always remains consistent and continuously available.
Development tools get overburdened as the process needs to start from the scratch.
Data is federated. This allows individual Microservice to adopt a data model best suited for its needs.
Data is centralized.
Small Focused Teams. Parallel and faster development.
Large team and considerable team management effort is required
Change in the data model of one Microservice does not affect other Microservices.
Change in data model affects the entire database
Interacts with other microservices by using well-defined interfaces
Not applicable
Microservices work on the principle that focuses on products, not projects
Put emphasize on the entire project
No cross-dependencies between code bases. You can use different technologies for different Microservices.
One function or program depends on others.

Microservice Challenges

  • MicroServices rely on each other, and they will have to communicate with each other.
  • Compared to monolithic systems, there are more services to monitor which are developed using different programming languages.
  • As it is a distributed system, it is an inherently complex model.
  • Different services will have its separate mechanism, resulting in a large amount of memory for an unstructured data.
  • Effective management and teamwork required to prevent cascading issues
  • Reproducing a problem will be a difficult task when it's gone in one version, and comes back in the latest version.
  • Independent Deployment is complicated with Microservices.
  • Microservice architecture brings plenty of operations overhead.
  • It is difficult to manage application when new services are added to the system
  • A wide array of skilled professionals is required to support heterogeneously distributed microservices
  • Microservice is costly, as you need to maintain different server space for different business tasks.

SOA vs. Microservices

SOA services are maintained in the organization by a registry which acts as a directory listing. Applications need to look up the services in the registry and invoke the service.
In another world, SOA is just like an orchestra where each artist is performing with his/her instrument while the music director gives instructions to all.
On the other end, Microservices is a form of service-oriented architecture style wherein applications are built as a collection of different smaller services instead of one software or application.
Microservices is just like a troupe where each dancer is independent and know what they need to do. So, if they miss some steps, they know how to get back on the correct sequence.
Here is a detailed comparison between SOA and Microservices
SOA is feature based
Microservices is Task based.
Parameter
SOA
Microservices
Design type
In SOA, software components are exposed to the outer world for usage in the form of services.
Micro Service is a part of SOA. It is an implementation of SOA.
Dependency
Business units are dependent.
They are independent of each other.
Size of the Software
Software size is larger than any conventional software
The size of the Software is always small in Microservices
Technology Stack
The technology stack is lower compared to Microservice.
Microservice technology stack could be very large
Nature of the application
Monolithic in nature
Full stack in nature
Independent and Focus
SOA applications are built to perform multiple business tasks.
They are built to perform a single business task.
Deployment
The deployment process is time- consuming.
Deployment is straightforward and less time-consuming.
Cost - effectiveness
More cost-effective.
Less cost-effective.
Scalability
Less compared to Microservices.
Highly scalable.
Business logic
Business logic components are stored inside of single service domain Simple wire protocols(HTTP with XML JSON)
API is driven with SDKs/Clients
Business logic can live across domains enterprise Service Bus like layers between services Middleware

Microservices Tools

1. Wiremock: Testing Microservices
WireMock is a flexible library for stubbing and mocking web services. It can configure the response returned by the HTTP API when it receives a specific request. It is also y used for testing Microservices.
Download link: http://wiremock.org/
2. Docker
Docker is open source project that allows us to create, deploy, and run applications by using containers. By using these containers, developers can run an application as a single package. It allows you to ship libraries and other dependencies in one package.
Download link: https://www.docker.com/
3. Hystrix
Hystrix is a fault tolerance java library. This tool is designed to separate points of access to remote services, systems, and 3rd-party libraries in a distributed environment like Microservices. It improves overall system by isolating the failing services and preventing the cascading effect of failures.

Best Practices of Microservices Architecture

  • Separate data store for each Microservice
  • Keep code of a similar level of maturity.
  • Separate build for each Micro service
  • Always treat- sever as stateless.
Summary
  • Microservices is a service-oriented architecture pattern wherein applications are built as a collection of various smallest independent service units.
  • Microservice Architecture is an architectural development style that allows building an application as a collection of small autonomous services developed for a business domain.
  • Monolithic architecture is like a big container in which all the software components of an application are clubbed into a single package
  • In a Microservice, every unit of the entire application should be the smallest, and it should be able to deliver one specific business goal
  • In Monolithic architecture, large code base can slow down the entire development process. New releases can take months. Code maintenance is difficult
  • Two types of Microservices are 1) Stateless 2) Stateful
  • Microservices rely on each other, and they will have to communicate with each other. Helps you to give emphasizes on a specific feature and business needs
  • Service-oriented architecture shortly known as SOA is an evolution of distributed computing based on the request or reply design model for synchronous and asynchronous applications
  • In SOA, software components are exposed to the outer world for usage in the form of services whereas Micro Service is a part of SOA. It is an implementation of SOA
  • Wiremock, Docker, and Hystrix are some popular Microservices Tools
Fast Delivery, Easy Maintenance

SOA

From guru 99
Service-oriented architecture (SOA) is an architectural pattern in computer software design in which application components provide services to other components via a communications protocol, typically over a network. The principles of service-orientation are independent of any product, vendor or technology.
SOA just makes it easier for software components over various networks to work with each other.
Web services which are built as per the SOA architecture tend to make web service more independent. The web services themselves can exchange data with each other and because of the underlying principles on which they are created, they don't need any sort of human interaction and also don't need any code modifications. It ensures that the web services on a network can interact with each other seamlessly.
SOA is based on some key principles which are mentioned below
1. Standardized Service Contract - Services adhere to a service description. A service must have some sort of description which describes what the service is about. This makes it easier for client applications to understand what the service does.
2. Loose Coupling – Less dependency on each other. This is one of the main characteristics of web services which just states that there should be as less dependency as possible between the web services and the client invoking the web service. So if the service functionality changes at any point in time, it should not break the client application or stop it from working.
3. Service Abstraction - Services hide the logic they encapsulate from the outside world. The service should not expose how it executes its functionality; it should just tell the client application on what it does and not on how it does it.
4. Service Reusability - Logic is divided into services with the intent of maximizing reuse. In any development company re-usability is a big topic because obviously one wouldn't want to spend time and effort building the same code again and again across multiple applications which require them. Hence, once the code for a web service is written it should have the ability work with various application types.
5. Service Autonomy - Services should have control over the logic they encapsulate. The service knows everything on what functionality it offers and hence should also have complete control over the code it contains.
6. Service Statelessness - Ideally, services should be stateless. This means that services should not withhold information from one state to the other. This would need to be done from either the client application. An example can be an order placed on a shopping site. Now you can have a web service which gives you the price of a particular item. But if the items are added to a shopping cart and the web page navigates to the page where you do the payment, the responsibility of the price of the item to be transferred to the payment page should not be done by the web service. Instead, it needs to be done by the web application.
7. Service Discoverability - Services can be discovered (usually in a service registry). We have already seen this in the concept of the UDDI, which performs a registry which can hold information about the web service.
8. Service Composability - Services break big problems into little problems. One should never embed all functionality of an application into one single service but instead, break the service down into modules each with a separate business functionality.
9. Service Interoperability - Services should use standards that allow diverse subscribers to use the service. In web services, standards as XML and communication over HTTP is used to ensure it conforms to this principle.


API interview questions

  https://www.katalon.com/resources-center/blog/web-api-testing-interview-questions/ Top 50+ Web API Testing Interview Questions [Ultimate l...