This week I came across axum, an open-source Rust library, that helps you build HTTP servers, like a REST API, or a Websocket API.
Axum is, according to benchmarks (I haven’t tested it myself yet) WAY faster than FastAPI (something like 10x).
So I decided to take it for a spin, and try to build something with it.
What to build?
In 2 weeks I will start teaching (again) the 4th cohort of my live course, and I wanted to spice things up, and build one of the components of the system using Rust.
More precisely, the final serving layer:
This is essentially a CRUD app (Create Read Update Delete) app (mine only Reads), that
listens to incoming requests from client apps. For example, what’s the predicted price for ETH in the next 5 minutes.next 5 minutes),
fetches the relevant data from a Postgres DB (our feature store), and
returns the prediction back to the client
As I started coding I realized it would be useful to record myself, as I do in my live coding sessions, and share the entire building (and thinking) process with you.
Zero edits.
Step by step (at least I tried :-))
From idea to working software (not fully testes, but not bad either).
All the source code is in this repo.
And all the video lessons are on my Youtube channel
Steps
These are the steps I followed build this REST API.
Step 1 - Welcome to the challenge
Step 2 - Bootstrap the project with cargo
Step 3 - Hello world with /health endpoint
Step 4 - Refactoring the imports with `use`
Step 5 - Add /predictions endpoint
Step 6 - Split code into separate files
Step 7 - Set up Postgres DB locally with Docker
Step 8 - Connect Rust with Postgres with sqlx
Step 9 - Load config parameter as environment variable.
Step 10 - Add GET parameter to /predictions endpoint and compile for release.
Wanna build an end-2-end ML system with me?
Building ML systems is hard. But super fun.
In 2 weeks, in the next iteration of Building a Real Time ML System. Together, 328 brave students and the same guy from the videos above, will build and deploy a real-time ML system on Kubernetes.
And one of the services will be very similar to REST API we built today.
It will be a tough, but a very fun ride. And you will learn tons of real world ML and LLM engineering.
Talk to you next week,
Enjoy the weekend,
Pau