Platform & Messaging
SMS Analytics Architecture
SMS Analytics Architecture
The Tech231 Platform uses TimescaleDB for high-performance, time-series SMS analytics. This document describes the architecture, data model, and query patterns.
Overview
SMS analytics provides tenants with detailed metrics about their messaging activity:
- Daily aggregates: Message counts, delivery rates, latency metrics per day
- Period aggregates: Weekly, monthly, quarterly, yearly rollups via continuous aggregates
- Platform health: Cross-tenant health monitoring for operations
Data Model
sms_analytics_daily (Hypertable)
The base table for all SMS analytics. Uses TimescaleDB hypertables with:
- Time partitioning: By
date_utcfor efficient time-range queries - Space partitioning: By
tenant_idhash for multi-tenant isolation
| Column | Type | Description |
|---|---|---|
| date_utc | DATE | UTC date of the analytics period |
| tenant_id | TEXT | Tenant identifier |
| direction | TEXT | 'outbound' or 'inbound' |
| attempted_count | BIGINT | Messages attempted |
| processed_count | BIGINT | Messages processed |
| delivered_count | BIGINT | Messages delivered |
| failed_count | BIGINT | Messages failed |
| unique_recipient_count | BIGINT | Unique recipients |
| avg_send_to_final_status_seconds | DOUBLE | Average latency |
| delivery_rate_percent | DOUBLE | Delivery rate (computed) |
| failure_rate_percent | DOUBLE | Failure rate (computed) |
Continuous Aggregates
Higher-level rollups are automatically maintained by TimescaleDB:
sms_analytics_weekly: 7-day time bucketssms_analytics_monthly: Calendar month bucketssms_analytics_quarterly: 3-month bucketssms_analytics_yearly: Calendar year buckets
Data Ingestion
Fire-and-Forget Pattern
Analytics writes use Orleans [OneWay] grain calls for non-blocking ingestion:
Code
SmsAnalyticsWriterGrain
Stateless worker grain that batches analytics events:
Code
Retention and Compression
TimescaleDB policies optimize storage:
| Policy | Setting | Purpose |
|---|---|---|
| Retention | 12 months | Automatically drop old daily data |
| Compression | 7 days | Compress chunks older than 7 days |
| Segment by | tenant_id, direction | Optimize compression for tenant queries |
| Order by | date_utc DESC | Optimize for recent-first queries |
Query Patterns
Tenant Daily Analytics
Code
Period Analytics (via Continuous Aggregates)
Code
Platform Health Summary
Code
API Endpoints
Tenant-Scoped Endpoints (v2)
| Endpoint | Description |
|---|---|
GET /api/v2/sms/analytics/timeseries/daily | Daily analytics for authenticated tenant |
GET /api/v2/sms/analytics/timeseries/period | Period analytics (week/month/quarter/year) |
Internal Health Endpoints
| Endpoint | Description | Auth Required |
|---|---|---|
GET /internal/sms/analytics/health/summary | Platform-wide health summary | PlatformOperator role |
GET /internal/sms/analytics/health/tenants | Per-tenant health breakdown | PlatformOperator role |
Migration from Orleans Grain Analytics
The legacy Orleans grain-based analytics are deprecated:
Code
See SMS Analytics Integration Guide for migration steps.
Last modified on