Back
Kevin Riedl

18 min read · 9 Jul 2026

Next

Smart City Architecture Best Practices: MQTT, ChirpStack, LoRaWAN, Kubernetes and Terraform

The short version: a smart city platform is not one platform. It is a chain of boring decisions that must survive weather, procurement, radio limits, privacy law, public scrutiny, and a device fleet that nobody wants to touch twice. The durable architecture is layered: low-power devices at the edge, LoRaWAN or cellular for field connectivity, MQTT for telemetry ingestion, a device registry and command path, a canonical data model for interoperability, a time-series store for measurements, an event stream for downstream consumers, APIs for applications, and infrastructure-as-code underneath it all. Kubernetes and Terraform help when the team has enough DevOps maturity. They hurt when they become the project.

Planning a smart-city or IoT platform?

 Map the architecture with us

The decision that matters before the stack

Most smart-city architecture discussions start in the wrong place. They ask whether the city should use MQTT, Kafka, LoRaWAN, Kubernetes, FIWARE, AWS IoT Core, Azure IoT Hub, ThingsBoard, or a custom backend. Those are implementation choices. The first architectural decision is the operating model.

A city platform has at least five owners: the public administration that pays for the service, the operations team that must respond to incidents, vendors that maintain devices, citizens whose data may be captured indirectly, and future application teams that will reuse the data. If the platform is designed only for the first pilot, it will become a museum of integrations. If it is designed only as a universal data space, the first pilot may never ship.

So the practical question is: are you building a single-use operational system, a multi-department city data platform, or a federated data space? MQTT plus a small backend is enough for the first. A city data platform needs identity, metadata, governance, standard APIs, long-term storage, and application boundaries. A federated data space needs semantic interoperability and explicit data-sharing contracts. The stack follows that answer, not the other way around.

A reference architecture that actually survives production

Here is the software architecture we would start from for parking, waste, air quality, water, lighting, asset tracking, energy monitoring, or municipal sensor networks. It is deliberately unglamorous, and it is close to how we scope IoT platforms before a hardware pilot starts.

  1. Device and field layer. Sensors, gateways, controllers, cameras only where justified, PLCs for industrial assets, and an explicit device identity. The device must know how to reconnect, buffer, rotate credentials, report firmware version, and fail quietly when the network disappears.
  2. Connectivity layer. LoRaWAN for small, infrequent, battery-powered messages; NB-IoT or LTE-M when carrier coverage and SIM operations are acceptable; wired Ethernet or industrial networks where power and reliability matter more than battery life; Wi-Fi only when you control the site.
  3. Ingestion layer. MQTT broker or managed IoT broker for telemetry, command topics, device lifecycle events, and bridge topics. This is where you enforce TLS, certificates, topic authorization, quotas, and payload size limits.
  4. Network-server layer for LoRaWAN. ChirpStack, The Things Stack, or a managed LoRaWAN network server handles join, deduplication, ADR, downlink scheduling, frame counters, and routing to applications. Do not put LoRaWAN MAC logic in your application backend.
  5. Normalization and validation layer. Decode payloads, attach device metadata, validate units, reject impossible values, add schema versions, and write idempotently. This is the layer that turns bytes into events your city can trust.
  6. Context and data model layer. Use NGSI-LD/FIWARE or OGC SensorThings when multiple departments, vendors, or public-data consumers must understand the same entity. Use a simpler internal model for isolated systems, but still document units, location, ownership, retention, and quality flags.
  7. Storage layer. Time-series database for observations, object storage for raw payload archives, relational storage for configuration and registry data, geospatial indexing for maps, and immutable logs for audit-relevant actions.
  8. Event and integration layer. Stream validated events to analytics, alerts, dashboards, work-order systems, open data portals, and AI systems. MQTT is often the edge protocol; Kafka, NATS, Redpanda, Pulsar, or cloud-native queues often make more sense after ingestion.
  9. Application layer. Dashboards, citizen-facing services, operator consoles, anomaly detection, maintenance planning, and APIs. Keep them replaceable. The platform should not depend on one dashboard vendor.
  10. Operations layer. Terraform for infrastructure, Kubernetes or managed services for workloads, GitOps for deploys, metrics, traces, logs, backups, restore tests, SBOMs, vulnerability management, and an incident runbook a non-founder can follow at 02:00. This is where QA discipline stops being a testing phase and becomes platform hygiene.

