When to Split an Axum App into Services
A beginner-friendly guide to deciding when a single Axum application should become multiple services, and how to structure that split.
As a project grows, a single Axum application can start to feel like one enormous room where every feature shares the same walls, electricity, and plumbing. That works beautifully for a while. But eventually you may wonder whether some features should get their own separate room - their own process, their own deployment, their own lifecycle. The decision to split one app into multiple services is exactly that: you stop running one program and start running several smaller programs that talk to each other over the network.
This page is about making that decision. It shows a single HTTP call only as an illustration of what changes when a function call becomes a network call, not as a full guide to writing HTTP clients. It focuses on the why, when, and what it looks like at a high level in Axum. By the end, you will know what a monolith is, what a service is, and the concrete factors that push you toward one or the other. You will also see how a small monolith might be broken into separate Axum services, and you will be able to recognize when splitting too early would cause more pain than benefit.
What a Monolith Actually Is
A monolith is simply an application where all the code lives in one executable. When you build an Axum project as you have done so far, with a single main.rs that creates one Router and serves all your routes from one process, you are building a monolith. There is nothing wrong with that. Most successful software starts as a monolith.
Inside a monolith, features share the same memory, the same configuration, and the same release cycle. That sharing is the superpower: if the users feature needs to call a function from the orders feature, it can do so directly, without any network call or serialization. If the entire codebase is small enough for one person to understand, a monolith is almost always the right choice.
In Axum, a monolith might look like this:
// src/main.rs
use axum::{routing::get, Router};
async fn list_users() -> &'static str {
"List of users"
}
async fn list_orders() -> &'static str {
"List of orders"
}
async fn list_products() -> &'static str {
"Product list"
}
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/users", get(list_users))
.route("/orders", get(list_orders))
.route("/products", get(list_products));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
Everything about users, orders, and products lives in one file, one process, and one deployment. If you need to change the list_users handler, you rebuild the whole thing and restart one process. That simplicity is precious.
What a Service Means
A service, in the context of splitting an Axum app, is a separate executable that exposes its own HTTP API and runs as its own process. Instead of one process answering every request, you have several processes, each responsible for one slice of the overall system. For example, you might have a users-service that only handles /users endpoints, an orders-service that only handles /orders, and a products-service for /products. They each have their own main.rs, their own Router, and their own axum::serve call.
These services typically communicate with each other over HTTP, using a client library like reqwest. They might also use a message broker, but HTTP is the most common starting point. The important mental shift is that a function call that used to happen inside one process - get_user_from_database(id) - now becomes a network request to another process.
A split version of the monolith above could have three separate projects. One service, the users service, might look like this:
// users-service/src/main.rs
use axum::{routing::get, Router};
async fn list_users() -> &'static str {
"List of users"
}
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/users", get(list_users));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3001").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
The orders service would run on port 3002, and the products service on 3003. Each is a completely independent program. They can be started, stopped, deployed, and scaled without touching the others.
Why Splitting Exists at All
The reason anyone considers splitting is that a monolith eventually hits friction that has nothing to do with the quality of the code. The friction comes from the number of people working on the app, the different rates of change between features, and the different resource needs of those features.
Imagine three developers all working on the same monolith. Alice is fixing a bug in the users feature. Bob is adding a new endpoint to orders. Charlie is rewriting the products database layer. Every time one of them finishes, they have to merge their changes into the same codebase and deploy the whole application. Alice's small bug fix now ships together with Bob's half-finished feature because the deployment unit is the entire monolith. If Bob's code has a memory leak, Alice's fix is now also running with that leak. The coupling is no longer in the source code; it is in the release process and the runtime.
Splitting into services loosens that coupling. Each service can be deployed on its own schedule. Alice can ship her fix immediately. Bob can keep iterating without blocking anyone. Charlie can rewrite the products service in a different technology if he wants, because services communicate only through HTTP, not through shared code.
That independence is the core value. But independence is not free. You pay for it with network complexity, duplicated infrastructure, and the loss of in-process function calls. The entire art of deciding when to split is weighing that cost against the benefit.
A Starter Example: When the Team Grows
The most common reason teams split is that the number of people working on the codebase makes coordination painful. If you have five or more developers each working on unrelated features, merging and deploying one monolith becomes a bottleneck. Each service gives a team its own codebase, its own deployment pipeline, and its own area of responsibility.
A beginner-friendly way to think about this is the "two‑pizza team" idea: if a team is small enough to be fed with two pizzas, it can operate more independently. A monolith shared by eight developers is like eight people all trying to edit the same document at the same time. Each person's changes affect everyone else, and nobody can finish without waiting for a global review. Splitting the document into chapters - each owned by a different pair of people - removes that contention.
In Axum terms, that means you would take the single main.rs from earlier, copy the users-related routes into one project, copy the orders routes into another, and so on. Each project has its own Cargo.toml, its own set of dependencies, and its own team. The cost is that now the orders service cannot call get_user_from_database() directly; it must make an HTTP request to the users service. That network call introduces latency, a new failure mode (what if the users service is down?), and a need for an HTTP client in the orders service.
When Splitting Is a Bad Idea
Splitting too early is one of the most common architectural mistakes. For a solo developer or a team of two, a monolith is almost always easier to build, debug, and deploy. A network call between services can fail in ways that a function call cannot: timeouts, connection refused, DNS errors, serialization bugs. Debugging a distributed system requires tracing requests across multiple processes and log files. If you do not need that complexity, do not invite it.
A concrete warning: if your main reason to split is "I heard microservices are the right way to do things," stop. Microservices are not inherently better. They solve a specific problem - organizational scaling and independent deployment - and they introduce a new set of problems. For a project with only a few hundred lines of Axum code and one developer, splitting into three services would multiply the operational burden: three processes to run, three ports to remember, three health checks to monitor, and three separate deployments for every small change. The monolith would give you all the same functionality with zero network overhead.
Distributed Data Consistency:
One of the biggest hidden costs of splitting is what happens to database transactions. In a monolith, you can wrap a user creation and an order creation in a single SQL transaction - if one fails, both roll back. Once those two features live in separate services, each usually has its own database. Making changes across two services atomically requires a pattern called saga or outbox, which is significantly more complicated. If your features frequently update data together and require strong consistency, keep them in one service until that consistency becomes a problem.
A Checklist to Help You Decide
When you are unsure whether to split, walk through these questions honestly. A "yes" to most of them points toward splitting. A "no" to several means you should stay monolithic for now.
- Do multiple teams work on the app independently? If separate teams each own a distinct set of routes and rarely touch each other's code, splitting gives them autonomy.
- Do different features need to scale independently? If the products list gets thousands of requests per second but the order creation endpoint gets only a few per minute, running them in one process forces you to scale the entire monolith horizontally. Separate services let you run many copies of the product service and only a couple of the order service.
- Do features change at very different rates? If the users service is stable and rarely updated, but the orders service sees daily changes, separate deployments prevent the stable part from being redeployed constantly.
- Do you need to isolate failures? If a memory leak in the image processing endpoint can take down the whole API, splitting that endpoint into its own service means only that service crashes while the rest stay up.
- Do different services need different technology stacks? Axum is great for most things, but maybe one part of your system needs WebAssembly, or another needs a specialized Python library. Separate services can use different languages and frameworks.
- Is the codebase so large that no single developer can understand it? When the cognitive load of one repo becomes unmanageable, splitting reduces what each person must hold in their head.
If you answered "yes" to one or two of these, you might still be fine with a monolith. The threshold is not absolute; it depends on your tolerance for operational complexity. But when three or more become true, the balance starts to tip.
What Splitting Actually Looks Like in Axum
A Cargo workspace can hold several independent binary crates, each with its own main.rs and its own axum::serve call. You do not have to use a workspace - you could just create separate top‑level projects - but a workspace keeps them together in one repository for convenience.
Here is a concrete example of a monolith that has grown to include both a users feature and an orders feature. Both need to access a shared database, but the teams are different and the deployment schedules are different. The decision is made to split.
First, the monolith before the split:
// src/main.rs (monolith)
use axum::{routing::{get, post}, Router, Json};
use serde::Deserialize;
#[derive(Deserialize)]
struct CreateOrder {
user_id: u64,
item: String,
}
async fn get_user() -> &'static str {
// Imagine this queries a database
"User data"
}
async fn create_order(Json(input): Json<CreateOrder>) -> String {
// Imagine this inserts into a database after checking the user exists
format!("Order created for user {} with item {}", input.user_id, input.item)
}
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/users/{id}", get(get_user))
.route("/orders", post(create_order));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
After splitting, the users service keeps only the user route. The orders service keeps the order route and must now call the users service to validate the user. That call uses reqwest as the HTTP client, so each service needs its own Cargo.toml with its dependencies - the orders service must list reqwest, or its code will not compile:
# users-service/Cargo.toml
[package]
name = "users-service"
version = "0.1.0"
edition = "2021"
[dependencies]
axum = "0.8"
tokio = { version = "1.0", features = ["full"] }
# orders-service/Cargo.toml
[package]
name = "orders-service"
version = "0.1.0"
edition = "2021"
[dependencies]
axum = "0.8"
tokio = { version = "1.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = "0.12"
reqwest is a Rust crate for making HTTP requests from code - it is the client side, the mirror image of Axum's server side. The users service does not need it, because it never calls another service; the orders service does, because it must ask the users service whether a user exists.
// users-service/src/main.rs
use axum::{routing::get, Router};
async fn get_user() -> &'static str {
"User data"
}
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/users/{id}", get(get_user));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3001").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
// orders-service/src/main.rs
use axum::{routing::post, Router, Json, http::StatusCode};
use serde::Deserialize;
#[derive(Deserialize)]
struct CreateOrder {
user_id: u64,
item: String,
}
async fn create_order(Json(input): Json<CreateOrder>) -> StatusCode {
// Call the users service to check the user exists
let user_url = format!("http://localhost:3001/users/{}", input.user_id);
match reqwest::get(&user_url).await {
Ok(response) if response.status().is_success() => {
// Insert the order into the database
StatusCode::CREATED
}
Ok(_) => StatusCode::BAD_REQUEST,
Err(_) => StatusCode::SERVICE_UNAVAILABLE,
}
}
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/orders", post(create_order));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3002").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
Notice two important changes. First, each service now has its own port: 3001 for users, 3002 for orders. Second, the orders service depends on the users service being available. If the users service crashes, the orders service returns 503 Service Unavailable. In the monolith, that dependency was invisible - a function call never failed because of a network partition. Now the failure is explicit, and you must handle it.
Network Calls Replace Function Calls:
Once you split, every cross-service dependency becomes a potential failure point. A function call in a monolith either returns or panics. A network call can hang, time out, return a malformed response, or fail because the other service is down. You must write code to handle all of those cases. This is not optional - it is the single biggest operational change when moving to services.
Multiple Ways to Split: By Feature, By Team, By Resource
There is no single correct way to divide a monolith. The three most common axes are:
- By feature or domain: users service, orders service, products service. This is the most intuitive and aligns with the mental model of the business domain.
- By team ownership: if Team A owns authentication and Team B owns reporting, you might split into
auth-serviceandreporting-service, even if those domains share some logic. - By resource profile: if one set of endpoints is CPU‑intensive and another is memory‑intensive, splitting allows you to deploy them on different hardware shapes or scale them independently.
The feature-based split is the most common for Axum applications because it maps naturally to route prefixes. In a monolith, you might have .route("/users", ...) and .route("/orders", ...). When you split, each service keeps its own route prefix. That makes routing at an API gateway or load balancer straightforward: send /users traffic to the users service, /orders traffic to the orders service.
The team-based split can be useful when you have a large organization, but it can also lead to services that do not map cleanly to routes. For a beginner, starting with a feature-based split is usually the best approach because the boundaries are already visible in the code.
The Hidden Cost: Data and Transactions
One thing that surprises many developers after they split is the loss of a shared database transaction. In a monolith, the create_order handler could start a database transaction, check the user's credit balance, insert the order, update the inventory, and commit. If any step failed, the whole transaction rolled back.
After splitting into a users service, an orders service, and an inventory service, there is no single transaction that spans all three. You could use a distributed transaction protocol like two‑phase commit, but that is complex and often avoided. The common pattern is to use eventual consistency: each service updates its own database and publishes events that other services consume. The system temporarily allows inconsistent states - an order might exist before the inventory is updated, and if the inventory update fails, a compensating action cancels the order.
For a beginner, the practical lesson is: do not split features that need to change atomically together. If create_order must always update both orders and inventory in one step, keep them in the same service, even if they are conceptually different domains. You can split them later when you are ready to accept eventual consistency.
Deployment and Operations Change Drastically
A monolith is deployed as one unit. You build one binary, push it to one server or container, and restart one process. Splitting into three services means three builds, three containers, three health checks, and three times the deployment scripts. The operational complexity grows with the number of services, not linearly but superlinearly, because you must also manage the network between them, service discovery, and possibly an API gateway in front.
For a team that has never run multiple services before, moving from one to three is a significant jump. You will need to decide how services discover each other (hardcoded localhost:3001? DNS names? a service registry?), how to handle retries when a service is temporarily down, and how to monitor the health of each service independently. None of this is required in a monolith.
Start with a Modest Split:
If you decide to split, do not break your app into ten services on day one. Split off the one feature that has the most independent scaling or deployment pressure - often a background job or a reporting endpoint - and keep the rest as a monolith. Run that setup for a few weeks before deciding whether to split further.
Common Mistakes Beginners Make
The most frequent mistakes are:
- Splitting before there is a need. If you are the only developer and your app is small, every service you add is pure overhead. You will spend more time wiring up HTTP calls and debugging network issues than you would have spent writing the feature in a monolith.
- Splitting by technical layer instead of by feature. Splitting into a
controllersservice, aservicesservice, and adatabaseservice does not reduce coupling; it increases it, because every request must bounce through all three. Feature-based splits are the only ones that reduce coupling meaningfully. - Ignoring data consistency. As described, cross-service transactions do not exist. If you split an order workflow and then discover you need to roll back an order when payment fails, you have to implement a saga pattern. Many teams learn this the hard way.
- Underestimating the operational cost. Every service needs monitoring, logging, deployment, and security. Three services is not three times the cost of one; it is often more, because you must also manage the interactions.
- Not having an API gateway. If you expose each service on a different port directly to the client, the client must know all the ports. In production, you typically put a single reverse proxy in front that routes
/usersto the users service and/ordersto the orders service. This routing layer is an extra component to maintain.
When the Monolith Is the Right Call:
If you have a small team, a stable feature set, low traffic, and features that share data tightly, staying with a monolith is not a failure - it is the correct engineering decision. Many successful products run as monoliths for years. The goal is not to have microservices; the goal is to have a maintainable system. If a monolith gives you that, you have achieved the goal.
A Decision Framework You Can Reuse
When the time comes to make this decision for your own Axum project, use this simple process:
- Write down the concrete pain you are feeling. Is it slow deployments? Merge conflicts between teams? Independent scaling needs? If you cannot name a specific pain, you do not need to split.
- Identify the smallest cut that relieves that pain. If deployments are slow because one enormous service takes forever to build, maybe you only need to split the build cache, not the services. If two teams fight over one codebase, maybe a monorepo with code ownership is enough.
- Prototype the split on paper first. Draw boxes for each proposed service, draw arrows for every call they must make to each other. If the arrows form a dense web, the services are too coupled and splitting will not help.
- Split one feature and measure. Pick the feature with the clearest boundary and the highest independence. Split only that one. Run both the new service and the remaining monolith for a few weeks. If the pain you identified decreases and the operational overhead is acceptable, consider further splits. If not, merge back.
This framework forces you to act on evidence, not on fashion. The worst reason to split is because a blog post said microservices are modern. The best reason is that you have measured a real problem and splitting is the least expensive way to solve it.
Summary
The decision to split an Axum app into services is not a step you must take to be a "real" backend developer. It is a trade‑off between the simplicity of one process and the independence of many. A monolith gives you shared memory, direct function calls, and simple deployments. Services give you independent scaling, independent deployment, and team autonomy - but at the cost of network complexity, distributed data, and operational overhead.
The single most important insight is that splitting is an organizational decision as much as a technical one. If you are one person, or a small team working on a cohesive product, a monolith is almost certainly the right choice. If you have multiple teams that need to move at different speeds, and you are willing to invest in the infrastructure to support multiple running services, splitting can be the key to scaling your development velocity. The Axum code itself is the easy part - each service is just another main.rs with a Router. The hard part is everything around it: networking, deployments, monitoring, and data consistency.
When you face this decision, start from the pain, not the pattern. Split the smallest piece that relieves the pain, and keep the rest together until you have evidence that more splitting is needed. That is how you grow an Axum project from a monolith into a well‑structured system without losing the simplicity that made Axum pleasant to use in the first place.