Monolith vs Microservices Monolith ┌────────────────────────┐ │ Monolith App │ │ ┌──────┐ ┌──────┐ │ │ │ Auth │ │ Order│ │ │ └──────┘ └──────┘ │ │ ┌──────┐ ┌───
Monolith vs Microservices
Monolith
┌────────────────────────┐
│ Monolith App │
│ ┌──────┐ ┌──────┐ │
│ │ Auth │ │ Order│ │
│ └──────┘ └──────┘ │
│ ┌──────┐ ┌──────┐ │
│ │ User │ │Payment│ │
│ └──────┘ └──────┘ │
│ One Database │
└────────────────────────┘
+ Simple, mudah develop & deploy
- Sulit scale satu bagian saja
Microservices
┌──────┐ ┌───────┐ ┌─────────┐
│ Auth │ │ Order │ │ Payment │
│ Svc │ │ Svc │ │ Svc │
│ DB │ │ DB │ │ DB │
└──┬───┘ └───┬───┘ └────┬────┘
│ │ │
└──── API Gateway ──────┘
│
Client
+ Scale independen per service
- Lebih complex (network, consistency)
Komunikasi antar Service
- Synchronous (HTTP/gRPC) — Service langsung call service lain. Simple tapi tight coupling.
- Asynchronous (Message Queue) — Kirim pesan via RabbitMQ/Kafka. Loose coupling tapi lebih complex.
// Synchronous: Order Service call Payment Service
const payment = await fetch("http://payment-service/charge", {
method: "POST",
body: JSON.stringify({ orderId: 123, amount: 99 }),
});
// Asynchronous: Order Service publish event
await messageQueue.publish("order.created", {
orderId: 123, userId: 456, amount: 99
});
// Payment Service subscribe dan proses
Kapan Pakai Microservices?
- Mulai dengan monolith — Hampir selalu. Premature microservices = premature complexity
- Pisahkan saat — Tim sudah besar (>20 dev), perlu scale independen, domain sudah jelas