19-02 Evolution of architecture technology selection based on service level

From Scratch - Single Service Application

Single application technology selection

  • (GitHub, Gitee...) Search for products with threads
  • Use the most familiar technology and go online at the fastest speed
  • If you have the money: consider a commercial solution

How to choose a personal small program technology

  • Search for software to quickly build programs
  • Technology Selection
    • Back-end technology selection
      • Use the most familiar technology to achieve the fastest development speed
      • MySQL、MyBatis、SoringBoot
    • Front-end technology selection
      • insert image description here

Separation of application services and data services

  • The start-up stage of enterprise application
  • two purposes
    • Choose the right technology to implement the project
    • Set the tone for the future direction of the project
    • insert image description here

issues to consider

  • Choice of operating platform
  • Choosing a Commercial or Open Source Solution
  • Determine the R&D model of the project
  • Determine the specific technology used

Get twice the result with half the effort - introduce the cache system

issues to consider

  • where to use the cache
  • What type of cache to use
  • adopt that caching mode
  • What cache component to use

cache location

  • client cache
    • cache in browser
    • app cache
  • caching in the network
    • proxy server cache
    • CDN cache
  • server cache

How to determine where the cache is located

  • If there is no performance bottleneck, don’t consider it, if it is slow, use the cache there

cache type

  • memory cache
    • Very fast, data may be lost
    • Applicable to scenarios with very high speed requirements and data loss tolerance
    • heap cache
      • advantage:
        • No need for serialization, deserialization
        • good performance
      • shortcoming:
        • Will affect GC
        • Capacity is limited by the size of the heap memory
        • Generally stored as soft references or weak references
      • Applicable scenarios for in-heap caching
        • Store very hot data
  • disk cache
    • Performance is worse than memory cache, data will not be lost
    • Applicable to scenarios that require persistence

load balancing

insert image description here

DNS-based load balancing

  • Configure the same resolution record for multiple addresses on the DNS server
  • advantage:
    • The work of load balancing is handed over to the DNS server, reducing the maintenance work of website management
    • The technical implementation is relatively flexible, convenient, simple and easy to implement, and the cost is low
    • Wide range of applications, suitable for most TCP/IP applications
  • shortcoming:
    • Generally does not reflect the current running status of the server
    • After a server goes offline, even if the DNS record is modified, it may take a long time for the record to take effect
    • Ensure that the target address pointed to by DNS resolution is highly available, and the address will not be changed frequently
    • Generally speaking, large websites will use DNS as a first-level load balancing
      • The IP pointed to by DNS does not correspond to a machine, but a highly available server cluster
      • The dig command can query records

Load balancing based on reverse proxy

  • The request passes through the reverse proxy, and the load balancing algorithm is provided by the reverse proxy component, and a server address is calculated and returned
  • represent realization
    • NGINX
    • HAProxy
    • Apache

Typical process of Internet project load balancer evolution (experience)

  • Early project: NGINX
  • Mid-term: High availability of NGINX combined with Keepalived
  • After that, install LVS or F5 to expand multiple NGINX
  • If an LVS cluster is too hungry, it will be combined with DNS to expand LVS

Stateful vs Stateless

  • Status: Whether the server should store the user's login status
  • Whether the server should maintain the user's session

Stateful

sticky session

  • After the client logs in on a Web Server, subsequent requests will be bound to the Web Server instance
  • insert image description here
  • Advantages and disadvantages
    • No need to introduce additional components
    • easy to implement
    • There is a single point of problem: additional failover is required
    • There may be an imbalance

session sharing

insert image description here

  • Use session to keep the session, and store multiple application instances in a central storage
  • Advantages and disadvantages
    • Additional components need to be introduced, even if any web application crashes, it can still be used
    • But once the Session Store crashes, all sessions will be lost

session replication

insert image description here

  • Replicate sessions between Web Server instances
  • Advantages and disadvantages
    • No need for failover
    • No need to introduce additional components
    • Session replication consumes bandwidth and memory

