Building Scalable Multi-Tenant Architecture for Indian Logistics
Sajeshkumar Adeya
CTO TechSonance
When building software for the Indian road transport and logistics sector, scalability isn't just about handling high request volumes. It's about ensuring absolute data isolation, resilient offline syncing, and handling complex regulatory requirements like GST, e-Way bills, and multi-tenant billing.
In this article, we share our architectural learnings from building FreightFlow, a full-stack multi-tenant SaaS platform built exclusively for Indian road transport operators.
The Core Challenge: Data Isolation at Scale
In logistics, data security is paramount. Fleet owners, transporters, and consignees all demand that their transaction sheets, driver payrolls, and pricing agreements remain strictly isolated. We evaluated two multi-tenant architectural strategies:
- Database-per-tenant: High isolation, but complex database migrations and high base server costs.
- Shared database with Row-Level Security (RLS): Unified schema, easy migrations, and robust security handled natively at the database level.
Implementing PostgreSQL Row-Level Security
We selected PostgreSQL Row-Level Security combined with Supabase schemas to enforce tenant isolation. Every table contains a tenant_id column. We configured the database to deny all reads and writes by default, enabling access only through a session-level tenant identifier:
-- Enable Row Level Security
ALTER TABLE lorry_receipts ENABLE ROW LEVEL SECURITY;
-- Create Tenant Policy
CREATE POLICY tenant_isolation_policy ON lorry_receipts
FOR ALL
USING (tenant_id = current_setting('app.current_tenant_id', true));
Optimizing Per-Trip Profit & Loss Queries
For transporters, calculating real-time profitability per vehicle requires aggregating trip earnings (freight charges) against immediate operational expenditures (fuel costs, driver wages, Toll payments, and vehicle repairs). We implemented indexed database views that compute material aggregates on the database layer, allowing FreightFlow to render financial metrics in under 150ms on mobile devices.
Conclusion
By pushing multi-tenancy rules and complex calculations down to the database level, we built a highly secure, fast, and maintainable ecosystem that handles hundreds of truck transactions concurrently.
Keep Reading
Why We Chose React 19 and Next.js for SyncServe Retail POS
Discover why offline-first IndexedDB structures and React 19 concurrent features are crucial for modern checkout terminals.
Agentic AI Workflows: The Next Frontier in Business Automation
Moving beyond simple chatbots. How we design autonomous AI agents to execute complex validation and internal operations.