The evolution of the Internet architecture
- All in One Architecture
-
- The solution
- Problems that may occur during cluster operations
-
-
- High availability
- High concurrency
- A high performance
-
- Cluster operations
-
- High concurrency in cluster operations leads to increased database stress
-
-
- Reading and writing separation
- Use search engine to relieve database access pressure and improve database capability
- Caching mechanism is introduced to reduce the pressure of database access
- Horizontal/vertical split of the database
-
- Features of Cluster Status
- Horizontal layered architecture
- Distributed Service Architecture
- Service-oriented Architecture (SOA)
- Microservices Architecture
-
- SpringBoot
- Advantages of microservices
- Disadvantages of microservices
- The cloud service
- Service Mesh
All in One Architecture
- All modules are together and the technology is not layered.
- Deploy all applications and software on a single machine.
- All the code is written in JSP, all the code is written together, this method is called all in One. Features: 1. No maintainability of the code. 2. Poor fault tolerance. (fault tolerance refers to software testing application runs the error in software and hardware and the ability to recover from errors, can from the system’s reliability, availability, scalability and so on several aspects to measure), because all the code written in JSP pages, when abnormity because users or some reason: the user can directly see exception error information; An exception may cause the server to break down.
- Monomer Hell: Just one application, deploying all functions together to reduce deployment nodes and costs.
The solution
1. Layered development: Solve the problem of poor fault tolerance of single architecture, while improving the maintainability of the code. MVC architecture (design pattern for Web applications) 3. Deployment separation of servers. Features: 1.MVC layered development: to solve the fault tolerance problem. 2. Separate database and project deployment. Problems: 1. High concurrency: As the number of user visits continues to increase, a single server cannot meet user access requirements. Solution: 1. Cluster
Problems that may occur during cluster operations
High availability
- High Availability (HA) is one of the factors that must be considered in the architecture design of distributed systems. It usually refers to the design to reduce the time when the system cannot provide services. Assuming that the system is always able to provide services, we say that the system is 100% available.
- How to ensure high availability: Avoid single points.
High concurrency
- High Concurrency is one of the most important things to consider when designing an Internet distributed system architecture. It usually refers to the idea of designing a system that can handle many requests in parallel.
- Some common indicators related to high concurrency
- Response Time: Time when the system responds to a request.
- Throughput: Number of requests processed per unit of time.
- Query Per Second (QPS) : the number of response requests Per Second.
- Number of concurrent users: specifies the number of concurrent users who use system functions. Improve the concurrent capability of the system. 1. Vertical expansion: Improve the processing capability of a single machine.
- Enhance the hardware performance of single machine
- Improve single-node architecture performance. 2. Horizontal scaling
- By increasing the number of servers, you can linearly expand system performance.
A high performance
Cluster operations
- Cluster: The same service is deployed on multiple servers. Features:
- The project is deployed on multiple servers (cluster). Advantages: 1. High concurrency 2. High availability question 1: How can session data be shared?
- Question 2: How do users forward requests to servers in these clusters? – Nginx server to complete the distribution of requests, load balancing policy mechanism.
High concurrency in cluster operations leads to increased database stress
- Cluster solution nginx+ Tomcat will effectively improve the performance of the application layer, but the database load pressure slowly increases, how to improve the database load solution:
Reading and writing separation
- Read/write separation: Data is synchronized between the primary and secondary databases. Master (write) adds, deletes, and modifies the database, while slave (read) queries the database.
- MySQL provides the master-slave replication function.
Use search engine to relieve database access pressure and improve database capability
- When the database reads the query operation, the database itself does not support the fuzzy query function very well. For example, e-commerce websites, search function is a very core functional module, even if the separation of reading and writing, can not solve the e-commerce website query (word segmentation technology), for such a problem, the introduction of search engine technology as a solution.
- Current mainstream search engine technology: 1. Solr 2. Elasticsearch 3.
Caching mechanism is introduced to reduce the pressure of database access
- As the number of visits continues to increase, even with master-slave replication, the pressure on database access continues to increase. Users need to access hotspot data frequently. If you need to query hotspot data in the database every time, which includes many general query functions, data in the database should not be stored in the memory. For example, mobile phone login verification code operation, to restrict the frequent access to the server for IP.
- Use Redis to implement the caching mechanism.
Horizontal/vertical split of the database
- Servers have limited vertical scaling capabilities.
- Table: Vertical split 1. Separate database table fields into new tables. 2. Separate hot/cold data into a new table.
- Table: Horizontal split 1. Separate database table data into new tables. 2. Divide horizontal data into new tables according to time, region and business logic.
- 1. Use third-party database middleware
- mycat
- sharding-jdbc
- DRDS (Ali)
Features of Cluster Status
- Through cluster design, continuous expansion of servers can ensure high availability and high concurrency.
- Problems: 1. High server costs, including server maintenance costs and manual maintenance costs. 2. Poor application maintainability. 3. Poor application scalability and low component reuse. 4. Collaborative development is difficult, and the same business code will be modified, which is easy to cause code conflicts and errors. 5. Single architecture: With the continuous increase of services, more and more code is generated, resulting in larger files during service deployment.
Horizontal layered architecture
-
When the volume of traffic gradually increases, the acceleration caused by the increase of a single application becomes smaller and smaller. The application is divided into several unrelated applications to improve efficiency. MVC, a Web framework for accelerating front-end page development, is key here. \
-
Horizontal split:
- The system is divided according to business: for example, the original system includes two categories of transaction and operation, which are split according to the principle of horizontal split. The system can be divided into: trading system, operation system
- Advantages: Different services often have different performance requirements and requests. After the split, ensure that the impact of availability between services is minimized
- Disadvantages: There may be duplicate wheels in multiple systems during the splitting process, which is difficult to maintain
-
After the split, the split project is aggregated and the conceptual parent project is proposed. The IDEA of the sample
-
In pom. XML: Dependencies – dependencyManagement- dependencyManagement
-
Use Maven to split and aggregate modules
-
Solve the following problems: 1. Module reuse 2. A large number of idle servers can be used to deploy services of a layer on multiple servers when the user accesses a layer too much. Use idle servers as other services, such as cloud server, Ali Cloud, Baidu Cloud and so on; \
-
Vertical split: The split apPlets are independent of each other
- The same system is split according to the application scenario (caller) : for example, the payment module of a transaction system has two call processes upstream: user payment and merchant payment. The payment module can be split into user payment and merchant payment according to the rule of vertical split
- Advantages: On-demand allocation (estimate the traffic of the caller, configure the number of corresponding machines). Each vertical call does not affect each other, and upstream call degradation can be carried out through configuration
- Cons: Almost identical wheels
-
Features: 1. Strong maintainability: If you want to change requirements, you only need to adjust a certain application. 2. Good scalability: As services increase, you only need to create new application modules. 3. Collaborative development is convenient: different teams modify different businesses. 4. Flexible deployment content and good performance expansion: Deploy multiple servers only for modules with heavy traffic. Problems: 1. The front-end page changes greatly: When users have higher requirements on the page, the page needs to be modified frequently. Because all layers of each application are complete, application services need to be redeployed to modify the page. 2. Service interaction between modules is difficult: As the number of application modules increases, service interaction between modules becomes difficult.
Distributed Service Architecture
- Distributed: A service is divided into multiple sub-services and deployed on different servers.
- Distributed service architecture: With the increasing number of layered applications, interactions between applications are inevitable. Core businesses are extracted as independent services to gradually form a stable service center, enabling front-end applications to respond to changing market demands more quickly. At this point RPC, a distributed service framework for improving service reuse and integration, is the key.
- Solution: 1. The front-end page changes greatly: When users have high requirements on the page, the page needs to be modified frequently. Because all layers of an application are complete, application services need to be redeployed to modify the page. Distributed solution: interface and business logic implementation separation, that is, front and back end separate development, horizontal split. 2. Service interaction between modules is difficult: As the number of application modules increases, service interaction between modules becomes difficult. Problem analysis: on a server, each module can be called through dependency (process); When different applications are deployed on different servers, calls are made between services. Distributed solutions:
- Remote Procedure Call (RPC) : Remote Procedure Call (RPC) is a protocol for requesting services from Remote computer programs over a network without knowledge of the underlying network technology.
- HTTP
- Distributed technology problems: 1. Distributed transaction problem 2. Distributed lock problem 3. Distributed Session problem 4. Distributed log management problem
- Problems: 1. As there are more and more services, the invocation between services will become extremely chaotic 2. As more and more services, capacity assessment, small service resource waste and other problems gradually emerged
Service-oriented Architecture (SOA)
-
As the number of services increases, problems such as capacity evaluation and resource waste of small services gradually emerge. In this case, a scheduling center needs to be added to manage cluster capacity in real time based on access pressure to improve cluster utilization. At this point, SOA, the resource scheduling and governance center for improving machine utilization, is key.
-
Service management Middleware:
- Dubbo
- SpringCloud
-
Manage cluster capacity in real time based on access pressure to improve cluster utilization.
-
SOA architecture features:
- The underlying implementation is based on SOAP or ESB message bus
- The bottom layer uses HTTP protocol + heavyweight data exchange format for communication
Microservices Architecture
-
Microservices: Individual applications are divided into discrete small applications, each of which is called a microservice
-
Microservices embody a more lightweight architecture
- RESTful API:Http + JSON format
- More suitable for agile development, rapid iteration of products
- Services can communicate with each other through RPC remote calls
-
Microservices architecture evolved from SOA architecture
- Servitization is already implemented at the SOA layer
- Micro services are subdivided in a separate service layer
-
Question: 1. What is the difference between microservices architecture and SOA architecture?
- Microservices architecture evolved from SOA architecture, inheriting the benefits of SOA architecture. Microservices remove the ESB message bus from SOA architecture and use HTTP + JSON (RESTful) lightweight data communication - microservices architecture is more granular than SOA architecture to improve efficiency. Each service is independent of each other. In microservice architectures, each service must be deployed independently. Microservice architectures are lighter and lighter - in SOA architectures, databases may be shared. Microservice architecture emphasizes that each service is a separate database, ensuring that each service is not affected by each other - microservice projects are more granular and more suitable for agile, rapid iteration than SOA architectureCopy the code
2. When building a single application, you need to configure the SSM project web. XML, all jar packages, and configuration files. Therefore, a large number of service projects need to be created when splitting and building microservices. Solution: SpringBoot.
SpringBoot
- SpringBoot: A framework to simplify Spring development. Used to monitor Spring application development, convention over configuration, simplify complexity, fast application development.
- Purpose: To simplify code initialization and development configuration.
Advantages of microservices
- The separation granularity of servitization becomes finer and the service reusability is strong. Improve development efficiency.
- Customize the optimization scheme according to the requirements and select the latest technology for the development and modification of the micro-service module.
- Suitable for Internet projects, high development efficiency, short iteration cycle.
Disadvantages of microservices
- There are too many micro services, and the management cost of services is high.
- This is not conducive to service deployment. The deployment is inconvenient and costly. Docker (image/container), K8S
- Technical difficulties increased, such as distributed transactions, distributed locks, distributed sessions, and distributed log management
- High technical requirements for the team, Dubbo, SpringCloud
The cloud service
- IaaS: Infrastructure as a Service. Consumers can obtain services from a sophisticated computer infrastructure over the Internet. Such services are called infrastructure as a service. Internet-based services, such as storage and databases, are part of IaaS.
- PaaS: Platform as a Service. The corresponding server platform or development environment in the era of cloud computing is provided as a service.
- SaaS: software-as-a-service, which provides Software services over the network.
Service Mesh
- As the infrastructure layer of communication between services, service grid can be likened to TCP/IP between applications or micro-services, responsible for network calls, fuses, traffic limiting and monitoring between services.
- With the service grid, we don’t have to worry about things between services that are typically implemented by applications or other frameworks:
- An intermediate layer of communication between applications.
- Lightweight network proxy.
- The application is not aware.
- Decouple application retry/timeout, monitoring, tracing, and service discovery.