Architecture: Highly Scalable Web Architecture

2021-12-21

0. The Core Question

  1. What is high scalability?

    • The ability to scale a website's processing capacity up or down simply by changing the number of deployed servers
  2. How is high scalability achieved?

    • Physical separation of functions
    • Clustering
      • Application server clusters
      • Data server clusters

1. Scalability Design


Scalability design of website architecture

  1. Scaling by physically separating different functions

    • Vertical separation
      • Deploy different parts of the business processing pipeline separately to make the system scalable
    • Horizontal separation
      • Deploy different business modules separately to make the system scalable
  2. Scaling a single function by adjusting cluster size

    • Application server clusters
    • Data server clusters
      • Cache data server clusters
      • Storage data server clusters

2. Scalability Design for Server Clusters

  1. HTTP redirect load balancing

    • Uses the HTTP redirect protocol to achieve load balancing
    • Advantages
      • Simple
    • Disadvantages
      • The browser must request the server twice to complete a single visit
      • The redirect server may become a bottleneck
      • Redirects may be judged by search engines as SEO cheating
  2. DNS resolution load balancing

    • DNS resolution requests return a different IP address computed by the load-balancing algorithm
    • Advantages
      • Saves the website from having to operate and maintain its own load-balancing servers
      • Can resolve the domain name to the server geographically closest to the user
    • Disadvantages
      • Because of multi-level DNS caching, changes take a long time to take effect
      • Control of DNS load balancing sits with the domain name service, leaving the website little room for improvement
  3. Reverse proxy load balancing

    • Forwards requests at the HTTP protocol level - application-layer load balancing
    • Advantages
      • Simple to deploy
    • Disadvantages
      • Performance may become a bottleneck
  4. IP load balancing

    • Achieves load balancing at the network layer by rewriting the destination address
    • Advantages
      • IP load balancing distributes data in the kernel process, delivering better processing performance than reverse proxy load balancing
    • Disadvantages
      • The cluster's maximum response data throughput is limited by the network interface bandwidth of the load-balancing server
  5. Data link layer load balancing

    • Triangle transmission mode
    • During data distribution, the load balancer does not modify IP addresses, only the destination MAC address
    • The most widely used load balancing method today
  6. Load balancing algorithms

    • Round Robin
    • Weighted Round Robin
    • Random
    • Least Connections
    • Source Address Hashing
      • Hashes the IP to select an application server, ensuring requests from the same source are always handled by the same server

3. Scalability Design for Distributed Cache Clusters

  1. Access model of a Memcached distributed cache cluster

    • Application -> Memcached API
    • Memcached API -> communication module -> Memcached servers
    • Memcached API -> routing algorithm -> server list
  2. Scalability challenges of a Memcached distributed cache cluster

    • Capacity expansion
  3. Consistent Hash algorithm for distributed caches

    • Consistent Hash ring

4. Scalability Design for Data Storage Server Clusters

  1. Scalability design for relational database clusters

    • Master-slave read/write separation
    • Database and table sharding
    • Sharding
      • Amoeba
      • Cobar
  2. Scalability design for NoSQL databases

    • HBase
    • Redis

5. Summary

  1. The design of a scalable architecture itself is simple
  2. Once coupled with availability, correctness, performance and other concerns, scalability becomes complex
  3. Take a holistic view of the team's knowledge base and structure, together with management's strategic vision and planning

6. Tips

  1. There are only problems you have not run into yet - none that cannot be solved
  2. Experts are experts because they have run into tough problems and solved them