IoT applications often need to manage large volumes of device-generated time-series data. A Time-Series Database (TSDB) is designed for this pattern, but performance and maintainability still depend heavily on data modeling and write strategy. In TDengine TSDB, the key decisions include database boundaries, Supertable design, Subtable creation, Tag selection, and the right write method for the workload.
IoT data characteristics
IoT data typically has several defining characteristics: many devices generate data continuously, each data point carries a timestamp, device metadata is relatively stable, and measurement values change over time. These characteristics fit the strengths of a TSDB.
Before starting modeling, you need to decide whether to create one or multiple databases based on data characteristics. If different device types have significantly different data structures, or require independent retention policies, the Time-Series Database supports multi-database storage for independent management.
Supertable design principles
The Supertable is the core concept in the TDengine TSDB data model. It defines the common schema for a class of devices. When designing a Supertable, the most important step is distinguishing between static Tags and measurements.
Static Tags: describe the inherent attributes of a device, such as device group and installation location. These do not change after data is written. Measurements: values that change continuously over time, such as current, voltage, and phase.
Taking a power monitoring scenario as an example, you can design the following Supertable:
CREATE STABLE IF NOT EXISTS power.meters (
ts TIMESTAMP,
current FLOAT,
voltage INT,
phase FLOAT
) TAGS (groupId INT, location BINARY(24))
In this structure: ts TIMESTAMP is the timestamp column, required in every table as the time-series index for the data. current FLOAT, voltage INT, and phase FLOAT are measurements that record the device’s real-time measurement data. groupId INT and location BINARY(24) are static Tags that identify the group and installation location of the device.
Subtable creation
Each data collection point corresponds to a Subtable. The Subtable inherits the Supertable structure and carries specific Tag values. The Time-Series Database provides an automatic table creation syntax that creates Subtables while writing data:
INSERT INTO power.d1001 USING power.meters TAGS(2,'California.SanFrancisco')
VALUES (NOW + 1a, 10.30000, 219, 0.31000)
This statement means: use the structure of the power.meters Supertable, create a Subtable named power.d1001, set the Tag groupId to 2 and location to California.SanFrancisco, and write one row of measurement data.
The automatic table creation syntax greatly simplifies table management in IoT scenarios. With a large number of devices, the Time-Series Database does not require pre-creating a Subtable for each device. Instead, table creation happens automatically when data is first written.
Writing method selection strategy
TDengine TSDB provides two main write methods for different IoT scenarios.
Standard SQL writing: uses INSERT statements, suitable for scenarios where data format is known and table structure is predefined. It supports single-row and batch writing. Combined with the automatic table creation syntax, it can flexibly handle new device connections. The Time-Series Database also supports parameter binding writes, which avoid repeated parsing overhead through precompiled SQL, improving write efficiency.
For large-scale data collection scenarios, you can also enable a high-efficiency write mode. The connector automatically creates write threads with dedicated queues, buffers data split by Subtable, and sends it in batches when a data volume threshold or timeout condition is met. This reduces network requests and increases throughput.
Schemaless mode writing: no need to create tables in advance. Write data directly, and the Time-Series Database automatically parses the data and creates the corresponding table structure. This mode is compatible with the InfluxDB line protocol, OpenTSDB TELNET line protocol, and JSON format protocol. It is suitable for scenarios where data formats are not fixed or rapid prototyping is needed.
Write performance optimization suggestions
In IoT scenarios, write performance is often a system bottleneck. Here are optimization suggestions based on Time-Series Database characteristics.
Configure batch parameters appropriately: by adjusting batch size and cache size parameters, you can find a balance between memory usage and throughput. The default batch size is 1000 rows and the default cache size is 10000 rows, which is suitable for many medium-scale IoT applications.
Use multi-threaded writing: the write capacity of a Time-Series Database is linearly correlated with the number of write threads configured. For high-concurrency scenarios, you can increase the number of background write threads appropriately. Each write thread has an exclusive fixed-size message queue.
Enable automatic reconnection: in IoT environments, network fluctuations are common. Enable the automatic reconnection feature and configure reasonable retry intervals and retry counts to ensure write reliability.
Data subscription and consumption
IoT platforms often need to push collected data to downstream systems in real time. The Time-Series Database provides built-in data subscription functionality, supporting topic and consumer group creation. This can replace traditional message queue products. Using the native subscription capability of a Time-Series Database simplifies system architecture and reduces operational costs.
Summary
In IoT scenarios, effective TSDB data modeling starts with a clear distinction between static Tags and changing measurements, then uses Supertables and Subtables to organize device data at scale. Combined with automatic table creation and high-performance write mode, TDengine TSDB can simplify the path from device connection to durable storage while keeping the model maintainable as the system grows.


