The first word

I often think about many technical “why questions” while walking, sometimes thinking about a problem for a long time until I am convinced of every point of the problem. Therefore, I want to record these thoughts and form an article, which can be regarded as a new series. You may not see the code in these articles, but you’ll get a peek at some of the overlooked questions and the deeper “why” of the question.

Today I bring the first one, why did Dubbo rewrite it with Go?


Dubbo, which was created by Alibaba and opened source in 2011, has been in its 10th year. In 2019, it was rewritten with Go and opened source. Now two years later, it has been developed from V1.0.0 to V3.0.0 with a star count of 3.8K so far.

Once a colleague asked me why Dubbo’s “old” project had to be rewritten with Go. Is there any practical significance?

Today I would like to share some of my views.

Connecting past and future

I think the best way to answer this question is to start with dubo-Go’s origins, as it describes itself on github’s page:

The official Chinese translation is

Apache Dubbo Go language implementation, build a bridge between Java and Golang, and interconnect with gRPC/Dubbo ecology, lead the Java ecology to enjoy the technology dividend of the cloud native era.

In a company or department, someone is using Java Dubbo and someone is using Go, and they need to communicate, so dubbo-Go is used to solve communication problems.

So the first question is, why does a company use Java and Go?

Programming language choices

As for programming language choice, in a commercial company, I think efficiency is the most important factor, and everything else is secondary. Because the main purpose of business companies is to make profits, no matter what language, as long as it can get the same revenue at the lowest cost is a good language.

Efficiency also includes several aspects:

  • Development efficiency. The development efficiency is high, the project can be on-line as soon as possible, occupy the market, but also can save the labor cost
  • Operating efficiency. High operation efficiency, can save server cost

Throughout the choice of many domestic commercial companies are considered this way, such as Ali.

In the early stage of Alibaba, PHP was chosen mainly for development efficiency. However, with the development of business, PHP performance could not be supported, so we had to change to a language with high operation efficiency.

However, the development efficiency of these two languages is low. It is necessary to find a balance between development efficiency and operation efficiency, so Ali chose Java.

When answering the question on Zhihu, Ali official chose Java for the following reasons: performance, easy to learn, rich ecology, active community

Performance first, easy to learn, rich ecology, active community are also said to be efficient development, it is with these advantages, high development efficiency.

When Alibaba chose Java, it developed a large number of Java middleware and trained a large number of Java talents. Therefore, other companies also referred to Alibaba when selecting technology, resulting in an increasing number of companies choosing Java.

It is the same with Go. Some young companies may have started with PHP, Python and other scripting languages in their early days, but when they grow bigger, they have to face the same problems as Ali: performance problems.

When Go was released in 2012, people had another choice. Go has high performance, but it is also very simple and easy to use. New companies like Bytedance are mainly based on Go.

So in summary, it is reasonable to choose Java or Go. It is reasonable to exist.

Why would a company choose Java and want to use Go?

  • Go is a faster startup language, faster compilation, less memory, and better at high concurrency (coroutines) than Java, so companies that already have Java will also consider Go, although the number of such companies is small.
  • Some companies don’t have a mandatory technology stack, so new departments and businesses can be developed in a new language, Go.

summary

To sum up, it is reasonable to choose Java or Go, and it is also reasonable for a company to choose both. Although the proportion is small, there is still a need for Java and Go communication.

Dubbo wins in RPC framework

In the early stage of a company, it is usually a single service. When the scale of a company reaches a certain extent and the single application cannot support the business development, it will choose the micro-service architecture. At this time, a convenient RPC framework is needed.

Among RPC frameworks that can adapt to Java language, Dubbo is the earliest open source in China and was opened in 2011.

Competitors like Spring Cloud opened in 2014, Weibo’s Motan in 2017, cross-language gRPC in 2015, and Thrift in 2007.

Thrift is just an RPC framework. Dubbo includes out-of-the-box service governance capabilities such as service registration and discovery, load balancing, fault tolerance, dynamic configuration, and so on.

It’s fair to say that early Java RPC frameworks had no choice.

With so many companies using it and Ali’s endorsement, Dubbo still has its place, even in the era of RPC frameworks blossoming.

summary

When a company chooses the Java programming language and the Dubbo framework (and there are plenty of them) and then tries to Go, or some new business or division tries to Go, they face the challenge of how Go communicates with Java’s Dubbo.

Since the Dubbo protocol is proprietary, the cost of re-implementing it with Go is still quite high. So Dubbo-Go came into being, and from this point of view, Dubbo-Go has considerable value in the way of connecting Java and Go communication.

End the fight with thread pools

If you are using the Dubbo framework, you will often need a Dubbo gateway. For details on the Dubbo gateway, please refer to my article “Evolution of Microservices Gateways”.

In this article, introduces in detail a Dubbo gateway of the background, difficulties, type selection, design, evolution, and hit the pit experience, of which I spent much introduced the “struggle” and the thread pool, in Java, thread is valuable, but Dubbo gateway if it is a synchronous call, must be a request to take up a single thread, this leads to concurrent couldn’t get on, Moreover, when the thread pool is full, other requests are affected.

So the solution is either to isolate the thread pool or make asynchronous calls instead. Isolating the thread pool only solves the problem that requests don’t interact with each other, but concurrency still doesn’t work. Switching to asynchronous calls works perfectly, but coding is too complicated.

The Go coroutine can just solve this problem, Go coroutine is very lightweight, scheduling efficiency is also higher, so we can use simple code to write a very efficient gateway.

For example, you can intuitively feel the performance of Nginx, but if you use Java to achieve, do not know how many machines to achieve the performance of Nginx, but Baidu in the reverse proxy to use Go write BFE instead of Nginx, visible its performance is exaggerated.

For an introduction to and principles of coroutines, please refer to my article, “A Year of Writing Golang: Talk about processes, threads, and coroutines.”

summary

Therefore, dubbo-Go also provides a new solution for Dubbo gateway. There is already an online Dubbo-Go gateway. The open source project refers to Dubbo-Go-Pixiu.

Pave the way for Dubbo Mesh

Service Mesh has gradually become the next generation of micro-service architecture, and Go is definitely a shining star language in Mesh. No matter K8S, Docker and other cloud native infrastructures use Go to write, Go’s development speed and high concurrency of coroutines make it the preferred language for Mesh.

Based on this, Dubbo Mesh is also paved the way for Dubbo. However, Dubbo Mesh is still in the stage of small area, and the complete implementation solution is not open source. From this point of view, if a company wants to take the road of Dubbo Mesh, Dubbo Go may also be one of the points that they should consider.

conclusion

With all that said, the answer to the question of why Dubbo is rewriting with Go is the same as the official answer: to bridge the gap between Java and Golang. Here are a few key points about why you should “build this bridge” :


  • Search the wechat public account “Bug catching Master”, reply the keyword “Nacos” to send you an e-book “Nacos architecture and Principle”, Dubbo materials are also preparing, do not want to miss you can click a follow.