Any micro service capacity is limited, but ideally should be generally limited to the number of micro-services (computing) servers, storage capacity and bandwidth of the network.
When a user requests and increase the amount, there is no problem as long as the budget is theoretically accessible indefinitely extended.
In fact, this assumption often does not hold a larger amount of data, more requests, higher concurrency, your service will barely.
You would have thought to add memory, plus storage, plus the bandwidth, server plus, but things were not so easy, your application must be able to service capabilities with the increase linearly with increasing resources
As the stand-alone memory, CPU and bandwidth is limited, so try your service designed for use by several independent, autonomous node stateless composition, so that you can easily add nodes to respond to the growing service requests
the term
- Scale up: scaling up or vertical expansion
- Scale out: horizontally extended outward or expanded
- Failover: Fast switching of the switching from the primary node to the slave node or partition or partition to reduce the impact on the user
- Stateless: Stateless, the server node itself does not store state, the benefits that can increase and decrease node at any time, in favor of horizontal expansion
- Stateful: Stateful, the state is always there, to see where you put it on, server memory, database, or shared cache server
- Sharding: The distribution of data and use the data set in the plurality of distributed databases up memory, processing power and to avoid single storage limit
Points
Service Separation Separation of services
From self-sufficient peasant society into a modern social division of labor, a single person to master the skills of fewer, different people have different division of labor and expertise, production efficiency greatly improved social
Micro service is to take a small service, so refined, focused on a relatively independent areas, in order to facilitate risk diversification, and re-combination, but also conducive to expansion of services and which one is the bottleneck, on which an optimization and expansion, rather than All servers must be upgraded together.
For example, I do a web conferencing servers, need to support text chat, audio and video conversations, desktop sharing, file sharing, remote control, conference recording, both control processing signaling, another transmission, encoding and decoding, and mixed media tone, if all put together, you can imagine the complexity of the system greatly increases do not say, hard to do tuning and expansion, audio and video codec is extremely time consuming CPU resources, allowing packet loss, and the control and text chat is different, the message must ensure reliable communication, so it is each separately for various services as well
Stateless Stateless
The state is always there, the key to see where you put it on, memory, files, data table, or cache?
If we put the state on a single server or memory file system, it will be very troublesome expansion high reliability is also a problem.
The state needs to be synchronized between different servers, can we avoid single point of failure, each server is consistent and clearly can not cope with massive data request.
- There are single-independence state
- Multiple synchronization status
- External shared state
Only the third, your server can be increased at the linear expansion
Data sharding data pieces
According to geographical location, user or organization Cluster data center and service area can be fragmented data, assuming you have more customers, who are located in different regions, different customer service requests and data size is different, how the data points piece of it?
Suppose you offer online education platform, the domain name is every day www.day-day-up.com , customers are large and small, each tutorial, as well as some online educational institutions.
You can slice the data for different customers (tenants tenant)
- East tutorial schools https://east-school.day-day-up.com , the school is relatively large, there are two big campuses:
- Greater China
- Southeast Asia
- Western tutorial schools https://west-school.day-day-up.com , the school is relatively small, there is only one main campus
Thus, we have the following configuration data table, in a central database and cache the Redis
- Tenant table
tenant_id | tenant_name | expire_date |
---|---|---|
d423b7f7-aa2f-40ee-afe7-6b4e5a245ff3 | East tutorial schools | 2018-12-31 |
c5ae1066-522b-4cf3-aba7-923f72f7f07d | Western tutorial schools | 2018-12-31 |
- Org Table
org_id | org_name | tenant_id |
---|---|---|
b30bae13-75ca-4b3c-8998-2d46ba6f74ff | Greater China | d423b7f7-aa2f-40ee-afe7-6b4e5a245ff3 |
c3cd2f82-dde6-481d-b441-d7e4e50e3eb6 | Southeast Asia | d423b7f7-aa2f-40ee-afe7-6b4e5a245ff3 |
b18dde72-de20-4952-b33c-73da44ebe95a | Main Campus | c5ae1066-522b-4cf3-aba7-923f72f7f07d |
- Sharding 表
tenant_id | org_id | database_pool_id |
---|---|---|
d423b7f7-aa2f-40ee-afe7-6b4e5a245ff3 | b30bae13-75ca-4b3c-8998-2d46ba6f74ff | ajpc_a1 |
d423b7f7-aa2f-40ee-afe7-6b4e5a245ff3 | c3cd2f82-dde6-481d-b441-d7e4e50e3eb6 | us_a1 |
d423b7f7-aa2f-40ee-afe7-6b4e5a245ff3 | b30bae13-75ca-4b3c-8998-2d46ba6f74ff | ajpc_b1 |
- DbPool table
db_pool_id | primary_db_pool | backup_db_pool |
---|---|---|
ajpc_a1 | mysql://username:password@hosta1/mysqldb_name | mysql://username:password@hosta2/mysqldb_name |
ajpc_b1 | mysql://username:password@hostb1/mysqldb_name | mysql://username:password@hostb2/mysqldb_name |
us_a1 | mysql://username:password@hosta1_us/mysqldb_name | mysql://username:password@hosta1_us/mysqldb_name |
Tips - quickly generate UUID
python -c 'import uuid; print uuid.uuid4();'
How to automatically expand and contract
basic requirements:
- The peak of adding servers, fast service
- Trough reduce server resource efficiency
- The server is triggered by changes in the monitoring and analysis program
Following the traditional structure is clearly not enough
According to the results of the decision Monitor and Metrics system, the results in real time to increase the server registered to similar Consul service discovery system, the use of its service discovery and health checks, with consul-template to refresh change HAProxy, Nginx such software load balancing system configuration file and reload (F5, NetScalar such hardware load the same way), to reduce server is the same process.
as the picture shows
Of course, your best servers are stateless, otherwise very troublesome, it may be done state synchronization when adding servers, the first server to suspend the state shut down the server, no longer accept new services, until all services in this server has ended, to shut down
Reference material
- Cloud Architecture Patterns for Mere Mortals by Bill Wilder
- Web Scalability for startup engineers
- https://cloud.google.com/solutions/autoscaled-load-balancing-using-haproxy-and-consul-on-compute-engine
Author: Walter Fan
link: https: //www.jianshu.com/p/3a7d9d34126f
Source: Jane book
Jane book copyright reserved by the authors, are reproduced in any form, please contact the author to obtain authorization and indicate the source.