My Journey into Rust


My last contact with enforced typed languages was with C and C++ on the university and with Go and Typescript on 2022.

Althought I love the backend environment and your challenges, Rust felt like everything we wanted.

Why Rust?

So, in recent years I have been working with robust technologies such as Python. I can easily find components or even libraries that make my development easier. However, we still faced limitations as even following good practices and other paradigms, applications ended up suffering from unexpected bugs and behaviors. I am not going to get into the merits of discussing which is better.

But safety and performance caught my attention, and I was following the Rust community closely in January, observing how it’s backend ecosystem was doing.

PS: In my opinion, just because you’re building a small application “yet” doesn’t mean you don’t need safety and performance.

Learning Experience

I started with a simple hello world 🤣. I did a short workshop just showing from my team some concepts about Rust I learned. But the journey to get the basis is short if you have any contact with typed languages.

However, Rust has important concepts and rules to understand and you need to practice a bit to get all those rules and different concepts like ownership and borrowing.

I think the game changer for me at this point was the platform Exercism. You can practice a language with good exercises testing lot of concepts about Rust, and the best for me there, is the mentoring feature, where you can ask for another developers to evaluate your code and help you if you got stuck on something. I would say that you will be already in Rust maybe in 3 months practicing every day on Exercism. I’m considering that you already program in any programming language.

Building a Real Challenge or App

I had the best challenge I could. I was working on a project, a MVP. This MVP was bought in India and was wrote on PHP using YII Framework. I never used this technology, and I decided to rewrite the entire application using Rust, backend side.

In my learning experience I never created an API or something like that using Rust. So, I accepted the challenge and as I was working alone on this project it would be interesting.

My goal was deliver the same MVP with some more features added using Rust and hosted on AWS with the same architecture and infrastructure. The app wasn’t a huge application, just an API using a database to persist the data, and websocket to work with RTC for video meeting.

Comparing with other languages

I did something similar with Go and I had a good progress, but with Rust I felt almost the same complexity to create an API.

package main

import "fmt"

func main(){
  fmt.Println("Hello world ;)")
}
fn main(){
  println!("Hello world ;)");
}

I like the approach to write an API without imperative rules to follow like almost all the frameworks to work with web development. I used to write API’s using clean architecture. With Rust you can follow clean architecture easily.

You can learn about a project using clean architecture with Rust here. Thinking about the future, maintaining an architecture in your project that will allow you to add new architectural layers and separate business logic is essential.

I thinks it’s important to mention that compared to Golang, the development curve is very similar. But if you are coming from Python using frameworks like Django for example, you will feel your productivity drop out a little bit. It will take you longer to build simple endpoints, if you use good practices.

Challenges Faced

Clean Architecture

Probably the first challenge I had was the organizing and routing. I did some experiments using Rocket, which is a web framework with a different purpose, the main Idea is be a like Rails framework using Rust.

But I was looking for something less imperative, something like Flask Framework or maybe like go-chi. I chose to work with actix-web, besides being a powerful framework that will provide you everything you’ll need for most web projects, it is a micro web framework without being imperative.

I found a book with valuable teachings and experiences using rust. Zero2prod is the perfect book for who knows how to create a web application end2end in another programming language using Rust. You won’t find about paradigms like clean architecture using Rust. However you’ll learn how to understand the entire Rust web ecosystem and it’s libraries that will help you build your product.

I didn’t have much difficult with relational and non-relational databases. In the case of my challenge I was using Postgres and Redis for cache. I got it’s done faster and smoothly.

Some important details and insights, you will have to take care of numerous aspects of your application, including observability. Which, if you’re not working with Golang in the Backend, will be a little strange for you at first, write your telemetry module to take care about your logging for example.

Deploying your Rust application will be the easiest part. If you uses Docker, Cargo will provide you a binary and you can run it where you want. I recommend use AWS Fargate, AWS ECS to run it with an application load balancer to provide you a solid and safety infra to work well.

Cargo is the NPM for Rust environment. Cargo is very huge and powerful, you’ll love it in your first day writing Rust code.

Impressions on Rust for production

Well, I could learn Rust, just for web environments with this challenge, but trust me, I never saw something robust and something that you can trust like Rust.

The application is running without issues or problems related with the implementation. Which left me surprised that I didn’t find any problems related to dangling pointers or something like that, considering that I was just starting out with Rust.

Regarding performance, Rust proved to be very good compared to PHP where the API was written. We are still iterating with the users and seen the performance. So far, I loved Rust on production.

I am confident in use Rust in my projects, I’ve already seen the process of writing a market-ready API from scratch. And I’m comfortable to introduce Rust on my team.

Rust Community and Ecosystem

Well, right here is the most active community I’ve seen for now. I was able to ask to many software engineers and developer who are using Rust in different communities. Whether on Discord, IRC or Telegram. I’ll leave the ones I use most currently.

Discord: https://discord.gg/rust-lang / https://discord.gg/rust-lang-community

iFood Rust

I was also very happy to see that there are large Rust communities in Brazil, the Telegram group already has more than 1.000 members. Important to mention which there are companies using Rust in Brazil, whether small companies and Big Techs such as iFood.

As I said, I found tons of communities with Rustaceans talking about Rust and your own challenges with that.

You will find a wide range libraries ecosystem. If you need to work with routing, Http requests, Restful, Websockets, you will easily find a crate to complete your challenge. I will leave the registry link so you can search for important libraries for your world.

Conclusion

I consider that I have managed to learn Rust, I’m still starting, but I will stick to Rust in new projects and will deal with my challenges using it when I can. I was embraced by the community and I was able to have all my doubts resolved and I was able to understand why Rust.

If you are looking for something different and challenging, Rust is the answer. If you are looking to improve yourself with computer science, Rust is the answer. If you are looking for put safety in your applications in a new way, Rust is the answer. Or maybe if you just are looking to learn a new programming language, again, Rust is the answer.

I can confirm, write Rust code is addictive. All the time I want to write something in Rust 🤓. I encourage you to accept the challenge and start with the Book, you will probably hear a lot about it.