no status

  • The server does not record the user's login status: the server no longer maintains the session
  • When the user logs in, a token is provided, which is usually encrypted
  • After that, each request will bring this token (passed in header, URL parameter, and cookie)
  • Stateful Cons = Stateless Pros
  • Disadvantages of statelessness:
    • Once the token is issued to the user, it is difficult to control its offline time
      insert image description here

Stateful vs Stateless

insert image description here

read-write separation

insert image description here

CDN

  • Static files: works really well
  • Dynamic data: not working well
  • dynamic content static
  • static and dynamic separation

Principles of CDN composition

insert image description here

Issues to be considered in CDN technology selection

  • self built or commercial
    • Prioritize the use of commercial CDN
    • When the commercial CDN can't meet the business needs and can't stand it, then consider self-built
    • Reason: Self-built is not cost-effective
    • Xiaomi, Kuaishou, Dianping => are all commercial CDNs
  • How to choose a CDN
    • speed
      • Number of nodes
      • bandwidth capacity
      • node distribution
    • Function
      • speed up optimization

        • DNS optimization
        • insert image description here
      • monitoring statistics

        • Real-time monitoring: click rate, hit rate, occupied traffic
        • Access log monitoring
      • safety

        • Anti-leech
        • IP black and white list
    • price
      • Billing by bandwidth peak
      • Pay by traffic

Full Text Search

  • Reduced query pressure on the database
  • Improve application performance and improve user experience
  • Five Paths to Realize Full-text Search
    • Use the database's built-in full-text search capabilities
    • Full-text search using deep database integration
    • Use an open source full-text search engine
    • Use commercial full-text search engines
    • Self-developed full-text search engine

Use the database's built-in full-text search capabilities

insert image description here

  • advantage
    • low learning cost
    • convenient
    • Maintains architectural simplicity without introducing new components
  • shortcoming
    • The search engine is not separated from the database, and the responsibility of the database is not single enough
    • The ability of full-text search is limited by the query ability of the database
  • Not recommended for use

Full-text search using deep database integration

  • Representative implementation: Sphinx
    • can run independently
    • Can be deeply integrated with MySQL and PostgreSQL
  • Selection suggestion
    • Sphinx is very popular in the industry
    • If you are interested in the cost of operation and maintenance and do not have high requirements for scalability, you can try
  • Tips
    • Compared with other full-text search engines, Sphinx is not very powerful
    • There are not many domestic documents
    • More and more enterprises are migrating from Sphinx to the third mode

Use an open source full-text search engine

  • Currently the most mainstream way
    • rich choice
    • Very good scalability
  • shortcoming
    • Requires independent deployment of search engines
    • Need to use the search engine specific syntax to operate the search engine
      • Both disadvantages and advantages, the disadvantage is that there is a learning cost, the advantage is that it can support more complex queries; in addition, search engines such as Elasticsearch support both DSL and SQL
    • Search engine and database are two independent software, data consistency needs to be considered
      • Synchronize with plugins like logstash-input-jdbc
      • When the application writes to the database, it also writes to the search engine
  • Selection suggestion: you can use it with confidence

Use commercial full-text search engines

  • Alibaba Cloud Open Search
  • Microsoft Azure Search
  • Not many success stories
  • Selection suggestion
    • Commercial products have good service, save trouble and worry, and can be used with confidence
    • Consider the impact of closedness of commercial products: For example, it is difficult for manufacturers to customize according to your special needs

Self-developed full-text search engine

  • Ali, Suning, Wind Information, Oriental Fortune
  • Advantages: The core technology is in your own hands, with better flexibility, and you can adjust and optimize from the bottom when encountering problems
  • Disadvantages: The technical requirements of the team will be relatively high, and the cost will be very high

insert image description here

Guess you like

Origin blog.csdn.net/m0_56709616/article/details/130842663