# Monolithic

**Also known as:** Single deployment unit  
**Category:** System Architecture (Macro)  
**Complexity:** 1/5  
**Fit:** 1–15 engineers  
**Guide:** https://layra4.dev/architectures/system/monolith

*One codebase, one artifact, one process. The right default for most new systems.*

A monolith is one codebase that builds into one artifact and runs as one process. The API, the background jobs and the web pages all deploy and scale together. Most successful systems start this way. In 2016, Stack Overflow served about 1.3 billion page views a month from one .NET application on nine web servers.

A monolith is not the same as messy code. Inner structure, such as layers or modules, is a separate choice. What defines a monolith is the single deploy: one thing to build, ship, watch and roll back. The cost appears with growth: many teams share one release, and you cannot scale one part alone.

> **In one sentence.** Keep everything in one deployable until a measured problem forces a split; one process is simpler than any scaling plan you do not need yet.

## Origin

Less a named pattern than the default before distribution was cheap. Martin Fowler's “MonolithFirst” (2015) and Sam Newman's books made it a deliberate choice again.

## What defines it

### Single deployable

Everything builds into one artifact and ships as one unit. There is one build, one release and one thing to roll back.

- One deploy pipeline
- One version of the system at a time
- Rollback is a single step

### In-process calls

Modules call each other as normal function calls. A call takes nanoseconds, needs no serialization and either returns or throws. A network call can also time out with no answer.

- No network latency
- No wire format to version
- No partial failure

### One shared database

Usually one database that every module reads and writes. A transaction (a group of writes that succeed or fail together) can cover the whole domain, so consistency is simple.

- ACID transactions across modules
- Joins across the whole domain
- No distributed consistency to manage

### Scale as a whole

You add capacity by running more copies of the whole process behind a load balancer. This works well until one part needs far more capacity than the rest.

- Horizontal scaling by full copies
- Cannot scale one part alone
- Stateless copies scale easily

> 4 copies × 8 vCPU behind NGINX can serve thousands of requests per second for a typical CRUD app.

## Keeping a monolith healthy

### Start with a monolith

Begin with one deployable. Extract a service only when a concrete need appears: a team too large for one release, one part that must scale alone, or a part that needs fault isolation.

### Keep module boundaries inside

Group code by business area (orders, billing) behind clear public functions. Then a later split is a refactor, not a rewrite. That next step is a modular monolith.

### Fix messy code with structure, not services

A tangled codebase is a structure problem. Splitting it into services gives you the same tangle, plus network calls, latency and partial failure.

### Know the real signals to split

Teams wait in one deploy queue, one hot path needs ten times the capacity of the rest, or a crash in one area keeps taking down everything. Without signals like these, stay.

## Examples

### One process wires and serves everything

```typescript
// index.ts — the entire application boots in one process
const db = createPool(env.DATABASE_URL);       // one shared database

const orders  = makeOrders(db);                // modules are just wired-in code
const billing = makeBilling(db);
const users   = makeUsers(db);

const app = new Elysia()
  .use(orders.routes)                          // same process, in-memory calls
  .use(billing.routes)
  .use(users.routes)
  .use(staticFiles("dist/web"));               // serves the web app too

app.listen(env.PORT);                          // one artifact, one deployment
```

One entry point composes every module and serves both the API and the web app. In-process calls, one database, one deploy.

## When to use

- A new product that is still looking for its market
- A team of up to about 15 engineers working in one codebase
- Domain boundaries are not yet clear enough to draw services

## When not to use

- One part needs far more scale than the rest, such as video encoding
- Several teams keep blocking each other on one deploy pipeline
- Regulation requires some data to run in a separate, isolated deployable

## Benefits

- The simplest system to build, test, deploy and debug
- Fast in-process calls and ACID transactions across the whole domain
- Cheapest to operate: one artifact, one pipeline, one thing to monitor

## Costs

- The whole app scales as a unit; you cannot scale one hot path alone
- One deploy pipeline becomes a queue as the number of teams grows
- A crash or memory leak in one area can take down the whole process

## Pitfalls

- Moving to microservices to fix messy code, and ending up with a distributed mess
- No module boundaries inside, so the eventual split becomes a full rewrite
- Every module reading every table, so no part can ever move out on its own
- Splitting early because of a diagram, then spending months on infrastructure instead of features

## Related patterns

- [Modular Monolith](https://layra4.dev/architectures/system/modular-monolith) — the same deployable with strict walls inside; the usual next step
- [Microservices](https://layra4.dev/architectures/system/microservices) — the far end, once real pressure forces a split
- [Layered Architecture](https://layra4.dev/architectures/application/layered) — a classic way to organise the code inside a monolith
- [Load Balancer](https://layra4.dev/architectures/core-building-blocks/load-balancer) — how you scale a monolith: more copies behind one address
- [Strangler Fig](https://layra4.dev/architectures/architectural/strangler-fig) — how to move parts out one at a time, once you do split

## Further reading

- *MonolithFirst (bliki)* — Martin Fowler — The argument for starting with a monolith and extracting services later.
- *Monolith to Microservices* — Sam Newman (2019) — How to split a monolith, and when not to.
