Assumptions
Storage
// log request
logAction(user, url, action, timestamp)
action can be structured type like
{
actionName,
sessionId,
metadata, // {kv pairs}
}
// query path
getData(query) // query is a custom query format
Since the log data is not strongly structured, there is weak relationship between each row, and we have high write throughput, we choose a no-sql database like Cassandra, DynamoDB.
Schema
IngestService
LogQueue
LogProcessingService
AggregationService
ReportClient and service
RetentionService
Ingestion flow
Query flow
Database
Log processing service
Aggregation service
IngestService, LogProcessingService, ReportService are stateless and can be horizontally scaled.
The LogQueue ingestion rate is ~1M * 1k * 20 / 86400 = 20k/sec and data throughput is ~200k/sec. This is not enormous but should should shard the message queue by customer as well.
There might be a spurt of high traffic. In that case the data pipeline should gracefully degrade
We should have monitoring and alerting in place.
All database should be high availability mode, have replicas.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?