MQTT: the best default for device telemetry, not your whole architecture

MQTT.org describes MQTT as an OASIS standard for IoT connectivity: publish/subscribe, lightweight, and designed for constrained devices and unreliable networks. That is exactly why it fits smart-city telemetry. A field device publishes to a topic; applications subscribe without the device knowing who they are. The broker becomes the decoupling point.

MQTT works well for smart-city ingestion when you use it with discipline:

  • Use topic design as an API. Topics such as city/{tenant}/{site}/{device}/telemetry look harmless until they become a contract. Decide early how tenant, application, location, device class, and event type are represented.
  • Use QoS intentionally. QoS 0 is fine for high-frequency environmental telemetry where the next sample arrives soon. QoS 1 is better for state changes, alarms, and operations where a duplicate is acceptable but a miss is not. Build idempotency anyway.
  • Do not confuse retained messages with history. Retained messages are useful for last-known state. They are not a time-series database.
  • Do not put domain truth in the broker. The broker transports events. The registry, context model, and storage layer own truth.
  • Plan for disorder. Messages from independent clients can arrive out of order. Include device timestamps, server receive timestamps, sequence numbers when possible, and monotonic validation for counters.

The most common MQTT failure mode is treating the broker as a database, integration platform, permissions engine, and analytics system. It is not. It is the pipe. A very good pipe, but still a pipe.

LoRaWAN and ChirpStack: where they belong

LoRaWAN is attractive in smart cities because the physics are city-friendly: long range, low power, low bandwidth, low cost per device, and private network ownership if you deploy gateways yourself. The LoRaWAN specification describes a star-of-stars topology where gateways relay end-device messages to a central network server, which routes packets to an application server. That network server role matters. It is not a generic message broker.

ChirpStack is the open-source LoRaWAN Network Server we would evaluate first when the city wants a private LoRaWAN network and the team can operate the stack. It provides gateway, device, tenant, and integration management, plus a gRPC API. Its configuration exposes the operational reality: PostgreSQL for persistent data, Redis for fast state, MQTT integration, regions, device classes, deduplication delay, downlink timing, and monitoring endpoints.

Use ChirpStack when you need control: your own gateways, your own tenant structure, your own integration path, and no dependency on a public LoRaWAN operator. Use a managed LoRaWAN service when the city does not have the team to operate radio infrastructure. Use NB-IoT or LTE-M when you need carrier coverage, mobility, or higher throughput and are comfortable with SIM lifecycle management. We compare the radio economics in more detail in our LoRaWAN vs NB-IoT vs Sigfox pilot-cost guide.

FIWARE, NGSI-LD and SensorThings: the interoperability layer

Smart cities fail slowly when every vendor ships its own data model. One vendor says a parking bay is a device. Another says it is an asset. A third stores occupancy as occupied: true, another as status: 1, another as a color on a map. The first year still works because the dashboard hides it. The third year hurts because procurement asks for reuse, open data, and cross-department analytics.

This is where context standards matter. The FIWARE catalogue is built around context data management and a common NGSI API. FIWARE states that NGSI-LD aligns with the ETSI standard and is JSON-LD based interoperability for federations and data spaces. The FIWARE tutorials make the pragmatic distinction well: use NGSI-v2 for simpler isolated systems, and use NGSI-LD when creating a data space or a system-of-systems.

OGC SensorThings is another strong option when the core domain is observations: things, sensors, datastreams, observed properties, features of interest, and observations. The OGC SensorThings API also defines an MQTT extension for creating observations and receiving updates. If the city already lives in GIS and sensor observations, SensorThings can be the cleanest API. If the city is building a broader context graph across assets, organizations, relationships, and data spaces, NGSI-LD/FIWARE is usually the better fit.

The best practice is not "always use FIWARE" or "always use SensorThings." It is: choose a canonical model at the boundary where data becomes shared. Inside one microservice, a simple schema is fine. At the city platform boundary, make the model explicit, versioned, documented, and boring enough for another vendor to implement.

Terraform and Kubernetes: useful, but not magic municipal dust

