SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
  • Client-Server
  • Monolithic Architecture
  • Microservices
  • Serverless
  • Event-Driven Architecture
  • Peer-to-Peer (P2P)
  • Hexagonal Architecture
  • CQRS
  • Event Sourcing
  • Domain-Driven Design (DDD)
  • Layered (N-Tier) Architecture
  • Containers and Docker
  • Kubernetes Basics
  • Clean Architecture and Modular Monolith
  • Multi-Tenancy
  • Cloud Basics: Regions, Zones and Edge
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Architecture/Architectural Patterns

Monolithic Architecture

Build the whole app as one piece that is built, deployed and run together.

⏱ 12 min readBeginnerMust KnowInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

A monolith is an application built, deployed and run as one single unit. All features (users, orders, payments and so on) live in one codebase, usually share one database, and start as one process.

  • Simple to start: one project, one build, one deploy, one place to look when something breaks.
  • Fast inside: parts talk by normal function calls, not over the network.
  • Hard to grow apart: you scale, release and crash the whole app together.
  • It is not "bad". Most successful products start as a monolith, and many stay one.

02Concept: What is it?

In a monolithic architecture, everything the product does is packaged together. When a user places an order, the same program checks the user, reads the cart, charges the card and sends the email. These are only functions and classes that call each other inside one process.

Usually the monolith is split into layers (web, business logic, data access), and one shared database holds all the tables. To release a change, even a tiny one, you build and deploy the whole thing.

A monolith can be well organised or a mess. A modular monolith keeps clear boundaries between modules (each module owns its tables and exposes a small interface), but still deploys as one unit. This gives most of the order of microservices, without the network.

One app, one process, one database
πŸ“±Clients
→↓
One deployable application
πŸ‘€Users
πŸ”ŽSearch
πŸ“¦Orders
πŸ’³Payments
→↓
πŸ—„οΈOne database
Modules talk with function calls. The whole box is deployed together.
🧠Monolith is about deployment, not code quality
The word describes how it is shipped (one unit), not how clean the code is. A tidy modular monolith is far better than a messy set of microservices.

03Real-Life Example

🍡The One-Room Restaurant
A small restaurant has a single kitchen where one team does everything: prepares starters, grills the main, bakes desserts and washes the dishes. It is easy to run: one boss, no messages between kitchens, and everyone sees what is happening. But on a busy night you cannot just add more dessert capacity. You have to build a copy of the whole restaurant. If the fryer starts a fire, the whole place closes. And to change the menu, the whole kitchen must stop for a day.
One-room restaurant
Monolith
One kitchen for everything
One application with every feature
Cooks talk by shouting across the room
Modules call each other as functions
One shared store room
One shared database
Copy the whole restaurant for more guests
Run more copies of the whole app
A fire closes the whole place
A crash takes down every feature
Change the menu = close for a day
Any change means redeploying everything
Easy for a small team to manage
Simple for small teams and early products
Scaling a monolith
βš–οΈLoad balancer
→↓
πŸ–₯️Copy 1all modules
πŸ–₯️Copy 2all modules
πŸ–₯️Copy 3all modules
→↓
πŸ—„οΈOne database

04Why Do We Need It?

πŸš€Fast to build
One project, no network plumbing. A small team can ship the first version quickly.
πŸ”ŽEasy to debug
One log, one stack trace, one debugger session. You can follow a request from start to end.
⚑Fast calls
A function call takes microseconds. A network call takes milliseconds and can fail.
🧾Real transactions
One database means one ACID transaction can change many tables safely.
πŸ§ͺSimple testing
Start the app and test the whole flow. No need to run ten services.
πŸ’ΈLow cost
Less infrastructure and fewer tools to run, so a small team spends time on features.
Do not pay for complexity you do not need yet. For a new product or a small team, one well-organised deployable is usually the best first choice.

05Where Do We Use It?

