- Part 7 of 21 in System Design Roadmap: From Beginner to Intermediate Architecture Beginner
Monolithic architecture, from single processes to modular systems
Learn how to build, structure, and scale monolithic software architectures effectively while avoiding common design pitfalls.
MonksBit Desk
November 25, 2026 · 7 min read · 31 views
Read
A monolithic architecture is a software design pattern where all functional components of an application are packaged, deployed, and executed as a single unified service. It executes in a shared runtime environment and interacts with a unified database rather than delegating domain boundaries across a network.
You will need. Basic knowledge of client-server application structure · Familiarity with standard relational databases and basic SQL queries · Understanding of function calls and modular programming
The full lesson
Level 1 · Beginner: Understanding the single-process application
At its core, a monolithic architecture means that all business logic runs within a single operating system process or a set of identical clones of that process. When a user sends a request, that single application handles request routing, domain calculations, database reads and writes, and returns the response.
Consider a simple e-commerce website with two features: user profile management and order processing. In a monolithic architecture, both features live inside the same codebase. When a customer places an order, the order handling function calls the user validation function directly in memory. There is no network request or serialization layer between these two business actions.
Because all code lives in one application package, building and running the system locally requires only one runtime environment and one persistent database instance. This keeps developer workflows straightforward and eliminates network latency between submodules.
A basic monolithic web server handling users and orders in memory
class MonolithApp: def __init__(self): self.users = {} self.orders = [] def register_user(self, user_id: str, name: str) -> dict: self.users[user_id] = {"id": user_id, "name": name} return self.users[user_id] def place_order(self, user_id: str, item: str, amount: float) -> dict: if user_id not in self.users: raise ValueError("User does not exist") order = {"order_id": len(self.orders) + 1, "user_id": user_id, "item": item, "amount": amount} self.orders.append(order) return orderapp = MonolithApp()app.register_user("u1", "Alice")new_order = app.place_order("u1", "Book", 19.99)print(f"Created order: {new_order}")
Key takeaways
- All modules execute within the same process or duplicate runtime instances.
- Internal communication happens through standard in-memory function calls.
- Deployment involves building and releasing a single software artifact.
Level 2 · Intermediate: Structuring a modular monolith with strict domain boundaries
The primary failure mode of a growing monolith is tight coupling, often leading to what engineers call a big ball of mud. In an unstructured monolith, any module can import any other module or read directly from another domain's database tables. To keep a monolith maintainable, you must organize it as a modular monolith.
A modular monolith divides the codebase into distinct packages representing bounded domains, such as Users, Inventory, and Orders. Each domain exposes a public interface—often called a facade or service interface—and hides its internal persistence logic. Modules communicate strictly via these interfaces instead of executing arbitrary cross-table queries.
Transactions also become clearer in a modular monolith. Because all components share a single relational database connection pool, a business transaction spanning multiple domains can rely on standard ACID database transactions. However, developers must avoid long-running locks that hold database connections hostage across unrelated domains.
A modular monolith with encapsulated services and in-memory boundaries
from typing import Dict, Optionalclass UserService: def __init__(self): self._users: Dict[str, dict] = {} def create_user(self, user_id: str, email: str) -> dict: if user_id in self._users: raise ValueError("User already exists") self._users[user_id] = {"id": user_id, "email": email} return self._users[user_id] def user_exists(self, user_id: str) -> bool: return user_id in self._usersclass OrderService: def __init__(self, user_service: UserService): self._user_service = user_service self._orders: Dict[int, dict] = {} self._next_id = 1 def create_order(self, user_id: str, total: float) -> dict: if not self._user_service.user_exists(user_id): raise ValueError(f"Cannot order: user {user_id} not found") order = {"order_id": self._next_id, "user_id": user_id, "total": total} self._orders[self._next_id] = order self._next_id += 1 return orderusers = UserService()orders = OrderService(user_service=users)users.create_user("usr_10", "alice@example.com")order = orders.create_order("usr_10", 49.50)print(order)
Key takeaways
- Domain boundaries must be enforced via explicit service interfaces.
- Modules should never directly query database tables owned by another domain.
- ACID transactions can span domains safely without distributed consensus protocols.
Level 3 · Advanced: Scaling, concurrency limits, and migration boundaries
Scaling a monolithic application horizontally involves running multiple stateless instances behind a layer 4 or layer 7 load balancer. Since state cannot be safely pinned to a specific worker, session storage, file uploads, and caching must be offloaded to external infrastructure like Redis or object storage. All instances read and write from a central database cluster.
The primary bottleneck of horizontal scaling in a monolith is the centralized database. When hundreds of monolith workers connect to one relational database, connection exhaustion and write lock contention occur quickly. Mitigations include aggressive connection pooling via proxies, splitting read traffic to read replicas, and partitioning tables horizontally.
Eventually, teams encounter organizational scaling bottlenecks rather than purely technical ones. If thirty engineers are committing to the same repository and testing the same unified deployment artifact, release cadence slows down. When specific components require fundamentally different resource profiles—such as a video transcoding pipeline versus a lightweight REST API—extracting those isolated services into standalone microservices becomes necessary.
An event-driven decoupled interface inside a monolith to prepare for extraction
from typing import Callable, Dict, Listclass EventBus: def __init__(self): self._subscribers: Dict[str, List[Callable]] = {} def subscribe(self, event_type: str, handler: Callable): self._subscribers.setdefault(event_type, []).append(handler) def publish(self, event_type: str, payload: dict): for handler in self._subscribers.get(event_type, []): handler(payload)bus = EventBus()def send_welcome_email(payload: dict): print(f"[Email Worker] Sending welcome email to {payload['email']}")bus.subscribe("user_registered", send_welcome_email)def register(email: str): user = {"id": "usr_99", "email": email} bus.publish("user_registered", user) return userregister("bob@example.com")
Key takeaways
- Monoliths scale horizontally by running stateless copies behind a load balancer.
- The shared database is the ultimate bottleneck for monolith concurrency.
- Internal event buses decouple subdomains and allow future extraction into microservices.
Complexity
- Time: O(1) to O(N) per operation depending on business logic
- Space: O(1) auxiliary overhead beyond application heap and database storage
Internal domain calls execute as native in-memory function calls taking O(1) invocation overhead, compared to O(network) for distributed architectures. Memory footprint is bounded by the single process heap and database caching without duplicate runtime container overhead.
Common mistakes
- Allowing modules to bypass domain APIs and execute direct joins across foreign database tables.
- Storing session data or transient files on the local file system, which prevents horizontal scaling across multiple instances.
- Bundling long-running batch jobs into request-response threads, which ties up web server worker pools.
- Treating the monolith as an excuse to avoid automated test suites, leading to fear of continuous deployments.
Practice problems
- Decouple database schema access (easy). Hint: Ensure that module A interacts with module B only through a typed interface rather than writing an SQL join against table B.
- Design an in-process event publisher (medium). Hint: Use the observer pattern to execute side effects asynchronously without blocking the primary transactional path.
- Implement graceful degradation under database read saturation (hard). Hint: Direct high-throughput read operations to an external cache while maintaining strong transactional writes on the primary database.
Summary
Monolithic architecture consolidates application logic and persistence into a unified, single-process deployment. It maximizes developer velocity and operational simplicity while avoiding distributed system overhead. By enforcing clean domain boundaries and keeping workers stateless, a monolithic system can scale to handle massive production traffic before any architectural decomposition is required.
Finish the Prove step above to complete this lesson.
System Design Roadmap: From Beginner to Intermediate Architecture · 7 of 21
Was this helpful?
Comments (0)
Sign in or create an account to join the conversation.
- No comments yet. Be the first!