Console #155 -- Interview with Yujia of rathole - high-performance reverse proxy written in Rust
Featuring Scrcpy, Caddy, and rathole
🤝 Sponsor
This space is reserved for sponsors that support us to keep the newsletter going! Want to support Console? Send us a note at osh@codesee.io
🏗️ Projects
Browse through open source projects on OpenSourceHub.io, add your project to get more exposure and connect with other maintainers and contributors!
scrcpy
scrcpy (screen copy) mirrors Android devices (video and audio) connected via USB or over WiFI, and allows to control the device with the keyboard and the mouse of the computer.
language: C stars: 82504 last commit: 4 days
repo: github.com/Genymobile/scrcpy
Caddy
Caddy 2 is a powerful, enterprise-ready, open source web server with automatic HTTPS written in Go
language: Go stars: 47000 last commit: 2 days
repo: github.com/caddyserver/caddy
site: caddyserver.com
rathole
A lightweight and high-performance reverse proxy for NAT traversal, written in Rust. An alternative to frp and ngrok.
language: Rust stars: 5080 last commit: March 27
repo: github.com/rapiz1/rathole
Join thousands of other open-source enthusiasts and developers in the Open Source Hub Discord server to continue the discussion on the projects in this week's email!
🎙️ Interview With Yujia of rathole - a high-performance reverse proxy written in Rust
Hey Yujia! Thanks for joining us! Let us start with your background.
Hi, I'm an undergraduate from China. I taught myself C language when I was a pupil because I enjoy creating things out of thin air with computers. Playing with software costs me nothing but brings me so much fun. In high school, I took part in competitive programming and got serval medals. In the university, I got bored with solving artificial algorithm problems purely synthesized for contests and then looked for real-world challenges. System programming fascinates me because it takes one's understanding of the big picture and the very detail at the same time to get things done.
Most code I write is in C/C++, and then Rust. To deliver UI, I sometimes write Typescript with React.
Who or what are your biggest influences as a developer?
Guys working on the Chapel programming language, namely my mentors: Engin Kayraklioglu, Paul Cassella, Krishna Kumar Dey. I met them in Google Summer of Code 2020, and they really showed me what is good software practice and how open source works. Up to today, I still benefit from the experience and use what I've learned in my daily work.
What’s your most controversial programming opinion?
I don't like Python at all. It's so error-prone without a type system. Maybe it's just me because I started programming with a type system of C. I see Python started adding type checking, but that's far from what I expected. I don't like Javascript for the same reason, but Typescript is fine for me.
Why was rathole started?
There are several reasons:
I have heard people ranting about frp. And I'm not happy with frp myself.
I see the trend of rewriting system software of Golang in Rust and agree with the benefits.
I think I can make a better one than existing software.
Frp is a tool that does similar things as rathole. First of all, I appreciate the work of frp's maintainers. It's a successful, easy-to-use tool that serves a great number of users. And I don't mean rathole is superior here. But some people, including myself, don't like some of its design choices, including the bad security model by default, and the bloated feature set.
For the second point, if a service is running 24/7 on my server, I don't want it to be something in Golang. The best system software is those you can't notice they're running. Especially on my 1G/1C, or even 512M/1C cheap VPS, I want every MiB of RAM to be useful. I don't think Golang should be there for Docker and Kubernetes at the first place.
How does rathole work?
First, let's start with two machines, one is accessible to the public, named Server, and the other one is behind the NAT, probably a box in your home, named Client. When a request from a visitor arrives the Server, the Server will send a control command to the Client through a long TCP connection established before. The Client will open another connection to the server, and serve the visitor. The Server will behave as proxy then. Note that all connections are initiated by the Client because of the NAT.
Can you explain the configuration options for rathole?
I think rathole#Quickstart already provides a minimal setup with an explanation.
Basically, you need to set up these things:
Tell Client where the Server is running.
For forwarding a service, tell Server which port to expose to the public, and tell Client which port the service is running at locally. Also, set up a password(token) on both sides.
Why did you pick Rust?
For better performance and less memory footprint. I think system software should be written in either C or Rust.
Why did you name it rathole?
I want the first letter to be R because of Rust, and rathole because it penetrates the NAT like a rat digging a hole through the wall.
Are there any overarching goals of rathole that drive design or implementation? If so, what trade-offs have been made in rathole as a consequence of these goals?
UNIX philosophy. I try to keep rathole only concerned about the NAT, not the proxying. If users request fancy features about proxy like hostname-based routing, and load balancing, I always tell them to use rathole WITH nginx, not instead of nginx. It makes rathole much more performant and flexible but requires the knowledge of nginx to achieve complex tasks.
Another goal is to deliver safety by default. It adds at least one more configuration option to fill. But it avoids being used to forward arbitrary traffic, which is a real risk for frp.
What were the existing projects like frp and ngrok lacking that made you consider building something new?
It's not about "lacking", it's about "better", or at least, better to my taste.
First of all, ngrok is no longer open source. I don't think there's a need to compare. Everyone loves free stuff.
As for frp, I've talked a lot about it above: the safety model, and the UNIX philosophy. One more thing I want to add here is the performance and memory footprint. You can easily beat Golang in memory usage with Rust. It's the low-hanging fruit. For performance, at first, I just wanted to see how far I could get with Rust. It turned out that a user told that he has 2x throughput improvement for the real-world workload. It's not only about the language but also about carefully designed protocol, de/serialization, and avoiding buffer copying. When developing rathole, I've learned the source of frp. Frp encodes each UDP packet into a JSON struct in the TCP stream, with UDP bytes encoded in base64. You can tell how the bandwidth is wasted. Inside frp, there are string/JSON/base64/bytes passing around in Golang channels, the cost of copying, de/serialization is also unneglectable.
Is rathole intended to eventually be monetized?
I don't it's going to be monetized. The market has already crowded with players like Tailscale, ngrok, and even Cloudflare tunnels and VPNs. I think ordinary customers need an easy network solution, not just a forwarding tool. Rathole is still for people who have a technical background and are willing to hack on their own.
What are you most proud of?
From the issues, I can tell some people are running rathole servers on their smartphones and using public IPs from 4G network. I've never thought of this kind of use case, but exactly suits rathole because of its good performance and low resource usage!
How do you balance your work on open-source with your day job and other responsibilities?
I work on open source in a sprint style. If I have spare time and interests, I will work intensively for a few days. After the first serval months of launching rathole, it's now very stable for current feature sets. The maintenance does not need much effort. So I can embark on new features whenever I feel comfortable.
Where do you see the project heading next?
TLS-related issues are still in my mind. It's very hard to deliver binaries considering there're many different TLS libraries and versions in the wild. So rathole requires re-compilation for some environments to use the TLS feature.
I always want to build an easier-to-use dashboard packed with nginx and rathole, but I have not found time to do so.
Are there any other projects besides rathole that you’re working on?
My university capstone project. I've designed a RISC-V CPU that can boot Linux and I'm writing a technical report for it to get my bachelor's degree. Also, I'm building a small business around LLM to help people to practice their oral English. It's not going well though.
Want to join the conversation about one of the projects featured this week? Drop a comment, or see what others are saying!
Interested in sponsoring the newsletter or know of any cool projects or interesting developers you want us to interview? Reach out at osh@codesee.io or mention us @ConsoleWeekly!