🌱New products and start-ups
You do not yet know the right boundaries. A monolith is easy to reshape.
πŸ‘₯Small teams
A team of a few people cannot run and monitor many separate services.
🏒Internal tools
Admin panels and back-office apps with modest traffic.
🧩Modular monoliths at scale
Companies such as Shopify and Basecamp run very large products as monoliths with strict module boundaries.
🏦Strong consistency needs
Features that need one transaction across many tables, like ledgers and bookings.
πŸ“±Typical web frameworks
Rails, Django, Laravel and Spring apps are monoliths by default.

06Types / Parts / How It Works

Kinds of monolith

Layered (classic) monolith
Split by technical layer
  • Web / controllers on top
  • Business logic in the middle
  • Data access at the bottom
  • Easy to start, but features spread across all layers and tangle over time
Modular monolith
Split by business feature
  • Modules like Users, Orders, Payments
  • Each module owns its data and exposes a small interface
  • Others may not reach inside it
  • Can be split into services later with much less pain
A layered view
PresentationControllers, views, API routes
Business logicRules and workflows
Data accessRepositories, queries
DatabaseShared tables
Edge Core Data
Each layer only calls the one below it.

Monolith vs microservices at a glance

QuestionMonolithMicroservices
DeployOne unit, all togetherEach service on its own
ScaleCopy everythingScale only what is busy
Talk between partsFunction callsNetwork calls
DataUsually one shared databaseA database per service
A crashCan take the whole app downUsually limited to one service
Team size it suitsSmall to mediumMany teams
Operations effortLowHigh (many things to run and watch)
VisualizerWhere a monolith hurts: scaling, shipping and crashesSwitch between the three scenarios. Raise the Search traffic and see how much idle code is copied. Add developers and watch releases queue. Crash a module and see who goes down with it.
What do you want to try?
Each box is one full copy of the app. Cyan = the busy Search module.
Copy 1
πŸ‘€
πŸ”Ž
πŸ“¦
πŸ’³
πŸ””
Copy 2
πŸ‘€
πŸ”Ž
πŸ“¦
πŸ’³
πŸ””
Copy 3
πŸ‘€
πŸ”Ž
πŸ“¦
πŸ’³
πŸ””
Copies
3
of the whole app
Memory used
3000 MB
all modules x copies
Needed
1800 MB
if only Search scaled
Wasted
1200 MB
idle code in copies
Only Search is busy, but you can only copy the whole app. 3 copies run, using 3000 MB. About 1200 MB of that holds idle Users, Orders, Payments and Notifications code.

A simplified model with made-up sizes. The point: in a monolith the unit you scale, release and crash is always the whole app. A well-built monolith can still reduce these costs with caching, background jobs and good module boundaries.

07How to Use It / Steps / Implementation

Building a monolith that stays healthy

  1. 1
    Split by feature, not by layer
    Create modules named after the business: orders, billing, users. Keep each module's code and tables together.
  2. 2
    Give each module a small front door
    Other modules may call only its public interface, never read its tables or private classes.
  3. 3
    Keep dependencies one-way
    Avoid cycles (orders calls billing and billing calls orders). Use events or interfaces to break them.
  4. 4
    Stay stateless
    Keep sessions in a shared store or token, so you can run several copies behind a load balancer.
  5. 5
    Move slow work out
    Send emails, reports and image work to a queue and background workers, not the web request.
  6. 6
    Cache and add read replicas
    These scale a monolith a long way before any split is needed.
  7. 7
    Automate build and tests
    A fast CI pipeline keeps whole-app releases safe and frequent.
  8. 8
    Split only for a real reason
    A hot module, a team bottleneck or different tech needs. Then extract it with the Strangler Fig approach.
πŸ’‘Monolith first
Many experienced engineers suggest starting with a monolith. You learn where the real boundaries are by living with the product, and moving a line inside one codebase is much cheaper than moving a line between services.

08Key Terms to Know

TermMeaning in easy words
MonolithAn application built and deployed as one single unit
DeployableThe thing you ship. In a monolith there is just one
Modular monolithA monolith with clear module boundaries inside
Layered architectureCode split into presentation, business and data layers
CouplingHow much one part depends on the details of another
CohesionHow well the things inside one module belong together
Big ball of mudA codebase with no clear structure where everything depends on everything
Shared databaseOne database used by every module of the app
Horizontal scalingRunning more copies of the app behind a load balancer
Blast radiusHow much of the system a single failure can hurt
Strangler FigA way of replacing a monolith piece by piece

