Chapter 1 of "Microservice Architecture Design Patterns"

Escape from single hell

FTGO monolithic architecture

​​​​​​The author uses the application example of a foreign company FTGO (an online catering takeout company) to explain the advantages and disadvantages of a monolithic architecture. The FTGO application architecture is as follows:Insert image description here

The application is a single application with a hexagonal architecture. The innermost part is business logic, including order management, delivery management, user management, etc. Outside the business logic are adapters that implement the user interface and adapters that interface with external systems. External systems such as: messaging service, email service, payment service, database. Through these adapters, business logic can access the database and call external services.

Benefits of monolithic architecture

  1. Application development is simple: just build this one application.
  2. Easy to make large-scale changes: code and database schema can be changed, then built and deployed.
  3. Testing is relatively simple and intuitive: if you only have this one application, just test the interface or use Selenium. Selenium is a tool that can control the browser.
  4. Simple deployment: The only thing the developer has to do during deployment is to copy the WAR file to the server where tomcat is installed.
  5. Horizontal scaling is effortless: multiple instances can be run, and there's a load balancer for scheduling. Let me mention here what horizontal expansion and vertical expansion are:
    Horizontal expansion and vertical expansion are both architectural concepts.
    Horizontal expansion is to add machines or nodes to the environment, such as adding a machine/node to the service, adding a slave database to mysql, etc., and each node completes it together. When everyone adds firewood, the flames rise.
    Vertical development is to improve the processing capabilities of a single node, such as adding memory to mysql, improving machine CPU performance, etc. Pay attention to personal development and have outstanding personal abilities

Disadvantages of monolithic architecture

  1. Excessive complexity scares away developers: The system is huge and complex, and it is difficult for developers to sort out the logic. It is difficult and time-consuming to change or add new functions. This situation will get worse with each development, a bit like in the industry. I mean "pile of mountains", hahaha.
  2. Slow development speed: The system is too large, and it will take longer and longer to build, start, test, and deploy, seriously affecting development efficiency.
  3. Difficult to expand: Expansion here means that the more functions the system provides, the more resources it requires. Such as memory, cpu, gpu. Ordinary servers cannot meet the requirements, and high-performance servers are required.
  4. Unreliable delivery: If there is a problem with one module, the entire service may malfunction or go down. One reason for problems is that the system is too large to be fully tested.

The Way to the Rescue: Microservice Architecture

Microservice concept

The famous architect of Netflix defines microservices as a service-oriented architecture composed of loosely coupled and bounded context elements. The authors describe a three-dimensional scalability model to better illustrate
Insert image description here
the X-axis: replicating instances and implementing load balancing to improve throughput and availability. Nothing much to say. It belongs to the horizontal expansion mentioned above.

Y-axis: Split the application into services based on functionality. Reduce application complexity.
Insert image description here

Z-axis: Requests are routed based on the attributes of the request, with each instance responsible for a subset of the data. For example, if you query user information, the request will be routed to the corresponding instance based on useId.


Insert image description here
A key feature of microservices is that each service is loosely coupled and communicates only through APIs. One way to achieve loose coupling is that each service has its own private database.

FTGO microservice architecture

Insert image description here
Split the single application into services such as order management, delivery management, restaurant management, and user management. Each service and API has its own clear definition, has an independent database, and can be developed, deployed, and expanded independently.

Microservices benefits

  1. Large and complex applications can be continuously delivered and deployed, which is the biggest benefit of microservices
  2. Each service is relatively small, easy to maintain, independently scalable, deployable, highly fault-tolerant, and can achieve team autonomy. Barabara…

Disadvantages of microservices

Microservices are not a silver bullet (similar to a special-effect weapon), and it does not mean that microservices can solve all problems in software.

  1. Service splitting and definition is a challenge. How to split and define does need to be considered. Otherwise, it may be split into a set of highly coupled microservice architecture.
  2. The complexity that comes with distributed systems. When one service becomes multiple, communication between services becomes necessary. This is more complicated than calling a local method by a service, and you need to consider the unavailability or high latency of the remote service and do troubleshooting. During development, multiple applications need to be opened. During testing, one application was deployed before, but now multiple applications may be deployed. If the application does not belong to the same team, deployment costs must be communicated with other teams.
  3. At what stage are microservices used? When you first start developing a project and need to iterate quickly, carefully designing a distributed architecture will slow down the development speed. When the problem becomes complex, it becomes necessary to decompose the application into a set of services. But how to reconstruct complex applications is also a problem.

Guess you like

Origin blog.csdn.net/Theflowerofac/article/details/132692812