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:
- Tez ishlab chiqish
- Team kichik (1-5 dev)
- Requirements o’zgaruvchan
Simple domain:
- CRUD app
- Kam traffic
Real examples:
- Basecamp
- Stack Overflow
- GitHub (dastlab)
Qachon Microservices?
Large scale:
- Million+ users
- High traffic
Large team:
- 50+ developers
- Multiple teams
Complex domain:
- Turli business areas
- Independent scaling needs
Real examples:
- Netflix
- Uber
- Amazon
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:
- Simple, fast development
- Small teams
- Start here!
Microservices:
- Scale, complexity
- Large teams
- Evolve to this
Keyingi dars: Rate Limiting.