System Design

Microservices vs Monolith

Monolith

Bitta katta application:

┌─────────────────────┐
│   Monolith App      │
│  ┌──────────────┐   │
│  │   UI Layer   │   │
│  ├──────────────┤   │
│  │ Business     │   │
│  │ Logic        │   │
│  ├──────────────┤   │
│  │ Data Access  │   │
│  └──────────────┘   │
│         ↓           │
│    Database         │
└─────────────────────┘

Afzalliklari

1. Simple: Bitta codebase, deploy, database
2. Easy development: Local’da ishga tushirish oson
3. Performance: Internal function calls (no network)
4. Transactions: ACID easy

Kamchiliklari

1. Scaling qiyin: Butun app’ni scale qilish kerak
2. Deploy risk: Kichik o’zgarish = butun app redeploy
3. Technology lock-in: Bitta stack (Java yoki Node.js)
4. Large codebase: 100K+ lines → hard to maintain

Microservices

Bir nechta kichik, mustaqil servislar:

┌──────────┐  ┌──────────┐  ┌──────────┐
│  User    │  │  Order   │  │ Payment  │
│ Service  │  │ Service  │  │ Service  │
└────┬─────┘  └────┬─────┘  └────┬─────┘
     │             │             │
  ┌──▼──┐       ┌──▼──┐       ┌──▼──┐
  │ DB  │       │ DB  │       │ DB  │
  └─────┘       └─────┘       └─────┘

Afzalliklari

1. Independent scaling: Faqat kerakli service’ni scale qilish
2. Technology diversity: Har biri o’z stack’i
3. Team autonomy: Har bir team o’z service’ini
4. Fault isolation: Bitta service crash = others work

Kamchiliklari

1. Complexity: Network calls, distributed tracing
2. Data consistency: No ACID across services
3. Testing: Integration tests qiyin
4. Operations: Deploy, monitor N services

Qachon Monolith?

Startup / MVP:

Simple domain:

Real examples:

Qachon Microservices?

Large scale:

Large team:

Complex domain:

Real examples:

Modular Monolith (Best of both)

┌──────────────────────────┐
│      Monolith            │
│  ┌────────┐  ┌────────┐  │
│  │Module A│  │Module B│  │
│  └────────┘  └────────┘  │
│  Well-defined boundaries │
└──────────────────────────┘

Start modular → Split to microservices later

Migration Strategy

1. Start: Monolith
2. Grow: Modular Monolith
3. Identify: Bottleneck modules
4. Extract: One module → microservice
5. Repeat: Gradually extract more

Don’t: Big bang rewrite
Do: Incremental extraction

Xulosa

Monolith:

Microservices:

Keyingi dars: Rate Limiting.