#1
ClickHouse is perfect for IoT data because it handles high write throughput and fast queries. Let’s build a real-time dashboard using Spring Boot.

1. Define IoT Data Model

CREATE TABLE iot_data (
  device_id String,
  ts DateTime,
  temperature Float32,
  humidity Float32
) ENGINE = MergeTree()
ORDER BY ts;

2. Insert IoT Events from Spring Boot

jdbcTemplate.update(
  "INSERT INTO iot_data (device_id, ts, temperature, humidity) VALUES (?,?,?,?)",
  "sensor-1", LocalDateTime.now(), 22.5, 60.0
);
This captures device telemetry in real time.

3. Query Data for Dashboard

List<Map<String,Object>> data = jdbcTemplate.queryForList(
  "SELECT ts, avg(temperature) AS temp, avg(humidity) AS hum " +
  "FROM iot_data GROUP BY ts ORDER BY ts DESC LIMIT 50"
);
The data is aggregated for charting.

4. Expose REST API

@GetMapping("/api/iot/latest")
public List<Map<String,Object>> latestData() {
    return jdbcTemplate.queryForList("SELECT * FROM iot_data ORDER BY ts DESC LIMIT 10");
}
This endpoint feeds dashboard components.

5. Build Frontend Dashboard

Use Chart.js or any frontend charting library to call /api/iot/latest and visualize live IoT metrics.

image quote pre code