Hi,
I'm currently facing a pretty interesting problem regarding super long compile times.
As mentioned in the title the goal is to transform a project from microservice architecture to a monolith.
Every microservice uses Axum as web framework and has the following directory structure:
src/
├─ db/ // Implements database access logic and defines data structure.
├─ services/ // Use functions from "db" to implement business logic.
├─ routes/ // Use functions from "services" to define route handlers and exposes a router.
├─ errors/ //
├─ util/ //
main.rs // Combines router(s) into one main router.
The first attempt to merge the services into a monolith was to create a workspace and put every service with its exact directory structure (like described above) into it as a crate. In addition to that I added a crate called app
which is the only executable of the workspace and contains the main.rs
file, which combines all the routers from the modules. This attempt unfortunately failed, because the data structure structs being defined in every module and being used somewhere else created cyclic dependencies.
Because of that I changed the structure a bit to get something like that
db/
├─ users/
├─ resources/
├─ customers/
|
services/
├─ resources/
├─ customers/
|
routes/
├─ .../
This helped compile times a bit but still a clean build is roughly 4 minutes (for over 500 The micro services compiled much faster even though they have almost the same dependencies.
Which project structure do you prefer? Tbh I like the first one better because the project would be split up into models like the microservices but the cyclic dependencies make it impossible.
What I found out is that the "routes" crate now takes roughly 1/3 of its time (~40s) only to link.
Could it be that the nested router from Axum is a problem in this regard or might there be a general problem with our code?
Tank you very much in advance