Contact me for consultation, training or discussion
(Reduced from 4.2s)
(Up from 150 tx/sec)
(Reduced from 8.5s)
The platform aimed to provide an all-in-one personal finance engine across Web, iOS, and Android. It unified bank account linking, automated SMS/PDF statement parsing, transaction tracking, external financial integrations (banks, stock brokers, mutual funds, loan portals), and a personalized AI recommendation engine.
However, as user onboarding scaled, transaction volume surged into millions of records. The system faced critical bottlenecks:
Dynamic Aggregation Locks: Generating real-time daily expense rollups, auto-categorization metrics, and personalized investment suggestions forced expensive MongoDB $group, $lookup, and $facet operations across millions of unindexed lead/transaction records, freezing query pipelines.
Complex Data Ingestion: Concurrent streams of automated SMS readers, linked bank feeds, and PDF statement parsers caused database write-contention and slow categorization.
LLM Tool Execution Latency: The LangChain-powered conversational agent stalled when fetching user analytics and executing commands (e.g., "Transfer savings to mutual fund" or "Show my spending breakdown") due to long database reads.
To achieve sub-second query responses and real-time interactive AI responses, the backend architecture was refactored from heavy monolithic aggregation into an event-driven microservices setup powered by pre-aggregated datasets and efficient vector retrieval.
1. MongoDB Aggregation & Schema Optimization
Bucket Pattern Implementation: Restructured raw transactional data into time-series buckets (daily/weekly collections) rather than running unindexed, raw aggregation over millions of individual documents.
Compound Indexing Strategy: Created multi-field compound indexes covering
{ userId: 1, date: -1, category: 1 } to allow index-only scans for high-frequency queries.
Asynchronous Materialized Views: Replaced live $group operations with background worker queues that maintain pre-computed aggregation views for immediate retrieval by the recommendation engine.
2. Event-Driven Real-Time Categorization Pipeline
Implemented a light hybrid rules-engine paired with Redis caching to classify incoming transactions (SMS, bank feeds) instantly before persisting them.
Offloaded heavy enrichment tasks to asynchronous background microservices, ensuring zero latency on incoming client write operations.
3. Low-Latency LangChain & RAG Integration
Custom LangChain Tools: Built dedicated, isolated micro-tools allowing the chatbot to run targeted operational commands (e.g., retrieving account balances or triggering investment checks) without scanning full transaction histories.
Context-Aware Vector Indexing: Stored embeddings of transactional summaries and user preferences in a vector collection, enabling fast semantic search for the LLM during user queries like "How much did I spend on dining out last month?"
Sub-Second Real-Time Insights: Reduced complex transaction query and categorization speeds by 96%, providing instant insights across millions of historical user entries.
Seamless Conversational Banking: Enabled an interactive, low-latency AI chatbot capable of reading user profile state, categorizing spending live, and executing cross-platform financial actions smoothly.
Linear Scalability: The system now sustains high concurrency across Web, iOS, and Android platforms while integrating cleanly with third-party payment and broker APIs without database lockups.