| Microservicio | Responsabilidad | Tecnología | API | Puerto |
|---|---|---|---|---|
| MS-Históricos | Consulta movimientos (CQRS Read) | Node.js + GraphQL | GraphQL | 3001 |
| MS-Pagos-Internos | Transferencias mismo banco | Node.js + GraphQL | GraphQL | 3002 |
| MS-Pagos-Interbancarios | Transferencias + SAGA | Node.js + GraphQL | GraphQL | 3003 |
| MS-Datos-Cliente | Info básica cliente | Node.js + GraphQL | GraphQL | 3004 |
| MS-Autenticación | OAuth 2.0 + Biometría | Node.js + Passport.js | REST | 3005 |
| MS-Auditoría | Eventos + Worker Pool | Node.js + GraphQL | GraphQL | 3006 |
| MS-Notificaciones | Email, SMS, Push + Workers | Node.js + Bull Queue | GraphQL | 3007 |
| MS-Archivos | Upload/Download documentos | Node.js + Multer | REST | 3008 |
| API-Gateway | Enrutamiento + Federation | Apollo Gateway | GraphQL | 8080 |
Node.js es la opción óptima para esta arquitectura por las siguientes razones:
Node.js desde la versión 12+ incluye Worker Threads, permitiendo verdadero procesamiento paralelo en múltiples cores de CPU.
graph TB
MAIN[Main Thread - Event Loop
• Recibe requests HTTP/GraphQL
• Coordina workers no bloqueante
• Gestiona I/O asíncrono DB, APIs
• Responde a clientes]
W1[Worker 1 Agregaciones SQL]
W2[Worker 2 Reportes PDF Gen]
W3[Worker 3 OCR DocBiometría]
W4[Worker 4 ML Scoring]
MAIN -->|Delega tareas
CPU-intensive| W1
MAIN -->|Delega tareas
CPU-intensive| W2
MAIN -->|Delega tareas
CPU-intensive| W3
MAIN -->|Delega tareas
CPU-intensive| W4
style MAIN fill:#667eea,stroke:#333,color:#fff,stroke-width:3px
style W1 fill:#4caf50,stroke:#333,color:#fff
style W2 fill:#4caf50,stroke:#333,color:#fff
style W3 fill:#4caf50,stroke:#333,color:#fff
style W4 fill:#4caf50,stroke:#333,color:#fff
| Operación | Single-thread | Con 4 Workers | Mejora |
|---|---|---|---|
| Requests para dashboard completo | 8-12 | 1-2 | 80-85% |
| Bandwidth consumido (mobile) | 150 KB | 45 KB | 70% |
| Latencia total (3G) | 3.2s | 1.1s | 66% |
| Time-to-interactive | 4.5s | 1.8s | 60% |
| Generar reporte 100K transacciones | 8.2s | 2.1s | ↑ 75% |
| OCR de 10 documentos | 45s | 12s | ↑ 73% |
| Scoring de 50 clientes | 15s | 4s | ↑ 73% |
| Eventos procesados/segundo | 800 | 3,200 | ↑ 300% |
REST (requiere 3 requests):
GET /customers/12345 → 2.3 KB
GET /customers/12345/accounts → 5.1 KB
GET /accounts/xxx/transactions?limit=5 → 4.2 KB
Total: 3 requests, 11.6 KB, ~1.8s en 3G
GraphQL (1 request):
query {
customer(id: "12345") {
name
accounts {
balance
lastTransaction { amount date }
}
}
}
Total: 1 request, 4.1 KB, ~0.6s en 3G
Resultado: 65% menos datos, 67% menos latencia
| Métrica | REST | GraphQL | Mejora |
|---|---|---|---|
| Requests para dashboard completo | 8-12 | 1-2 | 80-85% |
| Bandwidth consumido (mobile) | 150 KB | 45 KB | 70% |
| Latencia total (3G) | 3.2s | 1.1s | 66% |
| Time-to-interactive | 4.5s | 1.8s | 60% |
Apollo Client implementa caché automático normalizado:
{
"Customer:12345": {
__typename: "Customer",
id: "12345",
name: "Juan Pérez",
email: "juan@example.com"
},
"Account:acc-111": {
__typename: "Account",
id: "acc-111",
balance: 50000,
customer: { __ref: "Customer:12345" }
}
}
Beneficio: Si Customer:12345 se actualiza en cualquier query,
todas las vistas que lo usen se actualizan automáticamente.
| Caso de Uso | Endpoint REST | Razón |
|---|---|---|
| Upload archivos | POST /api/v1/documents/upload | GraphQL no eficiente para binarios |
| Download archivos | GET /api/v1/documents/:id/download | Streaming optimizado |
| Webhooks externos | POST /webhooks/ach-callback | Servicios externos esperan REST |
| Health checks | GET /health, GET /ready | Simplicidad, usado por K8s |
graph TB
GATEWAY[APOLLO GATEWAY GraphQL Federation
• Schema Stitching]
subgraph "CAPA DE SERVICIOS FRONTEND"
MS1[MS-Históricos
GraphQL
• Subgraph
• Query
• Worker Pool]
MS2[MS-Pagos
GraphQL
• Subgraph
• Mutation
• SAGA Pattern]
MS3[MS-Autenticación
REST
• POST /login
• OAuth 2.0]
end
KAFKA[KAFKA EVENT BUS
• saga.orchestration
• transactions.created
• audit.events]
subgraph "CAPA DE SERVICIOS BACKEND"
MS4[MS-Auditoría
GraphQL
• Subscription]
MS5[MS-Notificaciones
GraphQL
• Worker Pool]
MS6[MS-Datos-Cliente
GraphQL
• DataLoader]
end
GATEWAY --> MS1
GATEWAY --> MS2
GATEWAY --> MS3
MS1 --> KAFKA
MS2 --> KAFKA
MS3 --> KAFKA
KAFKA --> MS4
KAFKA --> MS5
KAFKA --> MS6
style GATEWAY fill:#667eea,stroke:#333,color:#fff,stroke-width:3px
style KAFKA fill:#764ba2,stroke:#333,color:#fff,stroke-width:3px
style MS1 fill:#4caf50,stroke:#333,color:#fff
style MS2 fill:#4caf50,stroke:#333,color:#fff
style MS3 fill:#ff9800,stroke:#333,color:#fff
style MS4 fill:#2196F3,stroke:#333,color:#fff
style MS5 fill:#2196F3,stroke:#333,color:#fff
style MS6 fill:#2196F3,stroke:#333,color:#fff
En arquitecturas de microservicios, las transacciones que abarcan múltiples servicios no pueden usar transacciones ACID tradicionales. El patrón SAGA soluciona esto dividiendo la transacción en pasos locales con acciones de compensación.
graph TB
SAGA[SAGA ORCHESTRATOR
MS-Pagos-Interbancarios
Estado en Redis TTL: 1h
sagaId: saga-12345
status: IN_PROGRESS
steps:
validateBalance ✓
debitAccount ✓
sendToACH ✗ FAILED
compensations:
creditAccount,
releaseHold]
KAFKA1[KAFKATOPIC
saga.orchestration]
subgraph "EVENTOS PRINCIPALES"
E1[debit.account]
E2[audit.log]
E3[send.to.ach]
end
FAIL[ACH FALLA ✗]
KAFKA2[KAFKA TOPIC
saga.compensation]
subgraph "COMPENSACIONES"
C1[credit.account
Compensate]
C2[delete.log
Compensate]
C3[notify.failure
Compensate]
end
SAGA -->|Emit Events| KAFKA1
KAFKA1 --> E1
KAFKA1 --> E2
KAFKA1 --> E3
E3 --> FAIL
E1 --> KAFKA2
E2 --> KAFKA2
FAIL --> KAFKA2
KAFKA2 --> C1
KAFKA2 --> C2
KAFKA2 --> C3
style SAGA fill:#667eea,stroke:#333,color:#fff,stroke-width:3px
style KAFKA1 fill:#764ba2,stroke:#333,color:#fff
style KAFKA2 fill:#764ba2,stroke:#333,color:#fff
style E1 fill:#4caf50,stroke:#333,color:#fff
style E2 fill:#4caf50,stroke:#333,color:#fff
style E3 fill:#4caf50,stroke:#333,color:#fff
style FAIL fill:#f44336,stroke:#333,color:#fff,stroke-width:3px
style C1 fill:#ff9800,stroke:#333,color:#fff
style C2 fill:#ff9800,stroke:#333,color:#fff
style C3 fill:#ff9800,stroke:#333,color:#fff
| Paso Original | Acción de Compensación | Tiempo Límite |
|---|---|---|
| validateBalance | Liberar hold de saldo | Inmediato |
| debitAccount | Acreditar monto debitado | < 30 segundos |
| auditLog | Marcar log como revertido | < 10 segundos |
| sendToACH | Solicitar cancelación ACH | < 5 minutos |
| notifyUser | Enviar notificación de fallo | < 1 minuto |
| Aspecto | Propuesta (Microservicios + GraphQL + Node.js) | Monolito REST + Java |
|---|---|---|
| Time-to-Market | 4-6 meses | 8-12 meses |
| Latencia API | <200ms (p95) | 350-500ms (p95) |
| Bandwidth mobile | 45 KB/request | 150 KB/request |
| Escalabilidad | Independiente por servicio | Todo o nada |
| Deployment | Sin downtime | 5-15 min downtime |
| Resiliencia | Fallo aislado | Fallo total |
| Costo 3 años | $90,000 | $150,000+ |