[] -Java face questions distributed micro and services face questions Summary

table of Contents

1.CAP theory

2.BASE theory

3. idempotency interface problems

4. How messaging middleware to solve the problem of lost messages

5. What is the distributed transaction? What type of distributed transactions?

Solution 6 distributed transaction What?

7.Dubbo how to handle the service request failed

10.Soa and micro Services Architecture What are the differences?

11.dubbo service providers, service consumers what information needs to be configured?

What 12.Dubbo load balancing strategy

Persistence way 13.Redis of what? What are the pros and cons of each?

14.aof file is too large how to deal with?

15. talk about the affairs of redis

16. What is Cache avalanche

17. How to avoid cache avalanche

18. The cache penetration is what? How to avoid?

19.zookeeper principle

What scenarios 20.zookeeper

21.zookeeper node types What? What is the difference?

22. zookeeper talk about the election mechanism

Why 23.zookeeper number of nodes can only be an odd number?

24. How to ensure high availability message queue

25. How to ensure that messages are not repeated (issues such as power) consumption

26. How to ensure the consumer ordering of messages? 

27. How to solve the delay of a message queue and expire problem?

28. The message queue is full of how to deal with? When the message is how to deal with excessive backlog?


1.CAP theory

Any distributed system can not meet the consistency (consistency), availability (availibity), partition fault tolerance (partition tolerance) of the three, at most only two of them can meet.

Jingdong seen a face questions:

Please talk with zookeeper registry and do make the difference Eureka registry at.

CAP can be carried out from the perspective of analysis, zk do registry is to meet the CP, spring cloud is to meet the AP, concrete can expand elaborate.

2.BASE theory

BASE is Basically Available (basic available) Soft state (soft state) Eventually consistent (eventual consistency) abbreviation of these words,

CAP is the theory evolved, the core idea is: even if unable to do so strong consistency, but each application according to their own characteristics, to take appropriate way to make the system achieve eventual consistency.

3. idempotency interface problems

Idempotent operation repeating means, idempotency interface is the interface is called repeatedly, in the case where the front end is not limiting, the same interface call may be repeated several times, in order to avoid similar problems repeat orders, by the following are several ways to solve power problems such as:

Globally unique ID, generated according to business operations and contents of the global unique ID, and then before proceeding to determining whether the ID already exists, if the ID does not exist for persistent (or redis exist in the database), if it already exists prove that the interface has been invoked before. for example, when you can produce a single serial number to uniquely identify the order.

You can use select + insert to be judged, because the general order of ID is a unique index is not recommended at high concurrency scenarios.

You can use optimistic locking solve, in the table can add a version field.

token mechanism, the token is placed in redis.

4. How messaging middleware to solve the problem of lost messages

May be sent in a message the sender id Here, the receiver receives the message in the DB, and then store the ID may be determined by determining the presence of the ID DB whether the message is successfully transmitted.

Of course, now messaging middleware are more powerful, and has been considered the perfect piece of content, so you can direct messaging middleware provided by means of the process to resolve.

For example rabbitMQ, provides transaction mechanism, you can commit the transaction before the message is sent, if the transmission fails automatically rolls back.

// 开启事务
channel.txSelect
try {
    // 这里发送消息
} catch (Exception e) {
    channel.txRollback

    // 这里再次重发这条消息
}

// 提交事务
channel.txCommit

But that would be more consumption of performance, it is more recommended practice is to confirm the use of the mechanism provided rabbitmq .confirm mechanism is asynchronous, after the consumer receives the message sent by the producer calls back ack, if the consumer fails to receive calls back nack Interface .

To truly foolproof, we need not only to Message for persistence, but also the need for Exchange, Queue also persistent, and rabbitMQ provides these persistence mechanisms, so use a good messaging middleware can be very good solve the problem of message loss.

Except, of course rabbitMQ, kafka also has a corresponding solution will not elaborate (mostly not).

5. What is the distributed transaction? What type of distributed transactions?

Transaction involves multiple databases distributed transaction operation is the aim to ensure data consistency in a distributed system.

Distributed Transaction type:

