API JSON built in Rust that periodically consults the Mempool lightning node state, process the data, and stores in a PostgresSQL database. The API features a GET method to retrieve the node's data from the database.
- PostgreSql (Supabase)
- axum = "0.8.4"
- tokio = "1.45.1"
- diesel = "2.2.0"
- chrono = "0.4.41"
- serde = "1.0.219"
- dotenvy = "0.15"
I chose the stack inspired by Guilherme Salustiano's talk, that showcases the Diesel Internals.
- Rename the .env file and configure your Database URL
mv .env.example/ .env- Setup the project through the Diesel CLI
diesel setup- Run the migrations
diesel migration run - Run the project
cargo run My goal was to implement the solution while learning and understanding the structure of a back-end built with this new stack. Some challenges I faced during development were:
- Researching the stack and figuring out how to integrate all components
- Learn how to iterate on the JSON structure (reference)
- Type
PgNumericandDateTimein the the table struct, it was conflicting when applyingserdemacros
I spent 4 days: the 1st day studying and choosing the stack; the 2nd day creating demos and the 3rd and 4º building the solution.
My learning repo, which includes the study materials I used and demos, can be found here:
- I chose to use Supabase PostgreSQL to avoid additional local database setup.
- Drop from Numeric type to Float in the capacity column, due to errors working with the
structandPgNumeric
With more time I would:
- Type more the code;
- Handle better the possible errors;
- Containerize the solution;
- Implement better concurrency with diesel_async and tokio::join;
- Create tests to measure the performance, errors and security;
- Add a telemetry feature for application monitoring.
The concurrency part