Architecture Overview
Earna AI’s architecture is designed as a modern, microservices-based financial platform that prioritizes security, scalability, and real-time processing while leveraging open-source technologies.
Architecture Principles
Core Principles
- Microservices Architecture - Modular, independently scalable services
- Event-Driven Design - Real-time data processing and updates
- Open Source First - Leverage best-in-class OSS solutions
- Security by Design - Zero-trust architecture with defense in depth
- API-First Development - Everything accessible via standardized APIs
High-Level Architecture
Service Architecture
Microservices
Microservices Design
Service Decomposition
Each service is designed with single responsibility principle and clear domain boundaries:
Credit Engine Service
Service: Credit Engine
Language: Node.js/TypeScript
Responsibilities:
- Credit score monitoring
- Credit optimization algorithms
- Dispute management
- Credit simulation
Dependencies:
- TigerBeetle (ledger)
- Plaid (data source)
- Supabase (metadata)
- Redis (caching)
APIs:
- /api/credit/score - Get credit scores
- /api/credit/optimize - Optimization recommendations
- /api/credit/simulate - What-if analysis
- /api/credit/dispute - Dispute management
Payment Service
Service: Payment Service
Language: Node.js/TypeScript
Responsibilities:
- Payment processing
- Bill payments
- Subscription management
- Transfer operations
Dependencies:
- Hyperswitch (payment orchestration)
- TigerBeetle (ledger recording)
- Redis (idempotency)
APIs:
- /api/payments/* - Payment operations
- /api/transfers/* - Money transfers
- /api/bills/* - Bill payments
- /api/subscriptions/* - Recurring payments
Analytics Service
Service: Analytics Service
Language: Python/TypeScript
Responsibilities:
- Data aggregation
- ML model serving
- Report generation
- Real-time analytics
Dependencies:
- ClickHouse (analytics DB)
- TensorFlow/PyTorch (ML)
- Apache Kafka (streaming)
APIs:
- /api/analytics/* - Analytics queries
- /api/insights/* - AI insights
- /api/reports/* - Report generation
AI Service
Service: AI Service
Language: Python
Responsibilities:
- Natural language processing
- Predictive modeling
- Recommendation engine
- Anomaly detection
Dependencies:
- OpenAI/Anthropic APIs
- Custom ML models
- Vector database (Pinecone)
APIs:
- /api/ai/chat - Conversational AI
- /api/ai/predict - Predictions
- /api/ai/recommend - Recommendations
Service Communication
Scalability Strategy
Horizontal Scaling
Component | Scaling Trigger | Scale Limit | Method |
---|---|---|---|
API Gateway | CPU > 70% | 20 instances | HPA |
Credit Engine | Request queue > 100 | 10 instances | HPA |
Payment Service | CPU > 60% | 10 instances | HPA |
TigerBeetle | Storage > 70% | 10 nodes | Manual |
Redis | Memory > 80% | 6 nodes | Manual |
PostgreSQL | Connections > 80% | 5 replicas | Auto |
Performance Targets
SLA Targets
- API Response: p95 < 200ms, p99 < 500ms
- Transaction Processing: < 100ms
- Database Queries: p95 < 50ms
- Cache Hit Rate: > 90%
- Availability: 99.99% (52 minutes/year)
Capacity Planning
Current Capacity:
Users: 100,000 active
Transactions/day: 10 million
API requests/second: 5,000
Storage: 10TB active data
Growth Projections:
6 months: 500,000 users
12 months: 1 million users
24 months: 5 million users
Scaling Plan:
Phase 1 (0-6 months):
- Current infrastructure
- Optimize queries
- Improve caching
Phase 2 (6-12 months):
- Add read replicas
- Implement sharding
- CDN for static assets
Phase 3 (12-24 months):
- Multi-region deployment
- Global load balancing
- Edge computing
Technology Decisions
Build vs Buy vs Open Source
Component | Decision | Rationale |
---|---|---|
Ledger | Open Source (TigerBeetle) | Performance, reliability, cost |
Payments | Buy (Hyperswitch) | Compliance, complexity |
Banking Data | Buy (Plaid) | Bank relationships, compliance |
Database | Open Source (PostgreSQL) | Flexibility, cost, community |
Analytics | Open Source (ClickHouse) | Performance, cost |
ML Platform | Build + Buy | Custom models + OpenAI/Anthropic |
Monitoring | Open Source (Prometheus) | Customization, cost |
Cost Optimization
Infrastructure Costs (Monthly Estimate)
Compute:
Kubernetes Cluster: $5,000
TigerBeetle Nodes: $2,000
Database Instances: $3,000
Redis Cluster: $1,000
Total: $11,000
Storage:
Block Storage: $1,000
Object Storage: $500
Backups: $500
Total: $2,000
Network:
Data Transfer: $1,000
Load Balancers: $500
CDN: $500
Total: $2,000
Services:
Plaid: $2,000
Hyperswitch: $1,000
AI APIs: $1,000
Monitoring: $500
Total: $4,500
Total Monthly: ~$20,000
Optimization Strategies
- Reserved Instances: 40% cost reduction
- Spot Instances: For batch processing
- Auto-scaling: Scale down during low usage
- Caching: Reduce database queries
- CDN: Reduce bandwidth costs
Related Documentation
- Implementation Phases - Development roadmap
- Core Technologies - Technology deep dive
- Design Structure Matrix - System dependencies
- Implementation Guide - Execution plan
Last updated on