During the interview, the interviewer directly asked, what is the distributed scenario used in the project? I feel that high concurrency and distribution are standard for interviews. To be honest, although 8 machines are used as clusters at the bottom of the project, there are not many business scenarios using distributed scenarios and the answer is not very good.
1. Personally speaking only in distributed terms, including distributed storage, distributed transactions, distributed locks, distributed locks have memcache, redis, DB and other implementations. In the future, if you encounter this kind of question, how can you answer it to the satisfaction of the interviewer? ?
(Personally, I feel that the interviewer wants to know: the understanding of the architecture design of the distributed problem and how to use it in the scene)
The summary answer is as follows:
I. Solution to session Sharing of java Clusters:
1. client cookie encryption. (Generally used in enterprise-level systems in intranet, cookie on user’s browser cannot be disabled. If disabled, the scheme will be invalid).
2. In the cluster, each application server provides the function of session replication, tomcat and jboss have implemented such a function. Features: Performance drops sharply with the increase of servers, which is easy to cause broadcast storms; Session data needs serialization, affecting performance.
3. Persistence of session, using database to save Session. Even if the server goes down, the session in the database still exists. Features: Every request session must read and write the database, which will bring performance overhead. Using in-memory database will improve performance, but data will be lost if it goes down (e.g. Alipay goes down, with disaster preparedness in the same city and disaster preparedness in different places).
4. Use shared storage to save the session. Similar to a database, even if it is down, there is no problem. In fact, it is to specially build a server, all landing on the session. Features: Frequent serialization and deserialization will affect performance.
5. use memcached to save the session. It is essentially a solution for memory databases. Features: The data stored in memcached need to be serialized, which is extremely inefficient.
Second, the distributed transaction solution:
1.TCC solution: try confirm cancel.
First, you need to understand why the system uses distributed.
With the development of the Internet, many performance bottlenecks of traditional single-project projects have become increasingly prominent. There are several performance bottlenecks.
I. Middle Tier: As the number of users increases and the number of concurrent requests increases, a single project cannot afford the performance bottleneck caused by such a large number of concurrent requests.
Second, the underlying database layer: with the development of business, the database pressure is increasing, resulting in performance bottlenecks.
In view of the above two points, I think we can solve them from two aspects.
There are several solutions for Middle Tier:
Application system cluster:
The simplest application system cluster is the server cluster, such as tomcat cluster. When applying system clusters, the prominent problem is session sharing, which can be solved by server plug-ins. The other can also be implemented through middleware such as redis.
Service-oriented splitting is currently a very hot way. Now everyone is talking about Microservices. Through the service splitting of traditional projects, the independent decoupling of services can be achieved, and single service can be expanded horizontally. The classic problem encountered in service splitting is the distributed transaction problem. At present, there are several commonly used distributed transaction solutions: message final consistency, TCC compensated transaction, and maximum possible inside notification. For details, please refer to this blogDistributed Transaction Solution
The underlying database layer:
If the performance pressure of the system appears in the database, then we can solve it with read/write splitting, sub-database and sub-table, etc. Since I have not had enough experience in this area, you can refer to other documents.
Mycat Database Sublibrary Subtable Middleware
MySQL High Availability read/write splitting Cluster