Notes on production deployment of a simple static site using Actix

Just deployed an Actix web project to production yesterday. The deployment looks like:

        User   →      Nginx       →        Actix
                 (SSL Terminate)     (Askama Templates)
                 (Serve JS/CSS)      (Postmark Email API) 
                                            ↑
                                     (systemd service)

Everything is deployed on a $5 VPS and it's working like charm! Since it involves a static website with couple of forms and email dispatch, Django felt like an overkill.

Wanted something with a light weight backend (no sessions/auth etc.) and absolute control over HTML/CSS along with proper template hierarchy and therefore builders like Jekyll and Hugo were ruled out (I am not too familiar with them either). Zeroed in on Rust + Actix with Askama for templates. It's very Jinja like and suited the use case.

For now, I am using deploy keys to clone the repo on the server and build it there. Cargo takes about 13m to do a full release build (actix, serde, askama, chrono, reqwest and sha2 being the external crates) which is very reasonable given a (US) $5 box with just 1G ram. Cargo crashed the first time when the box had no swap configured but, with 2G of swap, it went smooth. The binary is executed via a systemd service and Nginx reverse proxies it.

The plan was to use Actix-files to serve the static assets (JS/CSS/Images) directly but, for reasons I could not yet figure out, Actix was not setting content type and encoding headers on the CSS/JS files and therefore the browser was rejecting them. Switched to serving them directly from Nginx.

From cargo new to successfully hitting the live URL in browser, it took approx. 5 hours (the HTML/CSS part was ready before hand). You can say Rust is fair at developer productivity. Been using the Rust plugin with Pycharm, though it's rough around the edges - it's getting there and (personally) find it a valuable upgrade to Sublime/Vim.

Google Page Insight gives 99/100 for Desktop and 97/100 for mobile. In Firefox dev console, I see a response time of 8ms and a full page load (with cold cache) of 244ms. Decent. Any significant speed-ups will likely disconcert the users.

While this was a static site with a lightweight backend, for something like a SaaS MVP, Rust (and the ecosystem) will probably never want to catch-up with Django (or Rails) but, nonetheless, it was a great to have something deployed live using Rust. Will look forward to augmenting this further and deploying new projects with Rust.

While it's a silly little project in terms of complexity or size, posting it here to get the conversation going around web workflows people are using in the wild with Rust. For example, would you rather eliminate Nginx from the above chain? Why? How would you go about logging? Or any other thoughts/points members want to put forth.

4 Likes

is it still running? what are your experiences so far?

Yes! No issues so far. Only change made since is to use env_logger to improve logging and that's about it.

1 Like