Terraform is infrastructure as code for building, changing, and versioning cloud and on-prem resources. It shines in smart-city work because environments are long-lived, audited, and often repeated: dev, staging, production, sometimes per municipality or per department. Use Terraform for cloud resources, networks, DNS, databases, buckets, IAM, Kubernetes clusters, managed queues, and monitoring. Keep its state remote, locked, encrypted, and out of git; HashiCorp's own state docs warn that local state limits collaboration and that version-control storage can expose secrets or cause data loss.

Kubernetes is best treated as a workload control plane. It is useful when you have multiple services, multiple environments, autoscaling needs, custom networking, GitOps, and a team that understands deployments, probes, resource limits, secrets, network policies, and disaster recovery. Kubernetes docs warn that a Kubernetes object should be managed using only one technique; mixing management styles produces undefined behavior. That is the quiet lesson for city platforms too: pick a control plane and be consistent.

For a 20-device pilot, Kubernetes may be theater. A managed container service or even a single VM with backups can be the honest start. For a multi-department platform with dozens of services and regulatory expectations, Kubernetes plus GitOps can be the right foundation. The maturity test is simple: can the team patch the cluster, rotate secrets, restore data, debug networking, and explain the deployment path without the original architect in the room? If that person is missing, a fractional CTO review before procurement is cheaper than a rebuild after rollout.

Comparing the main approaches

ApproachBest forStrengthRisk
Managed IoT cloud (AWS IoT Core, Azure IoT Hub)Teams that want to move fast and accept cloud lock-inDevice auth, MQTT endpoints, routing, rules, device shadows/twins, cloud integrationsCost visibility, regional constraints, provider-specific architecture
Open-source LoRaWAN stack (ChirpStack + MQTT + Postgres/Redis)Private LoRaWAN networks and municipal controlNetwork ownership, transparent operations, no per-device cloud dependencyRadio/network operations become your responsibility
FIWARE/NGSI-LD platformCross-department context data, data spaces, vendor interoperabilityCanonical context model, federation, smart-city ecosystemMore modeling discipline required before the first dashboard appears
OGC SensorThingsObservation-heavy systems and GIS integrationClean model for sensors, datastreams, observations and features of interestLess natural for broad non-sensor business context
Custom event platform (MQTT + Kafka/NATS + APIs)Product teams with strong engineering and unusual requirementsMaximum fit, controlled cost, no platform-shaped ceilingYou own every missing feature: registry, auth, rules, data model, UI, ops
IoT application suite (ThingsBoard-style)Fast dashboards, rules, device management, visual workflowsShort time to demo, integrated UIHarder to escape once business logic lives inside the suite

Our default recommendation is a layered hybrid: managed services where they are commodity, open standards at interoperability boundaries, MQTT at the edge, a proper event stream after validation, and Terraform from day one. Kubernetes only enters when the platform earns it. That is the same bias we bring to custom software development: choose boring foundations, then spend the creativity where the product actually differentiates.

Best practices that prevent expensive rebuilds

  • Separate telemetry, state, and command. Telemetry is an event stream. State is the latest known view. Command is an intent with acknowledgement, timeout, authorization, and audit. If you mix them, downlinks and dashboards become unsafe.
  • Make every write idempotent. LoRaWAN deduplication, MQTT QoS 1, retries, broker reconnects, and cloud rules can all duplicate data. Use deduplication IDs, device counters, timestamps, and unique constraints.
  • Version payloads and codecs. A sensor payload decoder is production code. Store the firmware version, codec version, device profile, and unit assumptions with the event.
  • Design for late and missing data. Field networks are not office networks. Your analytics must tolerate gaps, delayed packets, clock drift, and backfilled data.
  • Use device identity, not just network identity. LoRaWAN keys, X.509 certificates, SIM identities, API keys, and dashboard users are different identities. Model them separately.
  • Keep raw payloads for replay. Store raw ingress events cheaply before transformation. When a decoder bug is found, replay is cheaper than explaining why six months of environmental data is wrong.
  • Push decisions to the lowest safe layer, not the lowest possible layer. Edge filtering saves bandwidth. Edge truth can be dangerous if business rules change and devices are hard to update.
  • Treat location as sensitive. Waste bins may be harmless; traffic, mobility, cameras, and occupancy data can become personal or politically sensitive when combined.
  • Budget operations, not only build. Batteries, gateways, SIMs, certificates, firmware, dashboards, databases, backups, alerts, and vendor handovers all need owners.
  • Write the exit plan before procurement signs. Require data export, API documentation, credential handover, schema documentation, infrastructure code, and firmware/update procedures.

