Interviewer: Enough lad, I will ask a message middleware, you have written it all by hand!

Preface

This kind of design problem must be familiar to everyone, and it can be encountered more or less during the interview.

For example, how to write a thread pool? How to write a HashMap? How to write an RPC framework, etc. Of course, the writing here is not really asking you to write it in code, but just talk about the design concept and the overall architecture.

This interview question comes from a reader’s byte interview experience. I will elaborate on the interview skills and the design of message middleware.

I think the focus is on interview skills because it is universal.

Two extreme situations

When most students encounter this problem, there are two extreme situations:

  • The first type: a dumbfounded face, blank eyes, no idea where to start, all thoughts, all turned into a sigh.

  • The second type: talk about it, like a handful of Gatlin in your mouth, da da da da da da da da, braving blue fire.

Needless to say, the first one is that a better interviewer may guide you and ask some suggestive questions, step by step to lead you to a better place. Of course, if you don’t have anything in your chest, it’s still hopeless, and the scene will be abnormal. awkward.

The second type will overwhelm the interviewer. Maybe you really know a lot and many details are clear, but you can't throw it all out. This will make you unable to grasp the point.

The interviewer is also a human

This point is actually very important. Many consider the interviewer as a questioning robot with unreasonable feelings. They think that he can get your point completely. They don’t know the details you are proud of. He may think you are talking about snakeskin. .

People will have feelings and they need to communicate . A good interviewer will control the overall progress. Starting from the routine, let the venue become hot and dig deeper.

Of course, there are some interviewers who are relatively weak. At this time, you need to deliberately flow out a little blank to let the interviewer doodle so that the interviewer feels that you are very comfortable and your wave is stable.

Of course, even in the face of interviewers who control the audience, you have to take the initiative. Everyone has their own points of expertise. You need to guide the interviewer to ask about your strengths.

Correct answer posture

The correct answer is BFS (breadth first search) instead of DFS (depth first search). What does it mean?

That is, we need to first talk about the key points of what needs to be designed from the overall situation, and then wait for the interviewer to continue to ask questions and dig deeper .

We need to figure out the interviewer's psychology , and from his questions, we can see which direction he wants to know the focus of.

Take HashMap for example. You simply talk about acquisition, writing, conflict handling, expansion, and so on, and then wait for the interviewer’s next question. It may go deeper in thread safety, or it may go in the direction of expansion. Dig again, such as leading to Redis hash expansion and so on.

So let the interviewer leave the opportunity to ask questions, seize his preferences or answer in a familiar direction, so that if you answer well and talk to each other, the interviewer will highly recognize you.

And pay attention to pause when talking about the design points, leave the opportunity for the interviewer to interrupt, let the interviewer fully participate in your design .

Let's take HashMap as an example. For example, if you pause after getting, writing, and conflict, there is a high probability that the interviewer will ask if there are any more? Let the interviewer have a sense of participation, let him feel that the design is gradually improved after his guidance .

Of course, if you don’t ask, it’s okay, just pause and continue talking.

Let the interview become a technical exchange, this is the highest state of the interview. I believe that after the interview, both parties will feel that the intention is still unfinished. This is how the mutual sympathy came.

But this kind of scenario is not so easy to encounter. First of all, you and the interviewer must have the same preferences. For example, you have a deep research on the JVM, and the interviewer has a deep research on storage. JVM does not understand Deep, so there will be no sparks.

So many people will encounter such a situation: I face this company while hanging out, and the other company is super superficial. This is normal.

Of course, if you say you are omnipotent, then I didn't say it.

Summary of interview skills

First of all, you must treat the interviewer correctly. You and the interviewer are the same. Don't be low-pitched.

Secondly, you need to grasp the key points when answering the questions. Don't say everything you know in a brainstorm. Leave it blank for the interviewer to ask questions.

Control the rhythm of the interview and lead in a direction you know well.

How to write a message middleware

Next, let's take a look at how to write a message middleware.

First of all, we need to clearly put forward several important roles of message middleware, namely, producer, consumer, broker, and registry.

