Skip to main content

Jump to

↑ ↓ to move · Enter to openCtrl / ⌘ K

Every page and action

All work

Admin Reporting on 15M+ Records

Finance and operations teams run reports on 15M+ activity records on demand, instead of waiting for scheduled exports. A separate read replica keeps that load away from customer checkout.

Case studyCaretutors Technologies LimitedJul 2025 – Present

reporting · read replica
CREATE INDEX idx_activity_type_created_status
ON user_activities (activity_type, created_at, status);
Index Scan · composite index38 ms
Example · Index Seek · 38 ms

15M+activity records

The problem

Internal teams (finance, operations, executive management) were previously handcuffed to slow scheduled batch exports to analyze user activity and revenue metrics. Attempting real-time queries against the monolithic primary PostgreSQL/MySQL transactional database caused severe table contention, high CPU spikes, and risked slowing down customer checkouts.

Architecture

Architected a two-tier database strategy: decoupled analytical reads from the transactional master by routing reporting traffic to a dedicated read replica. Simultaneously restructured SQL aggregation logic and created composite covering indexes tailored to high-cardinality time-series and status filters.

Query routing

Dedicated reporting replica

Asynchronous replication gives the reporting service a separate copy to aggregate and filter. The primary stays available for checkout writes.

CREATE INDEX idx_activity_type_created_status
ON user_activities (activity_type, created_at, status);

Engineering decisions

Read Replica Routing
Configured the application database layer to isolate reporting queries to an asynchronous read replica, ensuring 0% CPU impact on transactional checkout operations.
SQL Aggregation Optimization
Replaced inefficient correlated subqueries and table scans with indexed range filtering, pre-aggregated CTEs, and selective grouping.
Composite Index Strategy
Designed multi-column indexes on (activity_type, created_at, status) to convert expensive sequential scans into rapid B-tree index scans.
Self-Serve Dashboard
Built the administrative reporting interface so business teams can generate custom slice-and-dice reports instantly without engineering intervention.

Outcomes

Reporting architecture before and after optimization
DimensionLegacyOptimized
Query targetTransactional primaryDedicated read replica
Execution timeMinutes or worker timeoutsSub-second on demand
Checkout trafficCompetes with reportingSeparate connection pool
Table accessSequential scansComposite index lookups
Operations workflowScheduled batch exportsSelf-serve reporting
Data volume
15M+ rows
Reports
Real-time, on demand
Primary database
No reporting load
Replaced
Scheduled batch exports

Tools used

  • SQL
  • PostgreSQL
  • MySQL
  • Query Optimization
  • Composite Indexing
  • Read Replicas
  • Node.js
  • React
Next case studyPlatform Q&A Chatbot (RAG)