Microservice is a software architecture that is gaining more and more attention.
But what does it really mean? What kind of architecture can be called microservices?
There are many articles online, but they are all too complicated for beginners to understand. In my opinion, the concept is actually very simple and can be made clear in layman's terms.
I. Monolithic software
To understand microservices, you first need to understand the evolution of software architecture.
Early software, where all functions were written together, was called monolithic architecture (monolithic software).
The entire software is a single whole, as if it were an integrated machine.
As you can imagine, the more features the software has, the more complex the monolithic architecture becomes, and many of its shortcomings are exposed.
(1) All functions are coupled together and affect each other, ultimately making them difficult to manage.
(2) Even if only one line of code is modified, the entire software has to be rebuilt and redeployed, which is very costly.
(3) Because the software is made as a whole, it is not possible to develop and test each feature individually, but only as a whole, leading to the necessity of a waterfall development model.
A detailed analysis of the above three reasons can be found in my previous article "The Biggest Puzzle in Software Engineering".
In short, large software with a monolithic architecture is not only slow to develop, but also creates complex code that is difficult to maintain and upgrade and becomes a heavy burden for programmers.
II. Service-oriented architecture
To solve these problems above, it was suggested early on that the coupling of code must be broken down and the monolithic architecture split into separate functional units of software.
About 20 years ago, with the advent of the Internet, units of functionality could be provided in the form of remote "services", giving rise to "service-oriented architecture" (SOA).
A service is a program that runs uninterrupted in the background and provides some kind of functionality. The most common service is a web service, which provides web access to the outside world through port 80.
A "service-oriented architecture" is a large monolithic program that is split into individual services, i.e. smaller programs. Each service is a separate functional unit with a different function, and the services are linked together by communication protocols.
There are many advantages to this architecture.
(1) Each service has a single function, equivalent to a small software, which is easy to develop and test.
(2) Individual services operate independently, simplifying the architecture and improving reliability.
(3) Encourage and support code reuse, where the same service can be used for multiple purposes.
(4) Different services can be developed and deployed separately to facilitate upgrades.
(5) Good expandability, can easily add machines and functions and withstand high loads.
(6) Not prone to single point of failure. Even if one service fails, it does not affect other services.
Unlike monolithic architectures, service-oriented architectures are language-insensitive; different services can be developed using different languages and tools and may need to be deployed on different systems and environments.
This means that service-oriented architecture runs on different servers by default, with each server providing one service and multiple servers working together to form a complete web application.
III. Microservices
In 2014, Docker came along and revolutionized the face of software development. It lets programs run in containers, each of which can be set up separately as a runtime environment, and takes up very few system resources.
Obviously, containers can be used to implement a "service-oriented architecture", where each service no longer occupies a server, but a container.
This eliminates the need for multiple servers, and in the simplest case, runs multiple containers natively and implements a service-oriented architecture with just one server, which could not be done before. This implementation is called microservices.
Simply put, microservices is a service-oriented architecture that uses container technology. It still uses "service" as a functional unit, but it is a lightweight implementation that does not require a new server, but a new container (a process), hence the name "microservice".
A microservice is a separate process. This process can run locally, on another server, or in the cloud (e.g., Cloud Services and Cloud Functions FaaS).
It has the same characteristics as a service-oriented architecture, but because it's more lightweight, decoupling and servitization of functionality can be done more thoroughly. Also, it can be standardized so that the same container will have the same result no matter where it is run, so there are many SaaS products on the market that offer standardized microservices.
It is due to these outstanding benefits of microservices that it has become so popular over the years. It, along with container technology and cloud services, is sure to play an increasingly important role in the future of software development.
(end)