[Event Review] Scala Meetup in January 2023

The eighth Scala Meetup ended successfully last Saturday. Three senior Scala users shared three major topics with 2000+ online users:

At the same time, in response to questions from fans, everyone also discussed issues that have attracted much attention, such as "Scala entry and advanced paths, and the application of Akka in distributed scenarios". The transcript of the speech can be downloaded here .

Welcome to pay attention to the public account of Bitu Technology to learn about the latest news and activities of Scala. You are also welcome to leave a message in the background and apply to join  the Scala development exchange group!

Tubi's gRPC Evolution Road

Tubi Scala Team & gRPC

Zhang Zhenglai, a back-end engineer from Tubi, first introduced the background of the birth of gRPC and its main related features.

gRPC is often used to build cross-language, cross-platform high-performance microservices. Its excellent features such as interface priority, efficient transmission, and good compatibility make it the de facto standard for service communication in the cloud-native era. It is also endorsed by Google and is the core of CNCF. one of the items.

gRPC mainly has four communication modes, which can be flexibly selected according to the actual business scenario, namely:

· One-way RPC (unary/simple RPC)

· Server-side streaming RPC

· Client-side streaming RPC

· Bidirectional streaming RPC

Zhenglai also demonstrated a simple gRPC HelloWorld application on the real machine, and compared the similarities and differences between gRPC and other communication frameworks, and listed the Pros & Cons of different frameworks. Let us compare gRPC with other frameworks such as REST and the same RPC framework The features of Thrift are well understood.

 Later, Zhenglai gave the reason why Tubi uses gRPC, which is equivalent to a summary of the excellent design points of gRPC:

· Service definition rather than resource definition, suitable for various business needs (more convenient for domain modeling)

· Strong type constraints, reduce development and maintenance costs, and improve engineer productivity (in line with Type Safe design requirements)

· Multi-language support, different teams can choose a more suitable programming language according to business needs (more tools can be used)

· Different teams can easily share service definitions through the centralized ProtoBuf code base (convenient for teams to maintain and uniformly model services)

ProtoBuf's efficient serialization performance and small serialization volume (in Akka, Protobuf is also used to serialize Whisper information between clusters)

· Native support for stream operations, making large data transmission more efficient (stream processing is really important in business scenarios)

· Good performance, can support high-throughput and low-latency services

· The community is active and the ecology is rapidly maturing

· Kubernetes is tightly integrated and can use functions such as HealthCheck and service discovery

Tubi Akka-gRPC migration

Tubi's internal services built using Scala rely heavily on the Akka framework. After Akka-gRPC matured, due to its excellent performance and practical features, the Tubi team began to migrate its gRPC services from gRPC runtime to Akka-gRPC.

Zhenglai also gave the corresponding Performance Benchmark. Migrating Akka-gRPC can make the system have better performance and stability under high load. The main benefit at this stage is the improvement of maintainability.

Regarding the impact of Akka's replacement of LICENSE, Zhenglai said that Tubi will continue to cooperate with Lightbend and use Akka's related services.

——The above sharing is from Ken

Through Zhenglai's sharing, I learned what Tubi's specific Scala application is like. It is a more practical sharing, and I feel that it is much better than just looking at the theory.

——The above sharing is from Alpha

Scala and functional programming

@Yuan Yang

 First, it introduced the Tongxiang project hatched by Beijing Zhiyuan Artificial Intelligence Research Institute - AI + auxiliary diagnosis system of traditional Chinese medicine, which provides doctors with the help of clinical auxiliary diagnosis, optimizes efficiency and diagnosis accuracy. In my opinion, this is a very interesting application point, and it is developed by Scala and Typescript (it seems that Mr. Yuan pays attention to Type Safety).

The most impressive thing is that when explaining the overall structure of the project, the title given was "Category Theory Theoretical Support". I don't know if a small hole was dug here to lead to the sharing of concepts related to category theory in subsequent speeches.

 Then Mr. Yuan explained the related concepts of functional programming, let us understand why side effects should be managed, and how is the best practice of functional programming.

Functional programming is rigorous, and it is more like a framework for dealing with problems to help us build businesses and applications more scientifically and effectively. We need to clarify the data and their format first; then define the conversion logic between different data, that is, the function to realize the conversion operation; finally, according to the business logic, connect these functions together.

According to my personal experience, in the process of implementing conversion operation functions, the main functions can be defined first according to the large framework of business logic, and then decoupled layer by layer. Finally, it will be found that the core function can be composed of several small functions.

The advantage of this is that it can make the written components have better composition and logical reusability; for side effects, we need to push them to the outer layer of logic as much as possible, first maximize the core logic layer, and finally Refocus on side effects.

Just imagine, if more than 70% of our core code is about the processing logic of functions with side effects, it will produce a very bad reading experience when understanding the code logic, and it will appear very verbose, because Almost none of what we see is what we want. A possible approach is to get through the core logic first, and then focus on managing side effects at the end.

Teacher Yuan mentioned that such a development paradigm will have a good correlation with AI automatic programming. In fact, it is not difficult to find that it is clear to describe the problems he needs to solve to AI through the method of functional programming. This may be seen in the future. More AI applications help developers improve efficiency (CodePilot and chatGPT are good examples, very powerful!); programmers can make their work more meaningful while realizing more value, and It is not mechanical duplication of labor.

 Next, Mr. Yuan explained the concept of Monad and IO Monad through a "box model".

Teacher Yuan’s explanations are very easy to understand. One of the most interesting examples is to compare Monad to a specific plan for doing something. It is also a box containing something to be done and its result; but the planned Execution is variable (has side effects, different results when executed at different times or places); each step in the plan will generate a new box, but it will not be opened immediately, there may be side effects in this box, But we also know that there may be something we want in it, which allows us to complete our design and implementation in a "what if" state, and finally deal with side effects.

The generation of the plan is a pure function, but the execution of the plan is not. We use Monad to make it possible to implement it in a pure function at design time, while retaining the ability to manage and control side effects.

 Finally, Mr. Yuan quickly went through the Type Classes in the Cats Library, and introduced the open-source Flag Boot microservice development library of the Zhiyuan team and the Benchmark comparing the Spring Boot framework. I look forward to Flag Boot getting better and better!

——The above sharing is from Ken

Teacher Yuan Yang's sharing was very inspiring to me. He used a new metaphor to explain Monad. It feels very vivid and understands Monad better.

——The above sharing is from Alpha

Scala in Interactive Notebooks

Teacher Li Feng's sharing let me know that Scala can be applied to so many fields, and learned about many interesting and practical Scala libraries, which I have never used in my work before. The teacher's enthusiasm for programming and dedication to the profession also infected me!

——The above sharing comes from Z

Teacher Li Feng shared a lot of content, and I feel that the research is more in-depth. For me, because I have never been in contact with it before, it is challenging to understand, but it is very good that Teacher Li Feng also shared what I have accumulated over the years. The document can be understood slowly later.

Regarding how to learn Scala, I was very impressed by Mr. Li Feng's sharing. Especially the need to generate the motivation to learn. This demand can be business, work development needs, or personal interests that want to broaden the boundaries.

——The above sharing comes from the construction next door

Application case of Scala in Tubi

Build a fully responsive ad serving system using Scala and Akka-Stream

Handling ad auctions with Scala and akka-stream

Scala Meetup past recommendations

【Event Review】June 2022

【Event Review】January 2021

【Event Review】September 2020

【Event Review】April 2020

Join Tubi  to create better services with Scala!

Guess you like

Origin blog.csdn.net/weixin_49193714/article/details/128729285
Recommended