Architecture: Highly Scalable Web Architecture
2021-12-21
0. The Core Question
-
What is high scalability?
- The ability to scale a website's processing capacity up or down simply by changing the number of deployed servers
-
How is high scalability achieved?
- Physical separation of functions
- Clustering
- Application server clusters
- Data server clusters
1. Scalability Design
Scalability design of website architecture
-
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
- Vertical separation
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
Access model of a Memcached distributed cache cluster
- Application -> Memcached API
- Memcached API -> communication module -> Memcached servers
- Memcached API -> routing algorithm -> server list
-
Scalability challenges of a Memcached distributed cache cluster
- Capacity expansion
-
Consistent Hash algorithm for distributed caches
- Consistent Hash ring
4. Scalability Design for Data Storage Server Clusters
-
Scalability design for relational database clusters
- Master-slave read/write separation
- Database and table sharding
- Sharding
- Amoeba
- Cobar
-
Scalability design for NoSQL databases
- HBase
- Redis
5. Summary
- The design of a scalable architecture itself is simple
- Once coupled with availability, correctness, performance and other concerns, scalability becomes complex
- Take a holistic view of the team's knowledge base and structure, together with management's strategic vision and planning
6. Tips
- There are only problems you have not run into yet - none that cannot be solved
- Experts are experts because they have run into tough problems and solved them