March 1, 2025
Building Real-time Cost Monitoring: Our Architecture
10 min read
Real-time cost monitoring requires streaming data from multiple sources, processing it efficiently, and serving it to users with minimal latency.
We built Sonar using Next.js, Supabase, and AWS SDKs to create a system that updates costs every 5 minutes without overwhelming APIs or databases.
Architecture overview
- Data collection: Server actions poll AWS Cost Explorer and CloudWatch every 5 minutes.
- Caching: We use Next.js unstable_cache with 1-hour TTL to avoid redundant API calls.
- Real-time updates: Supabase Realtime pushes updates to connected clients.
- Alerting: Background jobs check thresholds every minute and trigger alerts via Resend/Slack.
This architecture handles thousands of users while keeping API costs under $50/month.