Skip to content

Update app to use InfluxDB 3 Core #38

@jstirnaman

Description

@jstirnaman

Use InfluxDB 3 Core

Overview

Migrate the IoT API sample application from InfluxDB 2.x to InfluxDB 3 Core using the @influxdata/influxdb3-client JavaScript client library.


Phase 1: Core Migration ✅

Environment Changes

Variable New Value Replaces
INFLUX_HOST http://localhost:8181 INFLUX_URL
INFLUX_DATABASE iot_center INFLUX_BUCKET
INFLUX_DATABASE_AUTH iot_center_devices INFLUX_BUCKET_AUTH
INFLUX_TOKEN Admin token Same
INFLUX_ORG Removed Not used in InfluxDB 3

References


Related

## Use InfluxDB 3 Core

Overview

Migrate the IoT API sample application from InfluxDB 2.x to InfluxDB 3 Core using the @influxdata/influxdb3-client JavaScript client library.


Phase 1: Core Migration ✅

Environment Changes

Variable New Value Replaces
INFLUX_HOST http://localhost:8181 INFLUX_URL
INFLUX_DATABASE iot_center INFLUX_BUCKET
INFLUX_DATABASE_AUTH iot_center_devices INFLUX_BUCKET_AUTH
INFLUX_TOKEN Admin token Same
INFLUX_ORG Removed Not used in InfluxDB 3

Client Library Migration

  • Replace @influxdata/influxdb-client with @influxdata/influxdb3-client v2.0.0
  • Use InfluxDBClient class with { host, token } configuration
  • Use Point class for line protocol construction
  • Use client.query(sql, database) for SQL queries
  • Use client.write(data, database) for writes

Query Language Migration

  • Convert all Flux queries to SQL
  • InfluxDB 3 Core supports SQL queries only (no Flux)
  • Query limit: Last 72 hours of data (Core limitation)

Authentication Changes

  • InfluxDB 3 Core does not have the Authorizations API
  • Implement application-level device tokens stored in iot_center_devices database
  • Generate tokens using crypto.randomBytes(32).toString('hex')
  • Store device credentials as line protocol with deviceauth measurement

API Endpoints Migrated

  • GET /api/devices - List all devices (SQL query)
  • GET /api/devices/:deviceId - Get single device (SQL query with parameter)
  • POST /api/devices/create - Create device with application token
  • GET /api/measurements - Query telemetry data (SQL query)

Phase 2: Core Enhancements

Last Value Cache (LVC)

Sub-10ms query performance for latest device readings.

influxdb3 create last_cache \
  --database iot_center \
  --table environment \
  --key-columns deviceId \
  --value-columns Temperature,Humidity,Pressure,CO2

Use case: Real-time dashboard showing current sensor values for all devices.

Distinct Value Cache (DVC)

Fast metadata lookups without full table scans.

influxdb3 create distinct_cache \
  --database iot_center \
  --table environment \
  --columns deviceId,deviceType,location

Use case: Populate device filter dropdowns, list available locations.

Processing Engine

Python plugins for data processing triggered by WAL writes, schedules, or HTTP requests.

Example: Temperature Alert Plugin

# temperature_alert.py
def process_writes(influxdb3_local, table_batches, args):
    for table_batch in table_batches:
        if table_batch["table_name"] == "environment":
            for row in table_batch["rows"]:
                if row.get("Temperature", 0) > args.get("threshold", 30):
                    influxdb3_local.write(
                        f'alerts,deviceId={row["deviceId"]},type=temperature '
                        f'value={row["Temperature"]},message="High temperature"'
                    )

Use cases:

  • Temperature threshold alerts (WAL trigger)
  • Daily device health summary (scheduled)
  • On-demand data aggregation (HTTP request)

Technical Notes

InfluxDB 3 Core Limitations

Limitation Description
Query window Last 72 hours only
Authentication No resource tokens (use application-level auth)
Availability Single node only
Processing Engine Python plugins only

Data Model Changes

InfluxDB 3 InfluxDB 2.x
Database Bucket
Table Measurement
Tags Tags
Fields Fields

References


Related

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions