Skip to content

Monolithic

Understanding Traditional Application Design

Section titled “Understanding Traditional Application Design”

A monolithic architecture is a single-tiered software application where all components are combined into a single program from a single platform.

Monolithic Architecture
======================
+---------------------------------------------------+
| Application |
+---------------------------------------------------+
| |
| +-------------+ +-------------+ |
| | UI | | API | |
| | Layer | | Layer | |
| +-------------+ +-------------+ |
| | | |
| +-------------+ +-------------+ |
| | Business | | Business | |
| | Logic | | Logic | |
| +-------------+ +-------------+ |
| | | |
| +------------------------------------------+ |
| | Data Access Layer | |
| +------------------------------------------+ |
| | |
| +------------------------------------------+ |
| | Database | |
| +------------------------------------------+ |
| |
+---------------------------------------------------+

FeatureDescription
Single DeploymentOne unit to deploy
Shared DatabaseAll components use same DB
Tight CouplingComponents are interdependent
Single TechnologyOne language/framework
Simple DevelopmentIDE-friendly
Typical Monolith Structure
==========================
my-monolith-app/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ ├── controller/
│ │ │ │ ├── UserController.java
│ │ │ │ ├── OrderController.java
│ │ │ │ └── ProductController.java
│ │ │ ├── service/
│ │ │ │ ├── UserService.java
│ │ │ │ ├── OrderService.java
│ │ │ │ └── ProductService.java
│ │ │ ├── repository/
│ │ │ │ ├── UserRepository.java
│ │ │ │ └── OrderRepository.java
│ │ │ ├── model/
│ │ │ │ ├── User.java
│ │ │ │ └── Order.java
│ │ │ └── config/
│ │ │ └── AppConfig.java
│ │ └── resources/
│ │ └── application.properties
│ └── test/
│ └── java/
│ └── ...
├── pom.xml (or build.gradle)
└── README.md

Development Simplicity
=====================
1. Single codebase
- Easy to search
- Easy to understand
- Easy to navigate
2. Simple debugging
- Single stack trace
- No network calls to trace
- All code in one place
3. Easy testing
- No need for service mocking
- Integration tests are simpler
Performance Benefits
====================
1. No network latency
- In-memory calls between components
- Faster than RPC
2. Efficient data access
- Can use JOINs
- Single database connection
- Transactional integrity
Deployment Simplicity
=====================
Single command deployment:
# Docker
docker build -t myapp .
docker run myapp
# Traditional
./deploy.sh
vs Microservices:
- Deploy service A
- Deploy service B
- Deploy service C
- Update configurations
- Wait for all to be healthy

Scaling Problems
================
To scale, you must replicate ENTIRE application:
+----------+ +----------+ +----------+
| Monolith | | Monolith | | Monolith |
| App | | App | | App |
+----------+ +----------+ +----------+
| | |
v v v
+--------------------------------------------------+
| Database |
+--------------------------------------------------+
Problem: Even if only ONE component is under load,
you must scale EVERYTHING
Technology Constraints
======================
Once you choose, changing is hard:
Original: Java + Spring + Oracle
Want to add:
- Python ML service? -> Hard
- Node.js real-time? -> Hard
- PostgreSQL? -> Expensive migration
- Redis cache? -> Add dependency
Everything must use same stack!
Reliability Issues
==================
Single Point of Failure:
+------------------------------------------+
| |
| User Bug in Database |
| Request --> Product --> Connection |
| Service |
| Crash! |
| |
+------------------------------------------+
Result: ENTIRE application is down
Even if only one module has a bug!
Deployment Challenges
=====================
1. Small change = Full redeploy
- Risk of breaking other features
- Longer deployment times
- Requires coordination
2. All-or-nothing deploy
- Can't deploy partial features
- Feature flags help but add complexity
3. Downtime required
- Usually need maintenance window
- Blue-green helps but complex

ScenarioWhy Monolith Works
Small teamsSimple development
Early stageFast to build, iterate
Limited scaleDon’t need distributed scale
Simple domainNo complex service boundaries
CRUD appsStandard data operations
Proof of conceptFast to build
Companies That Started with Monoliths
======================================
Many successful companies started with monoliths:
1. Amazon
- Started as monolithic bookstore
- Eventually broke into microservices
- Monolith was right for initial stage
2. eBay
- Monolithic for years
- Microservices journey started later
3. Etsy
- PHP monolith
- Still runs largely monolithic
Key Insight:
============
Start simple, evolve when needed!

Monolith Scaling Strategies
===========================
1. Vertical Scaling
+------------------+
| More CPU/RAM |
| Bigger database |
+------------------+
2. Horizontal Scaling (with load balancer)
+------------------+
| Multiple |
| instances |
+------------------+
3. Database Optimization
+------------------+
| Caching |
| Read replicas |
| Indexing |
+------------------+
4. Feature Flags
+------------------+
| Deploy anytime |
| Toggle features |
+------------------+

Modular Monolith
================
Architecture:
+--------------------------------------------------+
| Application |
+--------------------------------------------------+
| |
| +----------+ +----------+ +----------+ |
| | Module A | | Module B | | Module C | |
| | | | | | | |
| | User | | Order | | Payment | |
| | Service | | Service | | Service | |
| +----------+ +----------+ +----------+ |
| |
+--------------------------------------------------+
| Shared Infrastructure |
| Database, Caching, etc. |
+--------------------------------------------------+
Key Difference from Microservices:
- Still one deployment
- Clear internal boundaries
- Can extract modules later
BenefitDescription
Future-readyEasy to extract services later
OrganizedClear module boundaries
TestableCan test modules in isolation
FlexibleCan add services when needed

Monolith Best Practices
=======================
1. Use Modular Architecture
+------------------+
| Clear packages |
| Separate concerns|
+------------------+
2. Implement Feature Flags
+------------------+
| Deploy anytime |
| A/B testing |
+------------------+
3. Add Comprehensive Monitoring
+------------------+
| Metrics |
| Logging |
| Tracing |
+------------------+
4. Use CI/CD
+------------------+
| Automated tests |
| Fast deploys |
+------------------+
5. Plan for Extraction
+------------------+
| Database per |
| module |
+------------------+

Key monolith concepts:

  1. Simplicity is strength - Easy to develop, debug, deploy
  2. Scale has limits - Works well up to a point
  3. Technology lock-in - Hard to change stacks
  4. Reliability risks - Single point of failure
  5. Start simple - Don’t over-engineer early
  6. Consider modular - Future extraction easier

Next: Chapter 12: Microservices Architecture