Briefly describe the data flow process of the message middleware. It is nothing more than the producer generating the message and sending it to the broker. The broker can suspend the message, and then the consumer obtains the message from the broker for consumption.

The registry used for service discovery includes: Broker's discovery, producer's discovery, consumer's discovery, and of course offline. It can be said that the high availability of services cannot be separated from the registry.

Then start to briefly describe the main points of the implementation, you can talk about the communication: the communication of each module can be implemented based on Netty and then a custom protocol. The registry can use zookeeper, consul, eureka, nacos, etc., or it can implement simple namesrv like RocketMQ itself. (This sentence is a key word).

In order to consider expansion and overall performance, a distributed idea is adopted. Like Kafka, a partition concept is adopted. A topic is divided into multiple partitions. To ensure data reliability, multiple copies of storage, namely Leader and Follower, are adopted, based on performance and data. Reliable trade-offs provide asynchronous and synchronous flash storage.

And use the election algorithm to ensure that the follower can be on top after the leader hangs, ensuring the high availability of the message queue.

Also in order to improve the reliability of the message queue, the local file system is used to store the messages, and the sequential write method is used to improve performance.

According to the characteristics of message queues, memory mapping and zero copy can be used to further improve performance, and batch processing ideas like Kafka can also be used to improve overall throughput.

At this point, it's almost the same. The main points to be said are almost the same. The interviewer has already thought in his heart that this person seems to have something.

After that, there are many points that can be digging deeper. For example, in the Netty mentioned, various registries can ask a lot, such as the selection comparison between the registries.

You also mentioned the election algorithm, so you may ask about Bully algorithm, Raft algorithm, ZAB algorithm, etc.

You also mentioned partitions. You may ask what is the difference between this partition and RocketMQ queues? How to implement specific partitions?

Then you mentioned writing in order. You might ask why you want to write in order? What do you mean by memory mapping and zero copy? Then do you know which RocketMQ and Kafka use? (I have analyzed these, you can see the things you don't know about RocketMQ and Kafka underlying storage)

Of course, you may also ask various details, such as how to store the message, how to generate the index of the message, etc., to dig deeper to see if you have read the source code of the message middleware.

There is still a lot to ask, and I cannot extend every point in this article. These knowledge points still depend on everyone's accumulation and thinking .

Of course, in future articles, you can write about some of the points mentioned today, such as Netty, election algorithms, and comparison of multiple registries.

What does the interviewer want to ask

Going back to this interview question, in fact, what the interviewer wants to ask is the general design, including the overall structure, data flow and the grasp of some characteristics, so what he wants to hear about this question is the key points, not those detail.

The continued digging depends on the various keywords you put forward when answering this question. Once the interviewer himself catches the familiar words, he will already know what to ask you next.

So when answering the interviewer, you must not only get his points, but also pave the way for subsequent answers . Don't mention the ones you don't know, and mention the ones you are good at.

At last

As I mentioned before, the focus of this article is not how to answer and write a message middleware, but the interview skills.

Because there are thousands of interview questions, and the skills mastered so thousands of interview questions are applicable.

I would also like to mention some personal opinions about interviews. I am personally an interview-driven learning contestant. My motivation for learning is the interview. I enjoy the unruly kind of a smile when the interviewer asks me everything.

But I don’t advocate the practice of purely back-testing questions. Learning is a cumulative process. As I said at the end of each article, from a little bit to a little bit, and as I mentioned at the beginning of every article, every era, Will not treat people who can learn.

My interview drive is not only about learning for the interview, but also learning from the interview scene. What does it mean?

To learn any thing, imitate an interviewer in front of you, let him ask you questions from various angles, and drive you to understand a knowledge point in an all-round way. This is what I call an interview-driven learning player.

So if you read my previous article, you will find that I often ask why, and then answer it.

One more thing to note, hands-on ability, this is very important.
Finally, I prepared some Java architecture learning materials for everyone. The learning technology content includes: Spring, Dubbo, MyBatis, RPC, source code analysis, high concurrency, high performance, distributed, performance optimization, microservice advanced architecture development, etc., click Get it for free here.

Guess you like

Origin blog.csdn.net/jiagouwgm/article/details/112667857