Engineering
Tradeoffs.
Every architectural choice in SortMail balances latency, operational cost, and schema integrity. Here are the core technical decisions and their alternatives.
Database-First over API-First
Directly querying third-party mail APIs creates latency spikes of one to two seconds per thread. By persisting metadata to PostgreSQL and using Gmail historyId tokens for incremental delta syncs, inbox rendering stays instantaneous. The tradeoff is local storage overhead, which is negligible compared to the responsiveness gains.
Gemini 2.0 Flash over GPT-4o
High-volume inbox parsing demands high speed at low cost. GPT-4o proved too slow and expensive for batch processing. Gemini 2.0 Flash reliably enforces structured JSON output, processes 10,000 tokens in under a second, and reduces expense to roughly ₹0.25 per message.
Single-Pass Execution over ReAct Loops
Autonomous agent loops increase latency and introduce unpredictable hallucinations. SortMail uses a functional pipeline where the LLM acts as a single-pass parser returning strict JSON. Standard FastAPI backend routines handle state management, routing, and database writes.
Strict DTO Contracts over Freeform Output
We enforce strict Pydantic schemas for all extracted objects. When an AI output violates expected types or structure, the parser quarantines the payload for inspection rather than allowing invalid entries into database tables.