Author: Marella | Founder of wolai.com
Our daily work scenarios are almost inseparable from "cloud documents". At present, people's demand for documents is not only simple records, but also extends to office collaboration, information organization, knowledge sharing, etc. Among many online documents in China, wolai has entered people's attention as a unique existence due to its new functions, fast iteration, smooth remote collaborative experience, efficient information organization, and information integration of "information blocks". People pay attention to the unique functions of wolai and the comfortable user experience of users, and pay more attention to the technical architecture behind these realizations. On a fine afternoon, we invited Marella, the founder of wolai.com, to chat with us about the serverless architecture behind wolai.
Why did I choose a serverless architecture?
At the beginning of the product "wolai", we hoped to put the architecture completely on Serverless. Therefore, in the stage of technology selection, we conducted a detailed investigation of several serverless products at home and abroad. We found that Alibaba Cloud Function Computing (FC) has outstanding advantages in terms of support and overall solutions, and it is very suitable for our needs. Therefore, we decided to choose the serverless architecture and fully use Alibaba Cloud Function Computing (FC).
As an office collaboration application, wolai has the function of multiple people editing documents online at the same time. To achieve this function, a very stable Web service interface and a distributed database with scalability, support for high concurrent writes, and read separation are very important. Therefore, when we found that serverless products can be well matched with distributed databases, we initially confirmed the main structure of wolai.
Next, we started to verify the feasibility of using Alibaba Cloud Function Compute (FC) on Alibaba Cloud. Through verification, it is found that Alibaba Cloud Function Compute (FC) can not only help us solve the above problems, but also help us greatly save the investment in labor costs and cloud resource usage costs.
Take a startup as an example and talk about functional computing
Next, I want to talk about why I insisted on choosing the serverless architecture when I started the company. I used to work for a payments company, so I'll use a more typical payments company as an example.
Inevitable traffic scaling problem
Suppose you create a payment company, and it needs more than 200 systems behind it. If most of these systems are based on Java, it means that the machines behind the payment business are clusters of one by one. These clusters need to be grouped and then online and offline one by one, which requires huge labor costs.
In addition to cluster grouping, developers also need to pay attention to whether there are bottlenecks in each intermediate system such as the cache and log system. Once a problem occurs, it needs to spend a lot of energy on the entire operation and maintenance system to solve it. With the development of the company, the service level of your company has finally increased. At this time, you will find that the cost has also increased significantly. For example, you need to deploy new machines, and you need to spend a lot of time to do calculation scaling. Work (to be exact, it's just "stretching", there is no way to "shrink", right?) So the problem of traffic scaling will be the first problem you encounter, and it is also an inevitable problem.
The problem of peaks and valleys of traffic
Next, you will also encounter the problem of peaks and valleys of traffic. Since there are fewer payment requests at night, the concurrent number of payment requests may be particularly high during the day or during big promotions and spikes. If a large amount of traffic flows in at the same time, you need to allocate computing resources quickly, which requires a lot of operation and maintenance work.
For a new company, it's hard to put a lot of effort into operating servers. At this time, you can choose Serverless, which can help you solve the above problems. You can safely "throw" the work of operating and maintaining the server to Serverless, and all you really need to focus on is your own business logic.
I can just focus on the code and the client's needs
In the past, when we did web services, the focus of development work was to do various optimizations on web servers. In fact, these works were all to solve a problem: after the equivalent level goes up, can the performance of the server be able to withstand? If not how to optimize? Developers spend a lot of time doing complex optimization work such as Nginx performance tuning, load balancing, reverse proxy, etc. When we use function computing, it is equivalent to removing a large part of the work of tuning web servers. , which greatly saves labor costs and improves efficiency. After using function computing, from development to launch of the entire service, most of the research and development can focus on the business code, without worrying about how the service itself runs stably.
Since the service was launched on June 15, 2020, we have never encountered the problem of service downtime or offline maintenance. These problems are common problems before using function computing. In the past, once we encountered such a problem, we needed to spend a long time to find the cause of the problem. We may need to upgrade the web service, add a few machines, or even do reverse proxy and load balancing... Even if all these tasks are completed, we can go online again. There will still be maintenance periods for our services, and it is still difficult for us to keep our services online. Therefore, a very important function point of function computing for me is the ability of continuous service. By using function computing, my business can be released stably and continuously incrementally.
When I was working at the last company, I did a version release every two weeks, and each release had a very detailed release list. The release involved a lot of conditions and dependencies, and the scripts that needed to be operated and maintained were very complicated. One little mistake, and the entire release can turn into a small accident, or even a big one. When we put the entire architecture on Serverless and split all functions, the probability of accidents is greatly reduced. Even if something goes wrong, I can fix it by rolling back quickly. Now our R&D habit is to release at least one version every day, and all the problems solved that day will be released. Compared with traditional software companies, our iteration speed will be much faster when deployed on a serverless architecture.
Snapshot saving system to solve the problem of collaborative editing algorithm
For collaborative office products like wolai, collaborative editing is the top priority of the product. This function has high requirements for algorithms. We also solved this problem well by using function computing.
Wolai cloud note function has a concept of information block (Block), which is to reduce the smallest unit of information that users can access from 'file' to 'information block'". "Information block" can accommodate text paragraphs, tables, lists, As well as embedding pictures, videos and other information from outside, and can be easily edited, moved, and rendered in real time to form a page. So next I will use "block" to refer to information blocks.
Above the red bottom are independent blocks
After each keystroke by the user, our front end will have a snapshot-like saving mechanism. If the user presses the key very fast, his multiple key press operations may form a transaction in a certain time slice and send back to this function for calculation. Then we log these actions. When a second user presses a key at the same time, if he also presses a key on the same block, he will also trigger the same operation.
We will calculate the order in which these operations users actually affect the block in the function, and finally get what it should look like, and then the function calculation will also issue a queue request, when there is any block, or After the page it belongs to has this change event, it will be dropped into this redis. Once a block or a page has been updated within 5 minutes, we will call another function to remove the entire page and the entire block. Generate a snapshot one by one. So we combined function and queue calls into an automated system.
Once a user edits a page or block, we will generate a snapshot at a fixed time period. We now save a snapshot per minute for a single block (equivalent to the smallest unit of a single paragraph of text or a picture). It is equivalent to within 1 minute, as long as the user has an update, we will turn it into a snapshot as a whole, and then put it on the OSS. If each block is updated frequently, then there will be an extra one-minute snapshot for this block on the OSS. At present, we have more than 1 billion files on the OSS. If it is page-level editing, wolai saves snapshots in 5 minutes, and the frequency will be lower. By combining function computing and queues, we have created a snapshot saving system.
Wolai's Serverless Architecture Diagram
Problems solved with Serverless
By studying the user behavior of wolai, it is found that our user generally opens the wolai document every morning when he/she goes to work, and then he/she will continue to use it throughout the day until it is closed after get off work. Our users don't need to quickly open an app and then go away like a Mini Program user. On the contrary, they don't have particularly high requirements for the initial loading speed of the application, so our focus is not on server-side rendering issues. By studying user habits, we pay more attention to the question of whether users can respond quickly to each step of the operation after opening the app, which involves two points:
1. The user sends data to my server. Can the server receive the data quickly and stably?
2. When there is a lot of concurrency, will the response speed be slowed down?
Function decoupling, allowing small teams to exert great energy
By using function computing, wolai's front-end engineers can take charge of the entire development process from front to back, and our R&D iteration speed is very fast.
In order to achieve rapid iteration and save manpower, we split every small function point of the application into a very small part, and deployed a lot of services in function computing. At the same time, there will be multiple functions under each service. way to achieve functional decoupling. The advantage of this is that when we need to release, if we only do some optimizations or bug fixes for one function, we only need to release this function, and we don't need to do the overall release at all. Therefore, we can quickly accumulate releases every day, and most functions are completely decoupled and do not affect each other. We try to completely separate all functions into independent business logic. This can ensure the speed of development iterations.
At present, there are 10 R&D engineers in our team. Eight of them are front-end engineers, which greatly improves the efficiency of the team.
Small Businesses Save 50% Using Function Compute
When selecting the model, we have made a rough calculation of the cost of using function calculation. The result of our calculation is that the use of function computing can save more than half of the computing cost compared to using the traditional framework, and the human input can be saved by half or more.
We can calculate an account. If we choose the traditional architecture, with the complexity of the current system, our application needs at least two operation and maintenance engineers. Now front-end engineers can develop and maintain the system from start to finish. Calculated according to the monthly labor cost of 30,000 yuan, including the cost of venue and hardware, for small companies, at least 700,000-800,000 operation and maintenance costs can be saved a year, and the cost of computing resources will also increase simultaneously, that is It is said that if it costs 1 million a year to use the traditional framework, it can become at least 500,000 using functional computing.
Since its launch in June 2020, the process of using function computing for wolai has been very smooth, and it took a very short time from model selection to completion of the project launch. I am very grateful to Alibaba Cloud for making such a product. Today, the division of labor between people and cloud computing has become more and more clear. I believe that with the blessing of serverless technology at the computing level, especially the resource scheduling level, more and more enterprises can no longer pay attention to resources, but focus more. on how to provide better service to customers. Looking forward to the future, Wolai will be able to make better products together with Alibaba Cloud Function Computing.
Serverless is gaining momentum. Faced with the upcoming changes, developers hope to quickly absorb serverless knowledge and apply its advantages to their daily work. To this end, Alibaba Cloud's cloud-native serverless team has launched a new "Serverless Technology Advanced Study Class", and specially invited serverless technical expert Jiang Yu as a leader to lead developers interested in serverless technology using a class system to jointly study the 2022 edition of "Serverless Technology Advanced Study Class". Serverless Development Cheat Sheet. Become classmates, friends, and technically advanced comrades with us, and learn to develop serverless enterprise-level applications in 10 days with 0 basics.
Currently in the admissions phase, join anytime until May 27th. Participate in the camp and complete all check-ins to obtain a certification issued by Alibaba Cloud Developer Academy.
Click here to start learning now!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。