Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Distributed system actual combat

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Introduction: I remember that in the nearly five years of work since I graduated from college in 2006, due to my work experience and limited vision, I have almost no concept of "distributed system". Of course, the Internet / mobile Internet at that time had not yet overturned our lives, and many network applications could cope with traditional centralized services. However, with the surging tide of the Internet, there are more and more subdivided high-traffic websites and applications, and the number of netizens is getting bigger and bigger like a snowball. In this case, the concept of distribution is almost a household name in the technology circle. It has also become another era "silver bullet" that we chase. I am no exception, but just because I am in a second-tier city with almost no Internet atmosphere and a conservative and closed technological atmosphere, I can only learn and practice the distributed system step by step. But in turn, I have a lot of practical experience.

Just mentioned that one of the backgrounds of distributed systems is that there are many large-scale websites and applications.

The characteristics of these systems are: high concurrency, high traffic; high availability; massive data; wide distribution of users, complex network situation, poor security environment; rapid demand change, iterative development, and frequent release.

The core architectural elements of these systems: performance, availability, scalability, scalability, and security.

Let's take a look at the features of distributed systems:

Heterogeneity: enables users to access services and run applications on a large number of heterogeneous computers and networks, such as allowing diversity and differences in hardware, operating systems, programming languages, developers, etc.

Openness (extensibility): enables the system to be extended and implemented in different ways, such as by publishing key interfaces of the system, extending other applications based on consistent communication mechanisms and network protocols.

Scalability: it can still operate effectively and efficiently by adjusting resources under different user sizes, such as strengthening hardware through vertical scaling, increasing servers through horizontal scaling, and so on.

Concurrency: maintain the correctness of users' operations on shared resources, such as the C (consistency) requirements in CAP theory.

High availability: improve availability through performance optimization, security, fault handling, such as the use of high-performance programming models, secure isolation and filtering mechanisms, automated fault detection, fault tolerance, fault repair, redundancy, etc.

Advantages of distributed systems:

Reduce the cost of collaboration between different module development teams, and make the business response more quickly.

Greatly reduce the coupling between systems and the overall complexity, each development team can focus on their own business modules.

It avoids the impact of individual module errors on the whole.

The separable and scalable business liberates the dependence on single service resources.

To achieve targeted business capacity expansion, reduce unnecessary waste of resources.

It can be seen that the distributed system provides a good solution and support for large-scale website applications at the technical and organizational level.

Theories related to distributed systems:

CAP theory: a distributed system can only satisfy Consistency, Availability and partition fault tolerance at most (Partition tolerance means that when a distributed system encounters a node or network partition failure, it can still provide services satisfying consistency and availability).

BASE theory: refers to basic availability (Basically Avalilable), flexible state (Soft State), final consistency (Eventual Consistency). BASE is an extension of CAP theory. The core idea is that even if strong consistency can not be achieved, applications can achieve final consistency in a suitable way.

In addition, people often ask whether the concept of distributed architecture is better than what we often call SOA (service-oriented architecture) and the popular micro-service architecture. I personally think that it is unreasonable to ask the pros and cons. First of all, the concept of distributed architecture is embodied and applied in both. As for the contrast of SOA and micro-services, both of them can solve problems in the same way when they adapt to each other, which is a good architectural concept. But there are differences and connections:

The main features of SOA are:

Service-oriented distributed computing

Loose coupling between services

Support the assembly of services

Service registration and automatic discovery

Define service interaction in the form of a service contract

Typical features of the microservice architecture:

A system composed of distributed services

Divide the organization by business rather than technology

Make living products instead of projects

Intelligent Service Endpoint and stupid Service choreography

Automatic operation and maintenance

System fault tolerance

Rapid evolution of services

The above is mainly about the understanding of the concept of distributed systems, many of which are a summary of books and learning. However, to achieve real understanding, there must be actual combat. Take the background architecture of one of the live chat / user and device online systems coded by yourself as an example. This architecture idea has been practically applied to a number of million-level services. In fact, the distributed application of this architecture is not designed on the premise of being familiar with the distributed theory, but based on other conceptual models and evolved in the process of specific business practice and organizational cooperation.

For example, the hierarchical architecture design, because of mainly doing network security and network programming, the hierarchical design of the TCP/IP protocol stack has deeply affected itself.

Separate the network layer, the business logic layer and the data layer, the network layer supports load balancing, the business layer supports dynamic expansion, the data layer supports distributed storage, and each layer supports distributed deployment. The following is a detailed diagram of the architecture.

Separate the modules with different functions at the process level and communicate with TCP. This is influenced by the concept of "UNIX programming Art Chapter 7-Multiprogramming: separating processes as independent functions", whether it is very similar to the concept of micro-services, and the way based on TCP communication is conducive to distributed deployment. The most characteristic program modularization technique of Unix is to decompose large programs into multiple collaborative processes and focus on considering the interfaces and communication modes between these sub-processes.

The general technical module is separated from the business application module, such as gateway services, online services to achieve network access and protocol forwarding functions do not carry business logic, by the specific application process to deal with the business. Gateway service is similar to Nginx. Users' requests are first distributed to the back-end application cluster through the front-end access layer (Nginx). In addition, the main work of access layer flow restriction and security is realized through security filtering (such as domain name IP class, protocol key, blacklist) implemented on the gateway.

The stateless design separates the information of state, message and business data from the business process, and uses distributed cache (such as redis) and database (relational database MySQL, non-relational database MongoDB) storage to call. In this way, business processes are conducive to distributed deployment, and data services also support distributed storage.

Services use standard and unified protocols for information exchange, such as serialization protocols Json and RESTful API. I personally prefer text-based protocols, which are easy to understand and easier to record, analyze and debug. This is deeply influenced by the concept of "Chapter 5 of the Art of Unix programming-text: good protocols produce good practices". Compared with binary protocols, text-based protocols can bring interoperability, transparency and scalability.

Through configuration files or configuration service loading policies, many static and dynamic policies are not written in the program, but loaded through configuration files or configuration services. in this way, you can quickly deploy and release new features and hot start the service without interruption. This is also the practice of the principle of separation in the Art of Unix programming: separation of strategy from mechanism, separation of interface from engine.

Information and code:

"Gateway server" and "IM system architecture design" in server-side architecture

DSF (Distributed service framework): an example of a simple distributed service framework implemented in C++, including a logical distribution service implementation (gateway service) and a logical application implementation (specific application service)

HighPerformanceNetworkServer: high-performance TCP network server program (the prototype of online server)

Reference books:

The Art of Unix programming

"the way of Enterprise IT Architecture Transformation: Alibaba's Strategic thought and Architecture practice in China and Taiwan"

"Technical Architecture of large websites"

Distributed system concept and Design

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report