🏗️ Architecture

Monolithic

Monolithic

Monolithic architecture is a traditional software structure in which all functionality is integrated into a single codebase and deployment unit. It is simple and fast early in development, but maintenance and scaling become difficult as it grows.

📖 Detailed Explanation

Monolithic architecture is a traditional software structure in which all of an application's functions (UI, business logic, data access) are integrated into a single codebase and built and deployed as a single unit.

Pros and Cons

Pros

  • Simple and fast in early development
  • Easy to run everything locally
  • Simple transaction management
  • Deployment is done in one step
  • Relatively easy to debug

Cons

  • Becomes more complex as the codebase grows
  • Even a small change requires redeploying everything
  • Cannot scale only specific functions
  • Hard to change the technology stack
  • Frequent conflicts between teams

When Monolithic Is a Good Fit

💻 Code Example

Typical Monolithic Structure

myapp/
├── src/
│   ├── controllers/        # 모든 HTTP 컨트롤러
│   │   ├── UserController.ts
│   │   ├── OrderController.ts
│   │   └── ProductController.ts
│   ├── services/           # 비즈니스 로직 (모두 같은 폴더)
│   │   ├── UserService.ts
│   │   ├── OrderService.ts
│   │   └── ProductService.ts
│   ├── models/             # 데이터베이스 모델 (공유)
│   │   ├── User.ts
│   │   ├── Order.ts
│   │   └── Product.ts
│   └── app.ts              # 단일 진입점
├── package.json
└── Dockerfile              # 하나의 이미지

Calls Between Monolithic Services

// services/OrderService.ts
import { UserService } from './UserService';
import { ProductService } from './ProductService';
import { Order } from '../models/Order';

export class OrderService {
  constructor(
    private userService: UserService,     // 직접 의존
    private productService: ProductService  // 직접 의존
  ) {}

  async createOrder(userId: string, productIds: string[]) {
    // 함수 호출로 바로 접근 (네트워크 비용 없음)
    const user = await this.userService.findById(userId);
    const products = await this.productService.findByIds(productIds);

    // 같은 DB 트랜잭션 가능
    const order = new Order({ user, products });
    await order.save();

    return order;
  }
}

Problematic Pattern (Big Ball of Mud)

// 안티패턴: 순환 의존, 명확하지 않은 경계
import { OrderService } from './OrderService';
import { UserService } from './UserService';
import { NotificationService } from './NotificationService';

export class ProductService {
  // 모든 서비스가 서로를 알고 있음
  constructor(
    private orderService: OrderService,
    private userService: UserService,
    private notificationService: NotificationService
  ) {}

  async updatePrice(productId: string, newPrice: number) {
    // 도처에서 다른 서비스 호출
    await this.product.updatePrice(newPrice);

    // 연관된 주문 가격도 업데이트 (경계 침범)
    await this.orderService.recalculateOrdersWithProduct(productId);

    // 관심 있는 사용자에게 알림 (더 복잡해짐)
    const users = await this.userService.findWatchingProduct(productId);
    await this.notificationService.notifyPriceChange(users, productId);
  }
}

💬 Real-world conversation examples

👨‍💼 CTO

"Deployment takes 30 minutes, and even though I changed just one line, I have to rerun all the tests."

👩‍💻 Architect

"We've hit the limits of the monolith. I recommend first cleaning up the module boundaries and moving to a Modular Monolith, then gradually splitting it into microservices, starting with the parts that have the most traffic."

👨‍💻 Junior developer

"I heard microservices are the trend. Can't we just start with microservices from the beginning?"

👩‍💻 Senior developer

"There's a principle called Monolith First. If you split into microservices before you understand the domain well enough, you draw the boundaries wrong and suffer more later. It's better to start with a monolith and split it once the domain becomes clear."

⚠️ Cautions

Big Ball of Mud: Even a monolith becomes a "ball of mud" if it has no internal structure. Keep a layered architecture or a modular structure.

Distributed Monolith: A state where the system is split like microservices but remains tightly coupled. It has both the drawbacks of a monolith and the complexity of a distributed system.

Tip: A monolith is not a bad thing. Large services such as Shopify and Stack Overflow also operate monoliths well. What matters is code quality and modularization.

🔗 Related Terms

📚 Learn More