A Concise Guide to Architecture

A Concise Guide to Architecture

The Design Principles section is for your reference.

Architectural Principles

  • Avoid over-engineering : The simplest solutions are the easiest to implement and maintain, and avoid wasting resources. But the scheme needs to include extensions.
  • Redundancy design : Redundant nodes for services and databases to ensure high availability of services. It is realized through database master-slave mode and application cluster.
  • Multi-active data center : For disaster recovery, the high availability of applications is fundamentally guaranteed. It is necessary to build a multi-active data center to prevent the failure of a data center due to uncontrollable factors, causing the unavailability of the entire system.
  • Stateless design : The design of APIs, interfaces, etc. cannot have pre- and post-dependencies, and a resource is not affected by changes to other resources. Stateless systems scale better. If state is necessary, either the client manages the state, or the server manages the state with a distributed cache.
  • Rollback : For any business, especially critical business, there is a recovery mechanism. Rollback can be achieved using log-based WAL, event-based Event sourcing, etc.
  • Can be disabled/self-protected : It has a current limiting mechanism, which can reject overflow requests when the upstream traffic exceeds its own load capacity. Traffic can be blocked at the front of the application by manual switching or automatic switching (to monitor abnormal traffic behavior).
  • Problem traceability : When there is a problem with the system, it can locate the trajectory of the request, the request information of each step, etc. The distributed link tracking system solves this problem.
  • Monitorable : Monitorability is the key to ensuring the stable operation of the system. Including monitoring of business logic, monitoring of application processes, and monitoring of system resources such as CPU and hard disk that applications depend on. Every system needs to do a good job of monitoring at these levels.
  • Fault isolation : Isolating system-dependent resources (threads, CPUs) and services so that the failure of one service will not affect the invocation of other services. Faults can be isolated through thread pools or distributed deployment nodes.
  • Mature and controllable technology selection : Use mainstream, mature, documented, and supported technologies on the market, and choose the appropriate rather than the hottest technology to implement the system.
  • Cascade storage : memory -> SSD hard disk -> traditional hard disk -> tape, data can be stored hierarchically according to its importance and life cycle.
  • Cache design : Isolate requests from back-end logic and storage, which is a mechanism for the principle of proximity. Including client cache (pre-delivered resources), Nginx cache, local cache and distributed cache.
  • Asynchronous design : For interfaces where the caller does not pay attention to the result or allows delayed return of the result, using a queue for asynchronous response can greatly improve system performance; when calling other services, it returns directly without waiting for the server to return the result, which can also improve the system. Responsive performance. Asynchronous queues are also a common means of solving distributed transactions.
  • Forward- looking design : According to industry experience and prediction, design scalability and backward compatibility in advance.
  • Horizontal expansion : Compared with vertical expansion, the ability to solve problems through heap machines is the highest priority, and the load capacity of the system can be close to infinite expansion. In addition, cloud-based computing technology can automatically adjust the capacity according to the system's load, which can save costs while ensuring the availability of services.
  • Build and Release in Small Steps : Quickly iterate on projects, with quick trial and error. There can be no project planning that spans too long.
  • Automation : The automation of packaging and testing is called continuous integration, and the automation of deployment is called continuous deployment. The automation mechanism is the basic guarantee of rapid iteration and trial and error.

The six-step approach to architecture

The author's understanding of the six-step thinking method of architecture proposed by Xia Huaxia, chief architect of Meituan, once shared.

Data Design Principles

  • Pay attention to storage efficiency
    • reduce transactions
    • Reduce join table queries
    • Use indexes appropriately
    • Consider using a cache
  • Avoid relying on database computing functions (functions, memory, triggers, etc.), and place the load on the business application side that is easier to expand
  • In the data statistics scenario, Redis can be used for data statistics with high real-time requirements; non-real-time data can use a separate table, and update data through queue asynchronous operations or timing calculations. In addition, for statistical data with high consistency requirements, it is necessary to rely on transactions or timing proofreading mechanisms to ensure accuracy.

Five ways to improve system response performance

  • Asynchronous : Queue buffering, asynchronous requests.
  • Concurrency : Use multiple CPUs and multiple threads to execute business logic.
  • Proximity principle : cache, gradient storage.
  • Reduce IO : Merge fine-grained interfaces into coarse-grained interfaces, and frequent coverage operations can only do the last operation. Here is a point that needs special attention:  try to avoid calling external services in the loop in the code. It is better to use the coarse-grained batch interface to make only one request outside the loop.
  • Partitioning : Frequently accessed datasets are kept to a reasonable size.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325009382&siteId=291194637