Two-phase commit protocol 2PC: The first step to request phase statistical result of the vote by the coordinator, the results of the implementation of the second step after the vote, if the result of the vote is submitted, it would be submitted to the Executive, or do not commit disadvantage is synchronous blocking, and. In case coordinator hung up can not guarantee ACID.

Three-phase commit 3PC: The first step became split 2PC 2-step and introduces a timeout mechanism to solve the pain points 2PC first step to send a signal Xianxiang participants to see if we can submit, if possible. returns yes, otherwise no. the second step preCommit stage, pre-submission that, if participants can complete commit, returns ack into the confirmation, if you can not give up the submission of this transaction. the third step doCommit stage, a real business submit.

Solution 6 distributed transaction What?

XA: XA protocol standard is based on a two-stage transaction implementation, the current mainstream database already support this agreement because it is two-phase commit protocol, the disadvantage is obvious, is not suitable for high concurrency scenarios.

Compensation mechanism TCC: try, commit, the abbreviation cancel, try to detect the stage, commit to the Executive, as long as try to perform a commit stage success will certainly be executed, cancel service error, roll back the transaction, the release of resources.

Messaging middleware MQ: .RocketMQ can be solved with support transactional messages through messaging middleware RocketMQ Ali, specifically thinking something like this:

The first step: A message producer sends a message to the message cluster prepared to get the message address.

Step Two: Local commits the transaction, and sends a confirmation message cluster.

The third step: to get through the first step to address, access the message and change the message state.

 

7.Dubbo how to handle the service request failed

It has a default retry mechanism and a timeout mechanism Dubbo start time, if the service does not respond within a defined time request, this request is considered a failure.

If the number of retries in the configuration, request fails dubbo will resend the request, the number of retries if the request fails has not exceeded the request is successful, considers that the request fails, an exception is thrown.

8.Dubbo What protocol support? What is the default protocol Dubbo?

Dubbo supports multiple protocols, such as dubbo, http, rmi, webservice, supported by default protocol is dubbo agreement.

9.Dubbo and SpringCloud What are the differences?

Dubbo is soa (service-oriented architecture), SpringCloud micro-service architecture.

Dubbo based RPC (Remote Procedure Call), SpringCloud is based on the Restful, tcp is connected to the bottom former, which is http, in the case of large number of requests, the response time is shorter than dubbo springcloud.

Functionality provided Dubbo to be less than springcloud, springcloud service provides a set of micro-management program, such as the service fuse, monitoring, tracking, configuration center.

10.Soa and micro Services Architecture What are the differences?

Micro Services is developed on the basis of the Soa, from the size, the size of the micro-services SOA is more than fine.

Since the micro finer granularity services, so that the degree of coupling with respect to the micro-service architecture lower coupling the SOA.

Service micro scale SOA services compared to the average larger, the amount of concurrency can carry much higher.

11.dubbo service providers, service consumers what information needs to be configured?

By: need to configure the IP, port, protocol.

Consumers: Address registry.

What 12.Dubbo load balancing strategy

Hash consistency balancing algorithms, polling, random call, the least active call law.

What data structure 13Redis support? What scenarios are there?

Redis supports a total of five kinds of data types: String, List, Hash, set, sort set.

String is often used to store strings, get, set cache.

List can be used to make a list of .Hash used to put objects, such as user information .sort set can be used for leaderboards

Persistence way 13.Redis of what? What are the pros and cons of each?

Redis persistence in two ways, AOF and RDB.

AOF: independent logging write commands stored logs, and then re-execute the data recorded in the log when you restart to complete the recovery benefits of data security is not easy to lose data, and content aof can read, if you do not accidentally knock. the flushall command, can also command aof flushall end of the file deleted, then you can restore the data. the disadvantage is that occupy large storage space, data recovery is slow.

RDB: the data in memory in a manner snapshot written to the binary file data recovery advantage is fast, convenient backup, the disadvantage is more consumption of memory, it may cause data loss.

14.aof file is too large how to deal with?

You can repeat aof command, bgwriteaof, after execution will trigger rewrite aof a file, the command aof repeating compression.

15. talk about the affairs of redis

redis transaction prior to open the MULTI affairs, multiple commands into teams to the transaction, and then trigger the execution of all the commands through the ranks of the EXEC command if you want to cancel the transaction can be executed discard command.

