B station technology selection and architecture

foreword

Taobao, Facebook, Meituan, these big companies in the industry all started from PHP in the early days. PHP has the characteristics of out-of-the-box and rich open source projects. The same is true for Station B. The technical development history of station B: it was developed in PHP language at the beginning, and then the middle platform of station B was gradually occupied by Node, and the background technology gradually moved closer to JAVA for higher concurrency, more robustness, and big data analysis. This has led to the overall confusion of Bilibili's technology. In the early stage, station B had failures almost every day. With the expansion of the team and business, the pressure from all aspects increased, and there were fires everywhere. The code is chaotic and the framework structure is chaotic, which has reached the point where it is difficult to maintain. It is necessary to clarify the context. Under such circumstances, unifying the technology stack is undoubtedly what should be done. In the end, it was found that rewriting was the optimal solution. Why Go? In the final analysis, rewriting the background project is an attempt by Bilibili to unify the technology stack. As for why Go was chosen in the end, it is very important that Go can meet the needs of refactoring and optimization of the Bilibili platform; R&D Director Mao Jian himself is a loyal preacher of the Go language.

insert image description here

B station front-end road

Station B, when it first started to separate the front and back ends, it did follow the first method. There are still some pages that still use this model, for example: www.bilibili.com/account/his... (see the website source code). It is a good way for pages that do not need SEO. After the front-end development is completed, the corresponding js and css are packaged through webpack and uploaded to the CDN, and then the html file packaged by webpack that references the corresponding resources is uploaded to a special static machine, and then the operation and maintenance configures the routing to transfer the page Just flow through. Back-end students only need to provide the corresponding API interface. The front and back ends are maintained separately, and you follow your own pace, which reduces the coupling between the page and the service.
This method is indeed a method that can quickly separate the front and back ends. It took us a while to refactor using vue on the PC side and react on the mobile H5 side. The progress is fast, but the disadvantages are slowly showing.
At the first screen, because he has to wait for the resource to be loaded before rendering, it will cause a white screen on the first screen. If it is a single page, it is okay, but if it is a spa application, its loading time will become very long. The white screen time will greatly affect the user experience, and because domestic search companies are not well compatible with spa applications, client-side rendering will be very unfriendly to seo, and pages with seo needs are in urgent need of service side rendering.

(On the homepage of Station B, the right module does server-side rendering, and the left module does not do server-side rendering.)
Then, relying on node for server-side rendering is put on the agenda.

selection

First, select the node framework. There are three mainstream frameworks on the market, hapi express koa, and some frameworks that have undergone some packaging and customization, such as eggjs. I
excluded eggjs from the beginning. The function is very powerful, there are many functions, some of which are not needed at all, which makes it not lightweight. Second, eggjs is a black box for me. If there is any problem, I will spend a lot of money to solve it. long time. (But I still borrowed from eggjs in many places, after all, it is very powerful)
Then the remaining three frameworks, express is relatively simple to use, and the documents are more
comprehensive, so I chose express (it was refactored later) = =!)
Then there is the selection of the front-end framework because there are many mainstream front-end frameworks, such as ng rv, etc. I am using react and vue. They have the advantage that they can be isomorphic on the front and back ends, and the same logic does not need to be used. Write two copies, it's great

(The isomorphic logic is probably like this.)
Since the front and back ends were separated before, the pc has been refactored with vue, so naturally, this time the server rendering is also built on vue and uses vue ssr (this is also for me. The latter idea laid the groundwork)
First, let’s choose a simple page for proofing, let’s use the tag page (the child chosen by God: www.bilibili.com/tag/3503159 )

B station Golang technology stack analysis

technology stack Technology Selection reference link
RPC The warden framework based on grpc package has been open source https://github.com/bilibili/kratos
HTTP frame The blade master framework based on gin package has been open-sourced as above
Service Registration and Discovery In the early stage, it was zk, and later gradually changed to refer to the self-developed discovery of Spring Cloud system Eureka, which has been open source https://github.com/bilibili/discovery
storage DB, redis, memcache, hbase store some user kv information and historical records, the packaged library library/database/ client library has been open source https://github.com/bilibili/kratos
search Station B videos, users, history records, etc. use es to search, and the client has been encapsulated in the basic library library/database/elastic
small file storage The bfs developed by Mao Jian has been open sourced. https://www.toutiao.com/i6272104949560115714/ https://github.com/Terry-Mao/bfs
message queue Databus based on kafka package
log A log framework based on uber's zap package
Configuration and Configuration Center Support reading configuration from environment variables, parsing configuration from toml, and supporting remote configuration center (self-developed, mysql storage, local landing, http protocol, long poll, client has update events, similar to Ctrip's open source Apollo)
monitor Using the open source prometheus, the framework and libraries (sql, redis, hbase, etc.) have pre-embedded counting points and time statistics points, and can also be used in business logic. library/stat/stat.go
trace trace seems to be agent-based, using unix domain socket for transmission, and the framework and library are pre-buried. library/net/trace.go
R&D process management TAPD, haha, there is related tapd struct information

Among them, RPC, HTTP framework, and some library packages for data access, including generation tools, are all open sourced on github with the kratos project (https://github.com/bilibili/kratos Kratos is a set of Go microservice frameworks open sourced by bilibili, including A large number of microservice related frameworks and tools)


The detailed introduction of the middleware currently used and packaged by station B is
mentioned in the sharing of Gopher China 2017 station
B. .jianshu.com/p/923917220d23
B station operation and maintenance system development
https://myslide.cn/slides/3840

Brief introduction of Mao Jian, technical director of bilibili

Mao Jian, technical director of bilibili, has been responsible for the UGC platform and infrastructure in bilibili (B station) since 2015, developed the open-source push service goim for live barrage, BFS distributed storage for B station, guided the development of B station cache proxy, bili twemproxy, etc., iterated and reconstructed the architecture of the historical master site. They worked in Cheetah Mobile for the past six years, worked as a MySQL DBA, and did C development. Among them, gopush-cluster was developed for the push system of Cheetah Mobile. I like application service performance diagnosis, kernel research, and stable server-side architecture evolution. Tencent Cloud Most Valuable Professional (TVP). Responsible for the data platform department of bilibili, with nearly ten years of experience in server-side research and development. Good at high-performance, high-availability server development, familiar with Go, Java, C and other languages. Participated in station B, complete transformation from monolithic architecture to microservices, including microservices governance, microservices availability design, microservices data consistency design, microservices middleware, microservices monitoring, microservices log collection, microservices load Balance, and microservice RPC framework development, etc.
More influential projects in the open source industry:

  • goim https://github.com/Terry-Mao/goim Distributed IM long connection broadcast service;
  • bfs https://github.com/Terry-Mao/bfs distributed small file storage;

Guess you like

Origin blog.csdn.net/jgku/article/details/128447915