For example, is the difficulty of QQ/ Weibo /12306 architecture the same as that of high concurrency? As described in this article, the architectural challenges of the three types of business are different in the same high-concurrency scenario:

  • QQ services, users mainly read and write their own data, access with uid attribute, data access lock conflict is small
  • In microblog services, the user’s feed home page is composed of messages released by others, so there are lock conflicts in data reading and writing
  • 12306 services have high concurrency. Almost all read/write lock conflicts are concentrated on a small amount of data, which is the most difficult

On the system
On the business

At the system level, what is the optimization direction of seckill business?

There are two main things:

(1) Try to intercept requests upstream of the system, rather than let lock conflicts fall on the database.



Voice-over:
At this time, the efficiency of the system is not as good as the offline ticket window.

(2) Make full use of the cache.

  • Number of queries, read, large amount

  • More than ticket inquiry, read, large amount

  • Order and pay, write, small volume

What is the common system layer architecture for slicing services?

  • End (browser /APP), top layer, user oriented

  • Site layer, access back-end data, assembled HTML/JSON returns

  • A service layer that shields the underlying data details and provides data access

  • The data layer, the DB stores the inventory, and of course the cache

How should these four layers be optimized?



Request interception on the end (browser /APP)

Does the user really send a request back each time they shake?



Voice-over:
If you submit frequently, you can be prompted “Too frequently”.

Voice-over:
This is called “blocking requests as upstream as possible” and the browser /APP layer blocks 80%+ of requests.

Second, site layer request interception


What makes a user unique?
A uid can be used to identify a user



One UID, 5s only through one request, what about the rest of the requests?

Voiceover: This can be done for both train queries and residual ticket queries to ensure user experience (at least no return)
404 pages), and ensure the robustness of the system (using page caching to intercept requests at the site level).

Request interception at the service layer

How to intercept concurrent requests that have reached the service layer?

Voice-over: If the database can only handle 500 write requests per second, only 500 pass through.
With what?




  • If the first batch of requests are successful, drop another batch

  • If the previous batch of requests is out of stock, all subsequent requests are returned “Sold out”

How to optimize read requests?
Voiceover: Cache is expanded horizontally, easily linear.


4. Database layer

  • Browsers block 80% of requests

  • The site layer intercepts 99% of the requests and does page caching

  • The service layer makes write request queue and data cache according to the business inventory and the database’s ability to withstand pressure


Voice-over: This kind of business data volume is not large, there is no need to separate the database, database to do a high availability on the line.
Voiceover: before optimization, 0 of 10W requests were successful, and the validity was 0%.

According to the above optimization scheme, in fact, the biggest pressure is the site layer, assuming that the number of valid requests per second is 100W, how to deal with the pressure of this part?

Site layer speed limit, is the request count per UID put in redis?
Under the condition of large throughput, high concurrent access to Redis, will network bandwidth become the bottleneck?

Voiceover: This count does not require a high level of data consistency and accuracy. Even if the service restart count is lost, the count can be restarted at most.

Business Compromise ONE

Business Compromise 2
Business Compromise 3
Business Compromise 4

Voiceover: Display inventory will be eliminated N times, display whether will only be eliminated once. Rather, users focus on the availability of tickets rather than the number of tickets available.

conclusion

Any architectural design that takes away from the business is a hooligan

The architect’s Path– Share technical ideas

Concurrent deduction, how to ensure data consistency?
Concurrent deduction consistency optimization, ABA problem under CAS
Concurrent deduction consistency, idempotency problem
The same is high concurrency, why different business difficulty is different?