Security and governance: the part pilots skip

Smart-city systems live close to public infrastructure. They do not need paranoia; they need discipline. Use the NIST Cybersecurity Framework as a shared vocabulary for governing, identifying, protecting, detecting, responding, and recovering from cybersecurity risk. Use least privilege for devices, vendors, dashboards, and operators. Rotate credentials. Log commands. Audit downlinks. Separate tenants. Encrypt transport. Encrypt sensitive storage. Monitor certificate expiry. Test restore. Document who may see location and occupancy data.

For LoRaWAN, respect the split between network and application keys. For MQTT, use TLS, per-device credentials, topic-level authorization, and broker quotas. For Kubernetes, enforce network policies, secret management, admission policy, image provenance, resource limits, and runtime observability. For Terraform, keep state secure and locked. For data sharing, define retention, lawful basis, aggregation level, and public-data delay before the dashboard goes live.

The conversion point for buyers is uncomfortable but useful: if a vendor cannot explain device identity, schema versioning, data retention, incident response, and exit rights, they are selling a dashboard, not a city platform. The same red flags show up during technical due diligence: missing ownership, missing runbooks, missing data contracts, and no evidence that the system can be operated by anyone except the original builder.

A practical build roadmap

Phase 1: the smallest credible pilot

Pick one use case, one district or facility, one device family, and one success metric. Stand up ingestion, registry, decoding, validation, storage, and one operator view. Use Terraform even if the platform is small. Do not build the city data space yet. Prove the field reality first: coverage, battery, installation, message quality, operational response, and data usefulness. Treat it like a minimum credible product: small in scope, complete where failure would invalidate the test.

Phase 2: production hardening

Add device lifecycle management, firmware process, monitoring, alert routing, backups, restore tests, tenant boundaries, payload replay, schema registry, and API documentation. Decide whether the platform should standardize on NGSI-LD, SensorThings, or a simpler internal model. Introduce Kubernetes only if the deployment complexity justifies it. This is the move from proof of concept to production-ready infrastructure.

Phase 3: platform and interoperability

Expose stable APIs, publish data contracts, connect work-order systems, analytics, open data, and AI use cases. Add data governance and external developer docs. Move from "we have sensors" to "we have reusable city data." This is where FIWARE, NGSI-LD, SensorThings, and data-space thinking earn their complexity.

Sources and architecture caveat

Smart-city stacks are long-lived, but vendor products and managed-cloud features move quickly. Treat the architecture principles as stable and the tool-specific details as a July 2026 snapshot. Re-check MQTT.org, the MQTT specification page, the LoRaWAN 1.1 specification, ChirpStack docs, ChirpStack configuration, the FIWARE catalogue, FIWARE NGSI-LD tutorials, OGC SensorThings API, Terraform, Terraform state docs, Kubernetes object-management docs, AWS IoT Core protocols, AWS IoT rules, and Azure IoT Hub device twins before procurement or budget sign-off.

Kevin Riedl

"The winning smart-city architecture is boring at every layer and explicit at every boundary. Sensors can be messy. Contracts cannot."

Final thoughts

Do not buy a smart-city platform by tool name. Start with the operating model: isolated use case, city data platform, or federated data space. Use MQTT for device telemetry, but do not mistake the broker for storage, governance, or analytics. Use LoRaWAN when low-power, small-payload devices and private network ownership matter; use ChirpStack when you want to operate that LoRaWAN network yourself. Use FIWARE/NGSI-LD or OGC SensorThings at the interoperability boundary, not because a slide says open standards, but because future departments and vendors need to understand the same data. Use Terraform early. Use Kubernetes only when the team can operate it. Above all, design for duplicates, late data, firmware drift, credential rotation, raw replay, secure state, and vendor exit. That is the difference between a smart-city demo and infrastructure a city can live with.

Need a vendor-neutral architecture review?

 Book the architecture call
Back
Kevin Riedl

18 min read · 9 Jul 2026

Next

IoT pilots that become products

Planning an IoT pilot and worried about hardware, connectivity, backend, or field reliability? Wavect turns sensor ideas into usable software products.

Relevant services: