InfluxDB Schema Design and Layout
InfluxDB is an open-source time series database developed by InfluxData. It's optimized for storing and querying time series data, which includes metrics and events or any data that is time-stamped.
The below guidelines help understand the terminologies that exist in InfluxDB and how a good schema design can be built.
Each measurement is a simple name that describes the schema.
Keys don't repeat within a schema.
Keys don't use reserved keywords or special keywords.
Tags store metadata common across many data points.
Fields store numeric data.
Fields store unique or highly variable data.
Measurements and keys don't contain data. (Tag values and field values will store data.)
Tags and Fields
Tag values are indexed, and field values aren't. This means that querying tags is more performant than querying fields. Your queries should guide what you store in tags and what you store in fields. In addition, you'll keep cardinality low by not creating measurements and keys as you write data.
Use fields for unique and numeric data
Store unique or frequently changing values as field values.
Store numeric values as field values. (Tags only store strings).
Use tags to improve query performance
Store values as tag values if they can be reasonably indexed.
Store values as tag values if the values are used in filter() or group() functions.
Store values as tag values if the values are shared across multiple data points, i.e. metadata about the field.
Keep tags simple
Use one tag for each data attribute. If your source data contains multiple data attributes in a single parameter, split each attribute into its own tag. When each tag represents one attribute (not multiple concatenated attributes) of your data, you'll reduce the need for regular expressions in your queries. Without regular expressions, your queries will be easier to write and more performant.
References:
InfluxDB schema design | InfluxDB OSS v2 Documentation (influxdata.com)