09Pros, Cons and Trade-offs

βœ… Pros
  • Simple to develop, test, debug and deploy
  • Fast in-process calls with no network failures
  • Real ACID transactions across all data
  • Low operations cost and few tools
  • Easy to refactor across module lines
⚠️ Cons
  • You can only scale the whole app, not one part
  • A bug or crash can bring everything down
  • Every change means a full build and deploy
  • Large codebases get slow to build and hard to understand
  • One technology stack for all parts
  • Many teams editing one codebase collide

Trade-offs

ChoiceWe gainWe lose
One deployableSimple releases and debuggingSmall changes cost a full release, and one bug can stop all
Shared databaseJoins and transactions are easyModules become tied through the schema
In-process callsSpeed and reliabilityNo independent scaling or failure isolation
One codebaseEasy refactoring and code sharingMerge conflicts and slow builds as teams grow
Modular boundariesOrder inside, easy later splitNeeds discipline, as nothing enforces it by default
Staying a monolithLow complexityMay hit scale or team limits one day

10Common Problems and Mistakes

Common mistakes

  1. The big ball of mud. No module rules, so everything calls everything. Changes become scary.
  2. Splitting too early. Moving to microservices before you need to, and getting a "distributed monolith".
  3. Shared tables everywhere. Any module can read any table, so you can never change the schema safely.
  4. Slow work inside the request. Sending emails or making reports while the user waits.
  5. State in memory. Sessions stored in one server's memory prevent running more copies.
  6. No tests. A big app with no tests makes every release a gamble.
  7. One huge database for everything. It becomes the bottleneck. Plan caching, replicas and later partitioning.

Signs it may be time to split

🐌Slow builds and deploys
Releases take hours and teams wait for each other.
πŸ”₯One hot module
One feature needs far more resources than the rest, and copying everything is wasteful.
πŸ‘₯Team collisions
Many teams change the same code and block each other.
🧬Different needs
A part needs another language, runtime or very different scaling.

11Real-World Examples

πŸ›οΈShopify
Runs one of the largest Rails apps as a modular monolith, with enforced module boundaries.
πŸ’¬Stack Overflow
Famously served huge traffic from a small number of servers running a mostly monolithic .NET app.
🎬Netflix (early days)
Started as one big app, then moved to microservices over years as the company grew.
πŸ“¦Amazon (early days)
Began with a large monolith (called Obidos) and split it up as teams and traffic grew.
🧰Basecamp
A public advocate of the β€œmajestic monolith” for small teams.
πŸ›οΈMany enterprises
Large core systems (banking, insurance) are monoliths that are being modernised step by step.
πŸ“Note
Company architectures change over time. These examples show the usual path: start simple, then split where the pain is.
Mini case: from monolith to a first service
🧱Monolithusers, orders, payments
→↓extract
πŸ”ŽSearch servicescaled alone
Only the hot part is carved out. The rest stays as it is.

12Related Topics to Read Next

Microservices→

The main alternative: many small deployable services.

Strangler Fig→

A safe way to move from a monolith to services.

Client-Server→

The basic model a monolith is built on.

Hexagonal Architecture→

A way to keep the inside of a monolith clean.

Scalability→

How copying a monolith helps, and where it stops.

ACID Transactions→

A key strength of one shared database.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • βœ”What: one application, one deployable, usually one database.
  • βœ”Strengths: simple, fast in-process calls, easy debugging, real transactions, low cost.
  • βœ”Weak spots: scale and release as one, a crash hits all, slow builds, team collisions.
  • βœ”Modular monolith: feature modules with small interfaces. Best default.
  • βœ”Scale it: stateless copies + load balancer + cache + replicas + queues.
  • βœ”Avoid: big ball of mud, shared tables, state in memory, splitting too early.
  • βœ”Split when: a hot module, team bottleneck or different tech. Use Strangler Fig.
  • βœ”One line: β€œStart with one tidy unit, and split only where it really hurts.”
← Previous
Client-Server
Next β†’
Microservices