With the proliferation of online applications, their architectures need to continuously evolve to make them stand out in the multitude of similar apps. Applications must be highly available and resilient while running on cloud environments. To ensure a consistent user experience, organizations need to frequently roll out updates, even multiple times in a day. However, monolithic web applications that serve up HTML to desktop browsers cannot cope with such regular updates and hamper developers’ productivity.
This led to the need for a new architecture: Microservices.
Let’s see what it stands for ?
Microservices is a way of breaking large software projects into loosely coupled modules that communicate with each other through simple APIs.
Microservices architecture involves developing applications as a suite of multiple independent modular services with each of them serving a unique purpose. Each of these services runs a particular process and communicates internally with other modules to serve a business goal.
Let’s dig deeper and understand why microservices architecture is needed.
Need of Microservices Architecture:
An independent application may have different individual modules that cater to the different business or technical needs. For a low-scale application with low complexity, the processing of overall tasks isn’t difficult when all modules are present in the same application. In fact, this improves program debugging speed and ensures a high level of execution efficiency.
However, as the scale of an independent application increases, these benefits soon fade away. With business expansion and changing needs, application backend gradually becomes too complex for developers to manually handle and scale. You need the ability to internally restructure your application based on changing requirements by adding, removing, or changing modules. Dead code appears and restructuring becomes more difficult. Minor changes may often impact the entire application. In this case, to resize or upgrade any module, you have to resize or upgrade all modules in the application. The program’s external dependencies become increasingly complex and the scope of automated testing falls.
To address all of these shortcomings, microservice architecture was developed. Let’s see how they bring value to your development process and application efficiency.
An application is made up of multiple services, where each service handles one set of tasks. In microservice architecture, these multiple services communicate with each other using web protocols, such as HTTP or JSON. Microservice advantages are:
- Resilient: Independent services are easy to discard. During an upgrade, you can easily replace an old service instance with a new one.
- Easy-to-enhance: The code becomes easy to change, overwrite, and discard as per the requirement.
- Ease-of-deployment: Deployment or rollback of independent modules become easier and faster without any impact on the remaining system.
- Improved Fault Isolation: Failure of a single module doesn’t affect other modules present in the application.
- Individual Services Scalability: Demanding modules or services can be easily scaled up without any need of scaling up the whole application.
- Hybrid Programming Support: Gives flexibility to select the most appropriate technologies for individual services without any impact on other services.
- Simplified Development Process: Independent modules can be assigned to different teams/groups to make the overall development process easier and convenient.
Needless to say, Microservices definitely make your life easier, but there are some drawbacks too.
Microservices: A silver bullet?
Although the name includes the qualifier, “micro,” its implementation requires manual efforts. If you do not have a complete understanding of the business field and are unaware of the true business needs, the management of multiple services along with numerous relevant processes becomes a daunting task. Besides, the number of processes grows when load balancing and messaging middleware are added. Management, operation, and orchestration of all these services become cumbersome. In addition, you need a DevOps expert for implementation and management of these architectures, which adds to overall overhead.
As microservice architecture acts a distributed system, a certain level of complexity gets added. Also, it can lead to several issues, including network latency, fault tolerance, message serialization, and asynchronicity.
As the number of service instances constantly changes, data traffic fluctuations significantly increase with the complexity of monitoring and log analysis. There are many open source monitoring and log solutions, but it is not easy to construct and customize a set of personalized solutions.
This demands for an all-in-one platform to address your non-functional needs, such as high availability, monitoring, and logs to make it easy to implement and manage a microservices architecture.
The best way to run a microservices application architecture is to use application containers. Container technology allows you to create a standard image from an application and its dependencies, and use this image throughout the process from development through testing to the production environment. DevOps fills in the gap between development and O&M.
Alibaba Cloud, with its efficient container service, is becoming the cornerstone for innovation and enabler for microservices architecture.
Alibaba Cloud Container Service: Comprehensive Platform to Create and Operate Microservices
It is a fully managed cloud container management service that enables you to efficiently run and manage Docker applications on a distributed cluster of Alibaba Cloud ECS instances. It replaces the need to install, operate, and scale your container cluster infrastructure.
In this series of articles, we will explore the use of Spring Cloud in the creation of microservice applications on the Alibaba Cloud Container Service.
Let’s firstly explore the basics of Spring Cloud and Netflix.
Spring Cloud and Netflix Overview
Spring Cloud is a project in Spring framework that provides development capabilities for common modules in distributed systems. These capabilities are configuration management (Config Server), service discovery (Eureka), service fusion (Hystrix), intelligent routing (Zuul), and Netflix OSS-based encapsulations. Using annotation statements, we can easily use Netflix open source products in Spring Boot applications to create microservices applications with production-level availability.
Building Microservices Applications: Sample Code
We are creating a complete microservices application in a virtual scenario which can run locally on Docker or be deployed on the Alibaba Cloud container service. View the sample code.
Comprehending Service-oriented Applications
In our simulated scenario, we break down an enterprise’s internal applications into multiple services and enable them to communicate with each other via API calls.
”Foo” and ”bar” are two basic services that use an intranet to access other services via APIs, but do not provide external service over the Internet. “Foobar” as a single application provides external services and must call both foo and bar services during processing.
Inter-Services Logical Architecture Diagram
Provided by discovery-server, the service discovery mechanism is based on Eureka. As discovery server is independent of the business, developers can simply use Docker images.
The foobar service provides external service by registering with the intelligent application routing gateway service. The gateway is based on Zuul and because its code is independent of the business, developers can simply use a Docker image. However, Zuul uses configuration files to describe the URL access modes corresponding to different services, and developers will need to change the image configuration files to actually use it or mount a volume to implement configuration file sharing and modification.
The foo, bar, and foobar code contains Eureka and Ribbon Client to provide Eureka self-registration and Eureka query capabilities, while Ribbon implements client load balancing.
During operation, each service is elastically scaled based on its load and may be composed of multiple running instances. During startup, all service instances are automatically registered with the Eureka Server. Inter-service discovery also uses the Eureka Server to fetch instance information and select an instance to access based on the automatic decision of the Ribbon Client. We do not use centralized load balancing, but discover and balance load through the clients.