A Full-Stack Monolith Forum on Rust, Sycamore + Axum + GraphQL + SQLX: A Study

80 points MadScientistCarl

TL;DR

I built a demo forum on pure Rust stack with WASM, GraphQL, and SQLite. DON'T USE IT IN PRODUCTION!

Longer version

Over the past weeks, I attempted to build a monolith forum (almost) purely on Rust, full stack from backend (async-graphql on Axum) to frontend (Sycamore on WASM). The repo is included below, along with a slightly longer report:

https://github.com/rongcuid/gqlforum-rs

DO NOT EVEN THINK ABOUT DEPLOYING IN PRODUCTION!

This is only a minimum demo! Its frontend doesn't even implement all functionality of the backend! However, what this stack do support, are:

  • Built-in password authentication
  • Server-side sessions
  • Basic authorization/access control
  • Absolute minimum UI
    • Log in/log out
    • Posting a topic
    • Replying to a topic

The backend has a few more functions, like registering a user, changing password, deleting posts and topics, etc. I just lost enough sanity to decide not to implement those.

What I find good:

  • Low resource usage. Something like 12MB memory use
  • Latency seem to be good
  • Sycamore is surprisingly pleasant to write... when I am not fighting the borrow checker or procedural macro expansion

What I find bad:

  • All those Layer's, Context's, and Extension's feel like a more cumbersome Monad Transformer without the compiler check and do syntax. Come on, shouldn't there be another way?
  • Making the frontend and backend serve from the same URL is really head-scratching
    • Trunk proxy causes a redirection loop
    • Serving separately has CORS problems
    • Axum's SpaRouter does not work for serving the root URL
    • I ended up manually syncing routes on frontend and backend
  • Axum and async-graphql don't work well together when you want to modify some state in async-graphql and have it seen in Axum. I ended up have to implement cookie signing myself because of this
  • WASM ecosystem doesn't have very good documentation to tell me where to find libraries
  • WASM binary is quite large, and grows fast