Writing a proxy in Rust and why it is the language of the future

Terry Raimondo
Jun 22, 2019 · 4 min read

It’s been a year since I wrote a little proxy with Rust, it is one of my first projects with this language and I learned a lot writing it. To sum up a bit, the main goal of this proxy is to be really simple to use and easy to extend with middlewares. It targets HTTP APIs and can be used in front of a lot of services. This proxy has been used in multiple projects, with microservices architecture and so on…

Why this proxy ?

As said earlier, we are working on a micro-services architecture. The first thing I needed was an authentication mechanism, we chose to use JWTs and added a service to generate and sign those. As I wanted to avoid asking this service if the provided token had the right signature for each request, I had to find another solution, what about a proxy ? It would also allow us to route our requests to the right services, log the requests, add CORS and so on…

The real deal here is that I can forget it once set up, it is not coupled with other services and is really light.

It is based on hyper, a solid and async HTTP library. I know my implementation may not be the most efficient, but it works, it is light, easy to use and extend, and my goal was not to write the perfect piece of software but something fitting my evolving needs. It has not the pretension of being a real fatass proxy like sozu.

How to use it:

I left some middlewares included in rs-simple-proxy like Logger or Router. Here, Auth middleware is a custom one.

What a rs-simple-proxy middleware looks like ?

Didn’t ask but got a good performance

The thing is, I never focused on the performance writing it, at first it was a test project to understand and see how we could leverage the awesomeness of Rust in our stack. It wasn’t meant to handle thousands of requests per sec. Guess what ? Side effect of Rust, it does.

When we benchmarked the part where rs-simple-proxy was used in production, we were instantly surprised by the results, when you come from the Ruby world, you know how to handle performance issues, cause you know… you’ll have some, you have to do some caching stuff, add workers so you can spin up more instances and such things.

This little project convinced me to go all-in Rust. I would not write a web service in Ruby anymore.

Rust is the future

Image for post
Image for post

Rust allowed me to build anything with approximately 0 worries.

  • It is not painful to write since there is no boilerplate depending on what you build, for example, rocket allows you to write web apps/apis in an awesome and fast way. see https://rocket.rs/.

And now what can’t I do with Rust ? Tell me. Since this proxy, almost all of my projects have been written in Rust, and although it is not really straight forward to write front apps with Rust, it is possible and will become more and more straightforward with the growing ecosystem of WASM (WebAssembly).

A big thanks to the Rust community.

The Startup

Medium's largest active publication, followed by +717K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store