Architecture & Design
Overview
Kredete Inc employs a microservices architecture designed for scalability, resilience, and maintainability. The system is built following Domain-Driven Design (DDD) principles with clear service boundaries and event-driven communication patterns.
High-Level Architecture
┌─────────────────────────────────────────────────────────────────────────────┐
│ EXTERNAL CLIENTS │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Mobile │ │ Web │ │ Partner │ │ Admin │ │ Third │ │
│ │ Apps │ │ Portal │ │ Systems │ │ Consoles │ │ Party │ │
│ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ │
└───────┼─────────────┼─────────────┼─────────────┼─────────────┼─────────────┘
│ │ │ │ │
└─────────────┴─────────────┴──────┬──────┴─────────────┘
│
┌──────────────────────────────────────────┼──────────────────────────────────┐
│ DMZ NETWORK │ │
│ ┌───────────────────────────────────────┼───────────────────────────────┐ │
│ │ API GATEWAY (Kong) │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ Rate │ │ Auth │ │ Request │ │ Load │ │ │
│ │ │ Limiting │ │ Validation │ │ Routing │ │ Balancing │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │ │
│ └───────────────────────────────────────┬───────────────────────────────┘ │
└──────────────────────────────────────────┼──────────────────────────────────┘
│
┌──────────────────────────────────────────┼──────────────────────────────────┐
│ APPLICATION LAYER│ │
│ ┌────────────┐ ┌────────────┐ ┌─────────┴──┐ ┌────────────┐ ┌────────────┐ │
│ │ Customer │ │ Loan │ │ Credit │ │ Ledger │ │ Collection │ │
│ │ Service │ │ Service │ │ Scoring │ │ Service │ │ Service │ │
│ │ (Go) │ │ (Go) │ │ (Python) │ │ (Go) │ │ (Go) │ │
│ └────────────┘ └────────────┘ └────────────┘ └────────────┘ └────────────┘ │
└──────────────────────────────────────────┬──────────────────────────────────┘
│
┌──────────────────────────────────────────┼──────────────────────────────────┐
│ MESSAGE BUS / EVENT STREAMING │
│ ┌───────────────────────────────────────────────────────────────────────┐ │
│ │ Apache Kafka Cluster │ │
│ └───────────────────────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────┬──────────────────────────────────┘
│
┌──────────────────────────────────────────┼──────────────────────────────────┐
│ DATA LAYER │ │
│ ┌────────────┐ ┌────────────┐ ┌─────────┴──┐ ┌────────────┐ ┌────────────┐ │
│ │ PostgreSQL │ │ MongoDB │ │ Redis │ │ Elastic │ │ S3/Minio │ │
│ │ (Primary) │ │ (Docs/Logs)│ │ (Cache) │ │ (Search) │ │ (Objects) │ │
│ └────────────┘ └────────────┘ └────────────┘ └────────────┘ └────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
Microservices Architecture
Service Registry
| Service | Port | Technology | Database | Description |
|---|---|---|---|---|
kredete-gateway |
8000 | Kong | PostgreSQL | API Gateway, routing, rate limiting |
kredete-customer |
8001 | Go | PostgreSQL | Customer management, profiles |
kredete-loan |
8002 | Go | PostgreSQL | Loan lifecycle management |
kredete-scoring |
8003 | Python/Flask | MongoDB | Credit scoring, ML models |
kredete-ledger |
8004 | Go | PostgreSQL | Core ledger, accounting |
kredete-collection |
8005 | Go | PostgreSQL | Collections, recovery |
kredete-notification |
8006 | Node.js | MongoDB | Multi-channel notifications |
kredete-payment |
8009 | Go | PostgreSQL | Payment processing |
kredete-analytics |
8010 | Python | TimescaleDB | Analytics, reporting |
kredete-auth |
8012 | Go | PostgreSQL/Redis | Authentication, authorization |
Service Communication Patterns
Synchronous Communication (REST/gRPC)
Used for real-time operations requiring immediate response:
┌──────────────┐ REST/gRPC ┌──────────────┐
│ Loan Service │ ──────────────────▶│Scoring │
│ │◀────────────────── │Service │
└──────────────┘ Credit Decision └──────────────┘
Use Cases:
- Credit decision requests
- Balance inquiries
- Customer profile lookups
- Real-time validations
Asynchronous Communication (Kafka Events)
Used for decoupled, eventually consistent operations:
┌──────────────┐ ┌──────────────┐
│ Loan Service │ │Notification │
│ │ loan.disbursed │Service │
│ │ ─────────────────▶ │ │
└──────────────┘ (Kafka) └──────────────┘
│
├────────▶ ┌──────────────┐
│ │Ledger │
│ │Service │
│ └──────────────┘
│
└────────▶ ┌──────────────┐
│Analytics │
│Service │
└──────────────┘
Kafka Topics
| Topic | Producer | Consumers | Purpose |
|---|---|---|---|
customer.created |
Customer Service | KYC, Notification, Analytics | New customer registration |
loan.applied |
Loan Service | Scoring, Notification | New loan application |
loan.approved |
Loan Service | Notification, Ledger | Loan approval |
loan.disbursed |
Loan Service | Ledger, Notification, Analytics | Disbursement |
payment.received |
Payment Service | Ledger, Notification | Payment confirmation |
fraud.alert |
Fraud Service | Notification, Loan | Fraud detection |
Infrastructure Architecture
Kubernetes Cluster Layout
┌─────────────────────────────────────────────────────────────────────────────┐
│ KUBERNETES CLUSTER (AWS EKS) │
│ │
│ ┌────────────────────────────────────────────────────────────────────────┐ │
│ │ INGRESS LAYER (NGINX Ingress) │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
│ │ │ TLS Term │ │ Rate Limit │ │ WAF Rules │ │ Routing │ │ │
│ │ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘ │ │
│ └────────────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────┐ ┌──────────────────────────────────────┐ │
│ │ PRODUCTION NAMESPACE │ │ STAGING NAMESPACE │ │
│ │ ┌────────┐ ┌────────┐ │ │ ┌────────┐ ┌────────┐ │ │
│ │ │customer│ │loan │ │ │ │customer│ │loan │ │ │
│ │ │x3 │ │x3 │ │ │ │x2 │ │x2 │ │ │
│ │ └────────┘ └────────┘ │ │ └────────┘ └────────┘ │ │
│ │ ┌────────┐ ┌────────┐ │ │ ┌────────┐ ┌────────┐ │ │
│ │ │scoring │ │ledger │ │ │ │scoring │ │ledger │ │ │
│ │ │x3 │ │x3 │ │ │ │x2 │ │x2 │ │ │
│ │ └────────┘ └────────┘ │ │ └────────┘ └────────┘ │ │
│ └──────────────────────────────┘ └──────────────────────────────────────┘ │
│ │
│ ┌────────────────────────────────────────────────────────────────────────┐ │
│ │ INFRASTRUCTURE NAMESPACE │ │
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
│ │ │Prometheus│ │Grafana │ │Jaeger │ │Loki │ │ArgoCD │ │ │
│ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │
│ └────────────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
Network Security Zones
┌─────────────────────────────────────────────────────────────────────────────┐
│ INTERNET │
└────────────────────────────────────┬────────────────────────────────────────┘
│
┌────────────┴────────────┐
│ WAF (AWS WAF) │
└────────────┬────────────┘
│
┌────────────────────────────────────┼────────────────────────────────────────┐
│ DMZ ZONE │
│ ┌─────────────────────────────────┴─────────────────────────────────────┐ │
│ │ Load Balancer (AWS ALB) │ │
│ └─────────────────────────────────┬─────────────────────────────────────┘ │
└────────────────────────────────────┼────────────────────────────────────────┘
│
┌────────────────────────────────────┼────────────────────────────────────────┐
│ APPLICATION ZONE │
│ ┌─────────────────────────────────┴─────────────────────────────────────┐ │
│ │ Microservices (Pods) │ │
│ └─────────────────────────────────┬─────────────────────────────────────┘ │
└────────────────────────────────────┼────────────────────────────────────────┘
│
┌────────────────────────────────────┼────────────────────────────────────────┐
│ DATA ZONE │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ PostgreSQL │ │ MongoDB │ │ Redis │ │ Kafka │ │
│ │ (RDS) │ │ (Atlas) │ │ (Elasti- │ │ (MSK) │ │
│ │ │ │ │ │ Cache) │ │ │ │
│ └────────────┘ └────────────┘ └────────────┘ └────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
Container Resource Allocation
| Service | CPU Request | CPU Limit | Memory Request | Memory Limit | Replicas (Prod) |
|---|---|---|---|---|---|
| kredete-gateway | 500m | 2000m | 512Mi | 2Gi | 3 |
| kredete-customer | 250m | 1000m | 256Mi | 1Gi | 3 |
| kredete-loan | 500m | 2000m | 512Mi | 2Gi | 5 |
| kredete-scoring | 1000m | 4000m | 2Gi | 8Gi | 4 |
| kredete-ledger | 500m | 2000m | 512Mi | 2Gi | 3 |
| kredete-payment | 500m | 2000m | 512Mi | 2Gi | 4 |
Data Retention Policy
| Data Type | Hot Storage | Warm Storage | Cold Storage | Legal Retention |
|---|---|---|---|---|
| Active Loans | PostgreSQL | - | - | Life of loan |
| Closed Loans | 2 years | 5 years | 10 years | 10 years |
| Transactions | 1 year | 5 years | 10 years | 10 years |
| Audit Logs | 90 days | 1 year | 7 years | 7 years |