Let's say we have 1M machines which sends 10 metrics per minute. It would be 200k QPS
If each metric is 100B in average, it would be 20MB Per Sec, it should be 630 TB per year.
The API design isn't key for this system.
We will relies on time-series databsae like influxDB which is designed specifically for metrics. It has good optimization in terms of metric data storage, query optimization and query functionality support
In the high-level, we break the whole system into 4 parts:
Metric ingestion flow:
Alert setup flow:
Alert flows:
Visualizing
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
The alert manager:
TimesDB:
client side push or pull mode:
In fact they both have pros and cons. We choose push here for lower system complexity
Push pros: 1) lower system complexity as it only needs to know the address of collector where pull has to maintain a service discovery for alive workload to pull 2) feasible to send metrics for short-live jobs which pull cannot cons: 1) cannot do locally debugging while pull support that by pulling /endpoint 2) it cannot detect if server is down or it is network issue on the monitoriong side but pull can do that
metric batching/aggregation: there are multiple places that we can do.
metric precompute: for the alerting, we can also precomputing the metrics for alerting so it can give better performance on the alerting.
The metric collector can be bottlenecks on the traffic spike so we add a message queue to solve that.
The metric collector/query server alert manager/visuallizer server are all stateless machine and they can be easily horizontally scaled up.
meta monitoring: we need to monitor the health of our system. In theory, we cannot monitor ourselves so we have to introduce another monitoring system to monitor ourselves and it shouldn't depend any of these components at all.