Building a Production Backend in Rust

Sep 19, 2024
KK
Shivam MathurSenior Developer

I've been working with Rust for a few days now. My main goal is to be able to use it for production systems, reducing my running costs while also providing durable and robust systems to my clients. To that end, I have been exploring Rust web frameworks and evaluating their suitability for my needs.

Exploring Rust Web Frameworks

Here are the frameworks I’ve experimented with so far:

Why Poem Stood Out

Among these frameworks, Poem has been my favorite. One of the standout features of Poem is its integration with poem_openapi, which simplifies the process of adding Swagger documentation to your project. Other frameworks required additional code to achieve this using utoipa, but Poem made it straightforward.

Loco also showed promise, but it’s not quite ready for production use. While Loco's Rails-like system is intriguing, I found it more efficient to build my server with Poem and SeaOrm. As a beginner with Rust, the learning curve with the borrow checker was challenging, but I'm gradually getting the hang of it.

My Rust Web Server

After a few hours of effort, I created a basic Rust web server, which you can check out here. This server was inspired by a system I built for my previous startup. My goal was to develop a system where capabilities could be added or removed as needed, ensuring flexibility and ease of maintenance. The original system was designed with heavy influence from Object Oriented Design Patterns and I've been able to translate the same into this using struct and impl.

Future Plans

This project is a work in progress. I aim to build a comprehensive backend system that includes all the essential capabilities needed for any product:

  • Authentication
  • Data Access Layer (DAL)
  • Scheduler
  • Background Workers with Message Queues
  • In-app Notifications
  • Emails
  • Payments
  • Logging
  • Monitoring
  • Organization Management

I have already implemented these features in a NestJS server, so this project involves translating and updating that system into Rust. Once completed, the only addition required to launch a SaaS server will be the unique business logic, with the foundational capabilities already in place.

Conclusion

Working with Rust for backend development has been an enlightening experience. While the learning curve is steep, especially with the borrow checker, the language’s performance and safety features make it an excellent choice for building robust and cost-effective production systems. Poem, in particular, has proven to be a valuable framework, and I look forward to seeing how this project evolves.

Stay tuned for more updates as I continue to build and refine this system!


api
 
article
 
backend
 
experiments
 
rust
 
saas
 
web-development