Analytics Service
Purpose
Aggregated analytics, reporting, and dashboard data for portfolio and transaction insights.
Responsibilities
- Event ingestion and aggregation
- Portfolio analytics computation
- Spending analysis
- Dashboard data API
- Report generation
Non-Responsibilities
- Real-time balances (Account/Ledger)
- Payment processing
- Portfolio management
APIs
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/v1/analytics/portfolio/{id}/performance | Bearer | Portfolio performance |
| GET | /api/v1/analytics/spending/monthly | Bearer | Monthly spending |
| GET | /api/v1/analytics/dashboard | Bearer | Dashboard summary |
| GET | /api/v1/analytics/reports/{type} | Bearer | Generate report |
Database
| Collection | Key Fields | Description |
|---|---|---|
| portfolio_analytics | portfolio_id, roi, sharpe, volatility | Computed metrics |
| spending_aggregates | customer_id, month, categories | Spending data |
| transaction_summaries | customer_id, period, totals | Transaction stats |
Kafka
Consumes: PaymentCompleted, PortfolioUpdated, MarketPriceUpdated, LedgerEntryCreated
Produces: None
Dependencies
Async: Kafka consumer building read models
Failure Handling
- Stale data → eventual consistency acceptable
- Missing events → backfill from batch job
Scaling
MongoDB sharding by customer_id. Heavy read, moderate write.
Security
Customers access own analytics. ADMIN for platform-wide reports.
Observability
Metrics: analytics_query_latency, analytics_events_processed.