16. What is Cache avalanche

If the expiration time all cached data settings are the same, then all cache fail due expire at the same time, then all the requests will be entered into the database, which is cached avalanche.

17. How to avoid cache avalanche

You can set a random value for the cache expiration time, avoid cache expires at the same time.

18. The cache penetration is what? How to avoid?

Cache penetration refers to when a certain query data does not exist, the cache will miss, if not from the database query is not placed in the cache, then each request into a database query will actually lose the name of the cache.

Bloom filter can be used, that is, the database hash all possible data into a sufficiently large bitmap, be sure there is no bitmap data will be filtered out, thereby reducing the pressure on the database.

19.zookeeper principle

zab protocol, the protocol has two modes zab recovery mode (selected from the master) and broadcast mode (synchronous), when the primary node is down or the service starts, ZK enters recovery mode, select Master node after a sync data.

What scenarios 20.zookeeper

zookeeper as registry dubbo, you can do a distributed lock, you can do the configuration of the center mycat.

21.zookeeper node types What? What is the difference?

Temporary and permanent node node, then fine division that the provisional order / disorder node, permanent order / disorder node.

After the end of the program to create a temporary node, the node will automatically disappear temporary, provisional data on the node will disappear together.

22. zookeeper talk about the election mechanism

zookeeper number of nodes must be 2n + 1, which is an odd number of nodes, in order to ensure the success of the elections.

5 to cluster nodes, for example, each have their own zk id, called myid, here I suppose five servers zk of myid were 1-5.

Start myid to zk 1, which will own vote, and then found no other nodes in the cluster to start, so it is looking state

Start myid as zk 2, which will own vote, then vote with 1 swap node, because the node myid node 2 is greater than 1, so the vote node 2 wins, 2 at this time of the vote but less than the total number of nodes nodes half, the node 2 can not be used as master, the node 2 will also be looking at state

Start myid as zk 3, which will own vote, then vote with 1,2 swap node, because the node is greater than myid 3 Node 2, Node 3 so the vote to win, Node 3 is greater than half the number of votes of the total number of nodes , this time winning node 3, to become the master node, the other node becomes two nodes slaver

Start myid as zk 4, although the maximum node myid 4, but this time there has been a master node 4 can only be nice to do a node from ...

Start myid 5 above ...

When a node has hung up after the start of re-election, with election rules similar to the above.

Why 23.zookeeper number of nodes can only be an odd number?

Since the election algorithm requires the zookeeper: Available nodes> The total number of nodes / 2 if an odd number of nodes, then once zk cluster equal split brain occurs, it can not guarantee that the algorithm requires.

24. How to ensure high availability message queue

Using cluster can be used to ensure high availability to RabbitMQ for example, we recommended mirrored clusters, ordinary cluster node if the disk hung up on GG, or can not ensure high availability configuration, mirroring the cluster to use HAProxy, need Admin page set policies, the ha-mode set to all, shows that are stored on each node in the mirror ... Due to space limitations, the specific cluster configuration behind me specifically wrote a blog summary.

25. How to ensure that messages are not repeated (issues such as power) consumption

rabbitmq did not provide information to prevent repeated consumption function, only to realize at the end of the business, if the business is to do a cluster, we can help solve redis, which would be the msgid and consumption status messages with redis stored, each consumer times before to check out the status of the message of this consumer if the consumer has been passed, you can not spend. If you are not spending, you can consume, consume complete the corresponding status has changed consumer can be.

26. How to ensure the consumer ordering of messages? 

To rabbitmq for example, message 1 and message 2 need to consume in order, you must consume messages 1, 2 post-consumer news, we can put order in the message to a different queue, and then consumed by the worker.

27. How to solve the delay of a message queue and expire problem?

Batch redirection, write their own programs failed to check out the data and then re-import in the team.

28. The message queue is full of how to deal with? When the message is how to deal with excessive backlog?

We should try to avoid this problem in the design, if it has been met, you can take the service degradation strategy, and temporarily add some more strong consumer spending power, to X times the rate of consumption in the queue backlog of messages.

Published 89 original articles · won praise 70 · views 40000 +

Guess you like

Origin blog.csdn.net/lovexiaotaozi/article/details/89713937