Why Microservices for Keneya?
A medical platform must be scalable, resilient and modular. Microservices allow us to:
Global Architecture
Keneya consists of 7 microservices:
Main Services
Inter-Service Communication
1. REST API via API Gateway
typescript
// api-gateway/src/main.ts
import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'
async function bootstrap() {
const app = await NestFactory.create(AppModule)
// Proxy to microservices
app.setGlobalPrefix('api/v1')
await app.listen(3000)
}2. Event-driven with Redis Pub/Sub
typescript
// consultation.service.ts
async completeConsultation(consultationId: string) {
const consultation = await this.consultationRepo.findById(consultationId)
consultation.status = 'completed'
await consultation.save()
// Publish event
await this.redisClient.publish('consultation.completed', {
consultationId,
patientId: consultation.patientId,
doctorId: consultation.doctorId
})
}
// medical-records.service.ts - Subscriber
this.redisClient.subscribe('consultation.completed')
this.redisClient.on('message', async (channel, message) => {
if (channel === 'consultation.completed') {
const data = JSON.parse(message)
// Update medical record automatically
await this.updateMedicalRecord(data)
}
})3. Real-time with Socket.io
typescript
// notification.gateway.ts
@WebSocketGateway({ namespace: 'notifications' })
export class NotificationGateway {
@WebSocketServer() server: Server
async sendToUser(userId: string, notification: any) {
this.server.to(`user:${userId}`).emit('notification', notification)
}
}Data Strategy
PostgreSQL for Critical Data
MongoDB for Documents
Redis for Cache
Deployment with Docker Compose
yaml
version: '3.8'
services:
auth-service:
build: ./services/auth
environment:
- DATABASE_URL=postgresql://...
- REDIS_URL=redis://redis:6379
depends_on:
- postgres
- redis
consultation-service:
build: ./services/consultation
environment:
- DATABASE_URL=postgresql://...
- MONGO_URL=mongodb://mongo:27017
depends_on:
- postgres
- mongoResults
Conclusion
Microservices add complexity, but for a platform like Keneya, the benefits in scalability and resilience are well worth the investment.
*Need help architecting your platform? [Contact us](/contact).*