liveBook · Manning

Monolithic architecture

As explained in Grokking Software Architecture

A software application developed and deployed as a single unified unit.

A monolith is like a single building: the user interface, business logic, and database access live in one application and are deployed together. Its modules run in the same process and communicate through in-memory calls rather than network requests. section 12.2.1

One building can still have well-organized rooms. A modular monolith keeps a single deployment unit while separating internal components behind strict interfaces. Without those boundaries, developers can bypass layers and turn the codebase into a tangled “big ball of mud.” section 12.2.1 section 12.2.6

Listing 3.13 “Before” Monolithic Code
class OrderProcessor {
    process(order) {
        // 1. Validation
        console.log("Validating order...");
        if (order.items.length === 0 || order.total <= 0) {
            throw new Error("Order is invalid.");
        }
 
        // 2. Payment Processing
        console.log(`Processing payment for ${order.total.toFixed(2)}`);
        const paymentSuccess = true; 
 
        // 3. Inventory Update & 4. Confirmation Email
        if (paymentSuccess) {
            console.log("Updating inventory...");
            console.log(
                `Sending confirmation email to ${order.CustomerEmail}`);
            return "Order processed successfully.";
        } else {
            return "Payment failed.";
        }
    }
}

This JavaScript order processor is a micro-monolith: one method handles validation, payment, inventory, and notification. It illustrates tangled responsibilities at method scale, not the deployment structure of a whole application. section 3.5.1

The single-unit design has practical tradeoffs:

  • Simplicity and speed: one application is straightforward to deploy and test, and internal calls avoid network latency. Shared code can also make broad refactoring easier. section 12.2.1 section 12.3.2
  • All-or-nothing changes: even a small inventory fix requires testing and deploying the whole application, with a risk of affecting checkout. section 12.2.1
  • Shared scaling: components cannot be scaled independently; a resource-heavy component can force the whole application onto a larger server. section 12.2.1
  • Team coordination: as an organization grows, teams sharing one deployment pipeline can delay one another when a build breaks or a release waits in a queue. section 12.2.3

A changing account model

Suppose a shop merges guest users and paying customers into one account type. In a monolith with a shared repository and database, a developer can find references, refactor the code, run the tests, and deploy. Separate services may instead require coordinated API changes, data migration, and deployments. section 12.3.2

A monolith is often a sensible starting point for a small team with changing requirements. Microservices can offer independent deployment and scaling, but introduce network and operational costs. Splitting deployment units without loosening their dependencies can create a distributed monolith: separate services that still fail together. section 12.3 section 12.11 section 6.8.4

When separation becomes worthwhile, establish internal boundaries first. The Strangler Fig pattern then offers an incremental route: use an API gateway to redirect traffic to new services gradually rather than replacing the entire application at once. section 12.2 section 12.11

How Grokking Software Architecture covers it

How deep it goes
Defines the deployment model and works through coupling, scaling, team coordination, and migration tradeoffs.
Examples
Uses a JavaScript order processor and an account-model refactor to illustrate tangled responsibilities and the advantages of shared code.
What you can do after
Evaluate a monolith against modular and distributed alternatives using deployment, scaling, coupling, and team-size tradeoffs.
How it connects
Connects monolithic architecture to modular monoliths, microservices, Conway's Law, and the Strangler Fig pattern.

Also explained in

Compare how 13 books explain monolithic architecture →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.