00 Preface Open Resty Opens the Gate to High Performance Development for You

00 Preface - OpenResty Opens the Gate to High-Performance Development for You #

Hello, I am Wen Ming, Chairman of the OpenResty Software Foundation. I previously served as a partner at a certain open-source commercial company and a member of the 360 Open Source Technical Committee. I have worked for an internet security company for 10 years, where I was responsible for developing cloud anti-malware, anti-phishing, and enterprise security products. In the next few months, I will guide you in systematically learning OpenResty.

Why Learn OpenResty #

Why learn OpenResty, this is the first question we will address. We are currently in a rapidly changing era of technology, and it is common to hear engineers joking that they can’t keep up with learning. People have limited energy, so there is an opportunity cost in choosing to learn a particular technology. The best choice is to start with the parts of your work that are involved, and learn in a practical way.

For server-side engineers, if your work involves NGINX, high performance, high concurrency, dynamic control, performance testing, and analysis, then regardless of the development language and platform, this OpenResty course will be beneficial to you. If you have not previously encountered OpenResty, I am confident that it will open the door to another world of server-side development for you.

OpenResty is a server-side development platform that combines development efficiency and performance. Although it is based on NGINX, its scope has long exceeded reverse proxying and load balancing.

Its core is a C module (lua-nginx-module) based on NGINX, which embeds LuaJIT into the NGINX server and provides a complete set of Lua APIs transparently supporting non-blocking I/O, lightweight threads, timers, and other high-level abstractions. At the same time, around this module, OpenResty has built a complete testing framework, debugging techniques, and a set of Lua-implemented utility libraries.

Using Lua language, you can perform string and numeric operations, query databases, send HTTP requests, execute scheduled tasks, and invoke external commands. You can also use the FFI to invoke external C functions. This basically satisfies all the functions required for server-side development.

By mastering OpenResty, you can enjoy the development efficiency and iteration speed of scripting languages, as well as the high concurrency and high performance advantages of NGINX C modules.

My Connection with OpenResty #

After talking about the features of OpenResty, how did I become connected to it? In fact, I first came into contact with OpenResty in 2012. At that time, I was in the process of selecting the technology for a new system. As a loyal fan of Python, I didn’t like the complexity of NGINX C modules but still wanted to obtain its high performance. How could I have both?

After searching for a while, I came across an article by “Big Aunt” ZQ in the Python community, introducing OpenResty. It was like finding a treasure. However, the excitement only lasted for a short period of time. Afterward, I was like a headless fly, blindly groping in the darkness. After stumbling countless times, I finally truly mastered OpenResty.

Unlike many engineers, I enjoy writing articles. I had been maintaining my own technical blog since university. One evening while working overtime, I noticed a colleague using GitHub to record his experience using ELK and publishing it on GitBook. It turned out that GitHub could be used to publish open-source books, not just code!

I was immediately inspired. That night, I created the outline for “Best Practices for OpenResty” and started “encouraging” other engineers to join in. We never promoted this open-source project, but it gradually became the best companion for beginners in OpenResty.

However, after joining OpenResty Inc., I gradually realized that there is a huge gap between being able to write correct OpenResty code and avoiding common pitfalls, and being able to write high-performance, high-quality OpenResty code. The key to bridging this enormous gap is scattered throughout the OpenResty open-source project’s source code, documentation, issues, pull requests, slides, and mailing lists. It requires you to connect them into a true treasure — a complete learning system and knowledge graph.

So, how can you systematically learn OpenResty? Many engineers have had this confusion in the OpenResty technical exchange group.

In fact, there are relatively few learning materials available for OpenResty. The official documentation only includes the API documentation and does not provide introductory or advanced documentation. The online resources that can be found are also not comprehensive. It can be said that the vast majority of OpenResty users are crossing the river by feeling the stones, a very painful process.

Therefore, I collaborated with Geek Time on this column with a clear goal — to allow you to quickly and easily get started and to paint a complete picture of OpenResty, helping you build a knowledge system and truly master this powerful development tool.

What background is required to study this column? #

OpenResty is built on the basis of NGINX and LuaJIT, so we certainly need basic knowledge of NGINX and LuaJIT.

However, you only need very little knowledge of NGINX to start your journey with OpenResty. To what extent? I introduce the relevant knowledge of NGINX in just one lesson. Even if you have never touched NGINX before, you can follow the pace of the course and gradually learn OpenResty.

It should be noted that OpenResty is not the same as NGINX. One of the purposes of the OpenResty project is to make you unaware of the existence of NGINX.

In terms of programming languages, Lua is a language that is easy to understand. As long as you can understand its code, you can complete the learning of this column, and you don’t need to be able to independently write complex Lua code. Similarly, I will spend a few lessons to help you get started with Lua and reach the level of using OpenResty.

Learning from Practice and Applying in Practice #

“Practice makes perfect” is a proper phrase when it comes to learning internet technology.

Unlike books that focus more on theory, the format of this column emphasizes practical aspects. Many of the codes featured in the column are derived from the test cases of the open-source project OpenResty, as well as actual open-source projects. By referencing these real-life cases, the aim is for you to encounter the best quality code and understand the most authentic usage scenarios from the beginning.

Additionally, I will incorporate multiple video courses within the column articles. The content of these video courses is based on the features and pull requests of actual open-source projects. Through these videos, you will directly witness how the knowledge you’ve just acquired is applied in real-life situations.

The final section of the column is our real “battlefield”. Together, I will guide you in building a microservice API gateway from scratch using OpenResty. According to our community statistics, nearly half of OpenResty users develop API gateways, with Kong and orange being the two most popular open-source gateway projects in the OpenResty domain. Would you like to build a simpler and higher performance API gateway from scratch? Let’s do it together.

Learning from actual open-source projects and applying your knowledge in actual open-source projects, integrating practice into a complete knowledge system - this is my teaching philosophy. I hope you enjoy this approach.

A tall building rises from level ground. Next, I will gradually help you master OpenResty. Enjoy!