Interview questions

How to design a highly concurrent system?

Interviewer psychological analysis

To be honest, if the interviewer asks you this question, then you have to exert all efforts now nurse. Why? Because you do not see a lot of companies now hiring in all JD spade, high concurrency on experience is preferred.

If you do have genuine talent, the Internet company doing too high concurrency system, then you really get as Tannangquwu offer basic, nothing issue. The interviewer would absolutely never ask you, or he is stupid.

Suppose you dry in a well-known electricity supplier companies is too high concurrency system, the one hundred million users a day, billions flow, concurrency million in the previous peak, or even thousands. Then people will be careful questioning your architecture, what architecture your system? How to deploy? How many machines are deployed? Cache ye use? MQ ye use? Database ye use? Is to dig you in the end is how Kang Zhu highly concurrent.

Because the real dry too high concurrency people must know, from the architecture of the system are in the business of paper, but also really high concurrency in complex business scenarios when a system architecture that is definitely not so simple, with a redis, with mq on You can do it? Of course not, after the real system architecture with the business, than this simple-called "high concurrency architecture" complex many times.

If the interviewer may ask you a question that how to design a highly concurrent system? So sorry, it must be because you did not actually doing too high concurrent systems . The interviewer will look at your resume lacks color, the feeling is not ye, so it will ask you, how to design a highly concurrent system? In fact, plainly essence is to see that you have not studied their own, there is no certain knowledge accumulation.

The best course is hiring a real high concurrent buddies slightly dry, but the number of buddies scarcity, bad move. So may times it is a trick of their own research had buddies, what better than a move would not buddies Okay!

So this time you have to do a one-man show, and show off all your knowledge about high concurrency!

Face questions analysis

In fact, the so-called high concurrency, if you want to understand the problem does, in fact, you have to start from the root causes of high concurrency, why have high concurrency? Why high concurrency very fast hardware?

I said a little plain, very simple, because the systems are just the beginning of connection to the database, but the database to know when to support concurrent two or three thousand per second, basically finished soon. So have said many companies, the beginning of the dry, technology is relatively low, the result of business development too fast, sometimes the system could not carry the pressure hung up.

Of course, hung up, why not hang? If your database instantly carry 5000/8000 per second, or even thousands of concurrent, it will be down, such as mysql because it simply did not carry such a high concurrency.

So why high concurrency regressed? Because now more and more people use the Internet, many app, website, system load is high concurrent requests, the peak may be complicated by several thousand per second, normal. What if two-eleven and the like, complicated by the tens of thousands to hundreds of thousands per second are possible.

So so high concurrency, coupled with already so complicated business, a quick play? Really powerful, it must be playing in complex business systems in high concurrency architecture of people, but you do not, then I tell you about how you should answer this question:

It can be divided into the following 6:00:

  • Split system
  • Cache
  • MQ
  • Sub-library sub-table
  • Separate read and write
  • ElasticSearch
    file

Split system

A system into multiple subsystems, with dubbo Laigao. Each system then even a database, a library so already, now multiple databases, can not carry it high concurrency.

Cache

Cache, you have to use the cache. Most of the high concurrency scenarios are reading and writing less , then you can write in a database and cache, then read when the cache does not have to walk a lot. After all, people redis easily tens of thousands of concurrent single. So you can think about your project, those who carry the main request read a scene, how to resist high concurrency with cache .

MQ

MQ, have to use MQ. You may still appear high concurrent write a scene, such as a business operating in dozens of databases to engage in frequent, additions and deletions additions and deletions, crazy. That high concurrency definitely hang out your system, if you use to carry redis write it certainly will not do, people are cached, LRU data at any time was up, the data format is also very simple, no transaction support. So that had to use mysql with mysql ah. Then you supposed to? With MQ bars, poured into a large amount of MQ write request, the queue slowly play, behind the post-consumer system write slowly , in a controlled range mysql carrier. So you have to think about your project, write those scenes carry complex business logic, how to write asynchronously with MQ, enhance concurrency. MQ is a stand-alone anti-tens of thousands of concurrent ok, but also specifically said before this.

Sub-library sub-table

Sub-library sub-table, probably the last database level or inevitable anti-high concurrency requirements, well, then it will be a database into multiple libraries, multiple libraries to carry higher concurrency; then a table will be split into a plurality of tables , each table holding data amount less, sql improve running performance.

Separate read and write

Separate read and write, this means that most of the time the database may also read how much writing is not necessary that all requests are concentrated in a library it can put forward a master-slave architecture, writing the main library in, from the library to read take, read out a write separation. Reading too much traffic , you can also add more from the library .

ElasticSearch

Elasticsearch, referred es. es are distributed, you can easily expansion, distributed natural you can support high-concurrency, because at every turn you can add machines to carry the expansion of higher concurrency. So some of the more simple query, operating statistics class, consider using es to carry, as well as full-text search of some kind of operation, you can also consider using es to carry.

Above 6:00, the basic is highly concurrent systems will certainly be doing some thing, we can combine carefully consider knowledge have said before, the time you can put this elaborate system, then each part should pay attention to what issues , have talked about before, you can elaborate elaborated on this show that you are a little accumulation.

To be honest, after all, you really powerful thing, not that get a little technical, or probably know a highly concurrent system should look like? In fact, actually a real complex business systems, high concurrency do much more than point to the above-mentioned complex several times to a hundred times. You need to consider: what needs to be sub-library sub-table, which does not require sub-library sub-table, single table with a single library sub-library sub-table how to join, what data should go into the cache, which can put data Kangzhu high concurrency after the request, you need to complete the analysis of a complex business system, and then step by step to join the transformation of the system architecture of high concurrency, this process is very complex, once done once and well, you're in the market It will be very popular.

In fact, most of the company's real value, not that you have some technical high concurrency related to some basic knowledge of architecture, architecture, RocketMQ, Kafka, Redis, Elasticsearch, high concurrency this one, you know, can only It is a second-class talent. Of a complex distributed systems hundreds of thousands of lines of code, step by step, architecture, design and practice of architecture is too high concurrency people, this experience is valuable.

Based on the number of public-meter pocket link:
https://mp.weixin.qq.com/s/9p-XPL_FRqN5nhbiwmOXSw