当前位置:网站首页>[learn microservice from 0] [01] what is microservice
[learn microservice from 0] [01] what is microservice
2022-07-07 12:46:00 【lpruoyu】
Continuous learning & Ongoing update …
Keep breaking away
【 from 0 Start learning about microservices 】【01】 What is microservice
Microservices :
- A software architecture style based on business functions
- Each module is developed independently 、 test 、 Deploy , Have your own process ; It has nothing to do with language ; Opening to the outside world API Interface (RPC/HTTP)
Single application
Before talking about micro services , Let me introduce you to the single application first . If you don't know the pain of monomer application , That doesn't really understand the value of microservices .
Earlier years , The application technology stacks of major Internet companies can be roughly divided into LAMP(Linux + Apache + MySQL + PHP) and MVC(Spring + iBatis/Hibernate + Tomcat) Two schools . Whether it's LAMP still MVC, They are all designed for single application architecture , Its advantage is low learning cost , Develop quickly , test 、 Deploy 、 Operation and maintenance are also more convenient , Even one person can complete the development and deployment of a website .
With the continuous expansion of business scale , The continuous expansion of team developers , The single application architecture will start to have problems . There will be some problems in the following aspects :
Inefficient deployment . Take the project I actually participated in as an example , When the code of single application is more and more , When we rely on more and more resources , Application compilation package 、 Deploy the test once , Even need to 10 Minutes or more . This is often said by new students roast , Time to deploy the test once , You can go downstairs for a cup of coffee .
The cost of teamwork is high . In my experience , In the early days when there were only two or three team developers , Collaborative code modification , Finally merge into the same master Branch , And then package and deploy , Controllable . But once the team expands , exceed 5 People modify the code , And then package and deploy together , In the test phase, only one piece of function has problems , You have to recompile, package, deploy , Then preview the test again , All the relevant developers have to be involved , inefficiency , High development cost .
The high availability of the system is poor . Because all the functional development is finally deployed to the same WAR In the bag , Run in the same Tomcat In progress , Once there is a problem with the code or resources involved in a function , That will affect the whole WAR Features deployed in the package . For example, a problem I often encounter : A piece of code keeps creating large objects in memory , And not recycled , After deploying to online operation for a period of time , Will cause JVM Memory leak , Abnormal exit , Then deploy in the same JVM All services in the process are unavailable , The consequences are very serious .
Online publishing slows down . Especially for Java applications , Once the code expands , The service will take longer to start , Some even surpass 10 Minutes or more , If the size of the machine exceeds 100 Table above , Assume that the step size for each release is 10%, A single release requires 100 minutes . therefore , There is an urgent need for a way to decouple the different modules of the application , Reduce development and deployment costs .
Microservice benefits :
- Modular deployment , Avoid a module downtime , Make the whole system unavailable
- It can be used separately for high concurrency scenarios ( seckill 、 Order 、…) Capacity expansion , Add machines
- It is convenient for developers to develop independently 、 Mutual interference
As a service
In popular terms , Service is the traditional stand-alone application through JAR Package dependency generates local method calls , Transform to pass RPC Interface generated remote method calls .
Generally, when writing business code , For some common business logic , I will try my best to abstract it and make it a special module , Because it is of great benefit to code reuse and business understanding .
Take Weibo system for example , Microblog includes content module , It also includes message module and user module . The message module depends on the content module , Both the message module and the content module depend on the user module . When the code of these three modules is coupled , When app starts , You need to load the code of each module and connect the corresponding resources at the same time . Once the code for any module appears bug, Or there is a problem with the dependent resources , The whole monomer application will be affected .
So , First of all, the user module can be separated from the single application , Independent into a service deployment , With RPC Provide external services in the form of interface . The content and message module calls the user interface , From in-process calls to remote RPC call .
such , User modules can be developed independently 、 test 、 Go live and operate , It can be done by a special team , Not coupled with other modules . Further, the message module can be divided into independent modules , Leave it to a dedicated team to develop and maintain .
It can be seen through service , It can solve the expansion of monomer application 、 Team development is highly coupled 、 The problem of inefficient collaboration .
What is microservice
from 2014 Year begins , Thanks to Docker Represented by the maturity of containerization technology and DevOps The rise of culture , The idea of servitization has further evolved , It has evolved into what we know today as micro services .
So what's the difference between microservices and service-oriented ?
in my opinion , It can be summarized as the following four points :
Service splitting is more granular . Micro service can be said to be a finer dimension of servitization , Down to a submodule , As long as the resource on which the module depends is not related to any other module , Then it can be broken down into a microservice .
Service independent deployment . Each microservice strictly follows the guidelines for independent packaging and deployment , They don't influence each other . For example, multiple units can be deployed on a single physical machine Docker example , Every Docker An instance can deploy code for a microservice .
Service independent maintenance . Each microservice can be developed by a small team or even an individual 、 test 、 Release and operations , And responsible for the entire life cycle .
Service governance capabilities are demanding . Because when you split it up into microservices , The number of services has increased , Therefore, a unified service governance platform is needed , To manage the services .
Continue to take the microblog system as an example , The function of the content module can be further divided , For example, the content module contains feed modular 、 Comment module and personal page module . Through microservicing , Turn these three modules into three separate services , Each service depends on its own resources , And independently deployed in different service pools , It can be maintained by different developers . When commenting on changes in service requirements , Just modify the comment business related code , And launch independently ; and feed Services and personal page services do not need to be changed , And it will not be affected by the changes that the release may bring .
thus it can be seen , Microservice is used to publish and deploy services , And the guarantee of service brings many benefits .
summary
The origin of the development of microservices , It evolved from a single application to a service-oriented split deployment , Later, with the continuous expansion of the scale of mobile Internet , agile development 、 Continuous delivery 、DevOps The development and practice of theory , And based on Docker Maturity of containerization Technology , Microservice architecture is becoming popular , It has gradually become the future evolution direction of application architecture .
In conclusion , Microservice architecture is the fine-grained service splitting of complex and bloated single application , Each separated service is packaged and deployed independently , And let the small team develop and operate , Thus greatly improving the efficiency of application delivery , And is widely used by major Internet companies .
Be careful
True knowledge comes from practice
It is better not to involve cross database table interaction in service splitting
Extracurricular development : What is microservice ( Wikipedia )
https://zh.wikipedia.org/wiki/%E5%BE%AE%E6%9C%8D%E5%8B%99
Microservices (Microservices) Is a software architecture style , It is With Small functional blocks that focus on a single responsibility and function Based on , With modularization The way Combine Out of complex large-scale applications , Functional blocks Use It has nothing to do with language Of API Interface sets communicate with each other .
2014 year ,Martin Fowler And James Lewis We put forward the concept of microservice , Microservices are defined as small services made up of a single application , Own your own process and lightweight processing , Services are designed according to business functions , Deploy in a fully automated manner , Use with other services HTTP API signal communication . At the same time, services will use the smallest centralized management ( for example Docker) Ability , Services can be implemented in different programming languages, databases and other components .
Microservice is a kind of Focus on business functions Service design concept , Each service has its own business functions , Opening to the outside world is not restricted by language API ( The most common is HTTP), Applications are composed of one or more microservices .
Another comparison of microservices is monolithic applications . A single application means that an application contains all the required business functions , And use an architecture like master-slave (Client/Server) Or multi-level architecture (N-tier) Realization , Although it can also be implemented as a distributed application , however In single application , Every business function is inseparable . If you want to extend a monolithic application, you must put the entire application into new computing resources ( Such as : virtual machine ) Inside , but In fact, the most resource consuming applications 、 There is only one business part that needs computing resources ( For example, run analysis report or mathematical algorithm analysis ), But this part cannot be divided because of the single application , Therefore, there will be a lot of waste of resources .
Microservices use the design concept based on business functions , When designing an application, it can be divided first by business function or process design , Each business function is independently implemented as an individual service that can be executed independently , Then use the same protocol to combine all the services required by the application , Form an application . If you need to expand specific business functions , As long as the service of this business function is extended , You don't need to extend the entire application , meanwhile , Because microservices are business function oriented implementation , Therefore, it will not be disturbed by the application , The administrator of microservices can configure microservices to different computing resources according to the needs of computing resources , Or build new computing resources and configure them .
Although general server virtualization technology can be applied to the management of microservices , But container technology (Container Technology) Such as Docker It will be more suitable for the development of computing resource management technology of microservices .
Reference resources
Wikipedia : Microservices
Geek time : from 0 Start learning about microservices -- First line practical experience of microblog service experts
The end of this paper , Thank you for your attention and support !
边栏推荐
- Day-18 hash table, generic
- [statistical learning method] learning notes - logistic regression and maximum entropy model
- SQL lab 26~31 summary (subsequent continuous update) (including parameter pollution explanation)
- The road to success in R & D efficiency of 1000 person Internet companies
- Talk about four cluster schemes of redis cache, and their advantages and disadvantages
- [statistical learning methods] learning notes - improvement methods
- SQL injection -- Audit of PHP source code (take SQL lab 1~15 as an example) (super detailed)
- Will the filing free server affect the ranking and weight of the website?
- Tutorial on the principle and application of database system (011) -- relational database
- xshell评估期已过怎么办
猜你喜欢
【PyTorch实战】图像描述——让神经网络看图讲故事
Processing strategy of message queue message loss and repeated message sending
How to use PS link layer and shortcut keys, and how to do PS layer link
OSPF exercise Report
leetcode刷题:二叉树26(二叉搜索树中的插入操作)
Cookie
SQL Lab (32~35) contains the principle understanding and precautions of wide byte injection (continuously updated later)
静态Vxlan 配置
Day-14 common APIs
如何将 @Transactional 事务注解运用到炉火纯青?
随机推荐
Solve server returns invalid timezone Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually
Routing strategy of multi-point republication [Huawei]
Processing strategy of message queue message loss and repeated message sending
Master公式。(用于计算递归的时间复杂度。)
Vxlan static centralized gateway
Aike AI frontier promotion (7.7)
Preorder, inorder and postorder traversal of binary tree
SQL Lab (46~53) (continuous update later) order by injection
[疑难杂症]pip运行突然出现ModuleNotFoundError: No module named ‘pip‘
Customize the web service configuration file
SQL lab 1~10 summary (subsequent continuous update)
PHP调用纯真IP数据库返回具体地址
ip2long之后有什么好处?
Dialogue with Wang Wenyu, co-founder of ppio: integrate edge computing resources and explore more audio and video service scenarios
Configure an encrypted web server
SQL lab 21~25 summary (subsequent continuous update) (including secondary injection explanation)
How much does it cost to develop a small program mall?
Sorting, dichotomy
【统计学习方法】学习笔记——逻辑斯谛回归和最大熵模型
opencv的四个函数