Chapter 6
Gateways, Edge, Fog, Cloud and IoT Platforms
Diploma in IOT
Introduction to IoT
•
Diploma
Gateways, Edge, Fog, Cloud and IoT Platforms
Introduction
An Internet of Things (IoT) solution is not merely a collection of sensors connected to the Internet. It is a distributed computing system in which devices generate data, communication networks transport it, and software services interpret it and produce actions. The location at which processing occurs strongly affects latency, availability, privacy, bandwidth consumption, operating cost and system complexity.
This chapter examines the principal computing and service layers used in IoT: gateways, edge computing, fog computing, cloud computing and IoT platforms. It also explains protocol translation, device registries, message brokers, rules engines, serverless processing and digital twins. The central design question is not whether processing should occur at the edge or in the cloud. Rather, it is which functions should be placed at each layer to satisfy the operational requirements of a particular application.
Learning objectives
After studying this chapter, you should be able to:
explain the purpose and functions of an IoT gateway;
distinguish protocol translation from data transformation and routing;
describe device registries, message brokers and rules engines;
compare edge, fog and cloud computing;
explain the role of an IoT platform and digital twin;
describe serverless IoT processing and its limitations;
select an appropriate processing location using latency, resilience, bandwidth, privacy and cost requirements;
identify security, governance and operational risks in distributed IoT systems.
1. The layered IoT computing model
A typical IoT architecture contains five logical levels:
Things and sensors: physical devices measure temperature, vibration, position, pressure or other variables, and actuators change the physical environment.
Connectivity: wired or wireless networks carry measurements and control messages.
Gateway and edge layer: nearby computing nodes aggregate, filter, translate and analyse data.
Fog or intermediate layer: local servers, site controllers or regional nodes coordinate multiple edge devices and provide distributed services.
Cloud and application layer: highly scalable services provide long-term storage, fleet management, analytics, dashboards, artificial intelligence and integration with enterprise systems.
These levels are logical rather than rigid. A gateway may also be an edge computer, and a cloud data centre may provide regional fog-like services. The important design principle is to place each function where its timing, availability, security and resource requirements can be met.
Layered IoT architecture from devices to cloud applications
Figure: Layered IoT architecture from devices to cloud applications
Figure: A logical IoT architecture showing progressively broader computing layers.
Data may also flow downward. Cloud policies, software updates and control commands travel through fog and edge nodes to actuators. A secure architecture therefore requires two-way communication, identity verification and authorization at every boundary.
2. IoT gateways
An IoT gateway is an intermediary system connecting devices or local networks to other networks and services. It may be a dedicated industrial computer, a home hub, a router with embedded software, or a virtual gateway running near the devices.
Gateway functions
A gateway commonly performs the following functions:
Connectivity aggregation: It connects many low-power devices to an upstream Ethernet, cellular or Wi-Fi network.
Protocol translation: It converts between communication protocols, such as Modbus or BLE on the device side and MQTT or HTTPS on the service side.
Data normalization: It changes different payload structures into a common representation, including units, timestamps and quality indicators.
Filtering and aggregation: It removes duplicates, suppresses irrelevant readings, calculates summaries and reduces upstream traffic.
Local control: It executes control logic when a cloud round trip would be too slow or unreliable.
Security enforcement: It authenticates devices, stores credentials, applies access policies and creates encrypted connections.
Buffering and store-and-forward: It temporarily stores data during an upstream outage and forwards it when connectivity returns.
Device management: It supports provisioning, configuration, diagnostics and firmware updates.
A gateway should not be confused with a simple network router. A router primarily forwards packets between networks. An IoT gateway may inspect application messages, understand device semantics and execute application logic.
Protocol translation
Protocol translation has at least three distinct parts. First, the gateway receives a message using a local protocol. Second, it interprets the message, including its address, data type, unit and quality status. Third, it publishes an equivalent message through an upstream protocol.
For example, a temperature controller may expose register values through Modbus. The gateway can read register 40001, interpret the integer 235 as 23.5 °C according to the device specification, attach a timestamp and publish a structured MQTT message. Translation must preserve meaning, not merely copy bytes. Common errors include reversed byte order, incorrect scaling, lost timestamps and confusion between signed and unsigned values.
Protocol translation also introduces a trust boundary. A gateway should validate message length and type, reject impossible values, limit command privileges and record translation errors. It should not expose a legacy industrial protocol directly to an untrusted network.
3. Core services of an IoT platform
An IoT platform is a collection of reusable services that connects devices to applications and supports their lifecycle. Platform implementations differ, but several services are common.
Device registry and digital identity
A device registry is an authoritative catalogue of devices and their metadata. A record may contain a unique device identifier, manufacturer, model, location, owner, capabilities, certificate reference, firmware version and operational status.
The registry is not simply an inventory spreadsheet. It supports lifecycle operations such as registration, activation, suspension, replacement and retirement. A device should receive only the permissions necessary for its role. For example, a temperature sensor may publish measurements but should not issue commands to a motor.
Identity must be distinct from a device's physical location or current network address. Addresses can change, while identity should remain stable enough for audit and management. Credentials should be stored securely, rotated when appropriate and revoked when a device is compromised.
Message brokers
A message broker receives, routes and sometimes stores messages between publishers and subscribers. MQTT brokers commonly use a topic hierarchy, while AMQP brokers may use exchanges, queues and routing keys. A producer does not need a direct connection to every consumer.
Publish/subscribe communication reduces coupling. A sensor publishes a reading, and several consumers may independently subscribe: a real-time dashboard, a historian, an alerting service and a machine-learning pipeline. Important broker concerns include authentication, authorization, message ordering, retained messages, delivery quality, queue limits and offline clients.
Delivery guarantees require careful interpretation. “At most once” may lose messages; “at least once” may deliver duplicates; “exactly once,” where supported, can impose performance and implementation costs and does not automatically make an entire business transaction exactly once. Applications using at-least-once delivery should use idempotent processing, such as a unique event identifier and duplicate detection.
Rules engines
A rules engine evaluates events against conditions and triggers actions. A rule might state: if freezer temperature remains above a threshold for five minutes, create an alert and send a command to activate backup cooling.
Rules engines may run in a gateway, fog node or cloud service. Local rules are suitable for safety and rapid response. Cloud rules are useful for fleet-wide policies and integration with enterprise workflows. Rules should specify units, time windows, missing-data behavior and hysteresis. Hysteresis prevents repeated switching when a measurement fluctuates around a threshold.
Rules are not equivalent to machine learning. A rule is explicit and auditable; a learned model infers patterns from data and may require monitoring for drift. Both can coexist in a dependable system, with hard safety constraints taking precedence over predictive recommendations.
4. Edge and fog computing
Edge computing places computation close to the data source or actuator. An edge node may be a gateway, industrial PC, camera controller or embedded computer. Its advantages include low response time, reduced bandwidth use, local operation during disconnection and improved data locality.
Edge resources are often constrained. They may have limited processor capacity, storage, cooling and physical protection. Software updates and observability can also be more difficult than in a centralized data centre. Edge applications should therefore be designed for failure, intermittent connectivity and remote maintenance.
Fog computing is a distributed layer between edge devices and centralized cloud services. A fog node may be located in a factory control room, telecommunications network, campus server room or regional data centre. Fog computing can coordinate several edge sites, perform regional analytics, cache services and enforce policies closer to users than a distant cloud.
The distinction between edge and fog is conceptual rather than universal. Edge usually means the immediate vicinity of devices; fog refers to one or more intermediate distributed layers. Both support a continuum of computing rather than a strict hierarchy.
Typical placement decisions
Requirement
Usually preferred location
Reason
Millisecond control loop
Device or edge
Network delay is minimized
Operation during Internet outage
Edge or fog
Local service remains available
Coordination across a factory
Fog
Several edge nodes can be combined
Long-term fleet analytics
Cloud
Scalable storage and compute
Sensitive raw video
Edge, with selected features upstream
Reduces exposure and bandwidth
Global model training
Cloud or centralized platform
Large compute and shared data
Emergency shutdown
Local safety controller
Cloud is not a dependable safety mechanism
Latency includes sensing, processing, queuing, transmission and actuation. A useful engineering budget is:
Here, each term is a time interval, measured in seconds or milliseconds. The equation is a decomposition of end-to-end delay, not a universal performance law. It assumes the stages occur sequentially; parallel or pipelined systems require a more detailed model. A control function is placed locally when its worst-case Ttotal exceeds the permitted response time or when network availability cannot be guaranteed.
5. Cloud services and serverless processing
Cloud computing provides elastic compute, storage, databases, analytics, identity services, monitoring and integration through shared infrastructure. In IoT, cloud services are valuable for large device fleets, historical analysis, dashboards, machine-learning training, backups and integration with enterprise resource planning or maintenance systems.
Cloud advantages include scale, managed operations and access to specialized services. Limitations include dependence on connectivity, recurring cost, possible data-residency constraints, variable latency and concentration of risk in a provider or account. Cloud architecture should include quotas, backup policies, regional resilience and an exit strategy for critical data.
Serverless computing allows developers to deploy functions or event-driven workflows without managing the underlying servers. An IoT event can invoke a function that validates a reading, updates a database, evaluates an alert or starts a workflow. The provider typically charges according to invocation and resource use, although pricing models vary.
Serverless is effective for irregular workloads and loosely coupled event processing. It is less suitable for strict millisecond control, persistent high-throughput processing with predictable cost, or workloads requiring specialized hardware unless the platform supports it. Designers must consider cold-start delay, execution time limits, concurrency limits, retries and duplicate events. A function should be short, stateless where possible and idempotent.
6. Digital twins
A digital twin is a software representation of a physical asset, process or system that is linked to the asset through data and, in some cases, control actions. A twin may contain identity, configuration, current state, historical observations, relationships and predicted condition.
A digital twin is more than a dashboard. A dashboard displays selected information, whereas a twin maintains a structured model of an entity and its lifecycle. For a pump, the twin may represent serial number, installation site, rated flow, current vibration, maintenance history, operating mode and predicted failure risk.
A practical twin should define:
the identity and ownership of the physical entity;
its properties, telemetry and commands;
relationships to other entities;
data timestamps, units and quality status;
permitted state transitions;
synchronization and conflict rules;
access control and retention policy.
Twin data may be stale, missing or contradictory. Systems should expose the age and quality of state rather than presenting every value as current truth. A command sent through a twin must also be authorized and acknowledged by the physical system.
Digital twins support predictive maintenance, asset visualization, simulation, commissioning and energy optimization. They do not eliminate the need for physical measurements, engineering judgment or safety interlocks.
7. Selecting a processing location
A sound placement decision begins with requirements rather than fashionable terminology. For each function, identify:
maximum acceptable response time and its worst-case, not merely average, value;
availability required during network or cloud failure;
data volume and bandwidth cost;
privacy, security and data-residency constraints;
compute, storage and power available locally;
update, monitoring and support capability;
expected operating and development cost;
need for local context or global fleet information.
A simple decision matrix can compare candidate locations. Assign each criterion a weight, score each location, and inspect the result for safety constraints. A weighted score may be represented as:
Sj = ∑(wi rij)
where Sj is the score for candidate location j, wi is the importance weight of criterion i, and rij is the rating of candidate j on that criterion. Weights should be non-negative and normally normalized so that their sum is 1; ratings must use a consistent scale. This is a decision aid, not a substitute for mandatory safety, legal or security requirements. A candidate failing a hard constraint must be rejected even if its weighted score is high.
Worked placement example
An automated packaging line must stop a conveyor when a guard is opened. The permitted response is 50 ms, and the plant must remain safe if the Internet connection fails. The cloud round trip is normally 80 ms and can be higher under congestion. The safety function therefore belongs in a local safety controller or edge node with a verified local input and output path. The cloud may receive event logs and maintenance data, but it must not be the only mechanism for emergency stopping.
A second function estimates weekly motor degradation from data collected across 200 machines. It does not control the motor directly, can tolerate minutes of delay and benefits from fleet-wide data. This function is appropriate for fog or cloud processing, with selected features or measurements transmitted from the edge.
8. Applied case: illustrative cold-chain monitoring system
Background
A food distributor operates refrigerated vehicles and warehouses. Temperature sensors produce readings every 30 seconds. Regulations and customer contracts require evidence that products remained within specified temperature limits.
Problem
The organization initially sends all readings directly to a cloud dashboard. Cellular coverage is intermittent, raw data costs are increasing, and drivers receive alerts too late. Devices also have inconsistent identifiers, making maintenance records unreliable.
Analysis
The system requires local buffering, rapid alerting and trustworthy historical evidence. A vehicle gateway can continue collecting data during connectivity loss. A cloud-only rule would be vulnerable to network delay, while a purely local system would make fleet-wide reporting difficult. Temperature readings also require unit normalization, timestamps and sensor-quality information.
Approach and solution
Each sensor receives a unique identity and certificate recorded in a device registry. A gateway translates the local sensor protocol, validates the range, attaches time and quality metadata, and stores readings in a tamper-evident local queue. A local rules engine generates an alert when temperature exceeds the product limit for a defined duration, using hysteresis to avoid repeated notifications. The gateway publishes events through MQTT when connectivity is available.
A regional service aggregates vehicle data and forwards it to the cloud. The cloud stores immutable audit records, provides fleet dashboards and invokes serverless functions for compliance reports. A digital twin represents each vehicle compartment, including target range, current state, sensor history and calibration date. Raw high-frequency data is retained according to policy, while summaries are used for routine dashboards.
Outcome
Alerts can be generated during network outages, and buffered evidence is uploaded after reconnection. Fleet managers obtain a consistent view of vehicles and sensor health. The design reduces upstream traffic while preserving data required for audits. Safety and compliance rules remain explicit and testable rather than hidden inside an opaque predictive model.
Learning points
Device identity is essential for trustworthy data.
Local buffering improves resilience without eliminating cloud benefits.
Rules requiring rapid action belong near the physical process.
A cloud platform is appropriate for fleet-wide history and reporting.
Data quality, calibration and timestamps are as important as connectivity.
9. Security, governance and operational practice
Distributed IoT systems enlarge the attack surface. Recommended practices include secure boot where feasible, signed firmware, unique credentials, certificate rotation, encrypted communication, least-privilege authorization, network segmentation and vulnerability management. Gateways should expose only necessary services and should be hardened against physical tampering.
Operations teams need observability at every layer. Useful metrics include message delay, queue depth, rejected messages, device availability, battery state, firmware version, clock synchronization and rule execution failures. Logs should be time-synchronized and protected from unauthorized alteration.
Privacy must be considered when sensors reveal people, locations, health conditions or work patterns. Collect only necessary data, define retention periods, restrict access and document lawful purposes. Data sent to a cloud provider may cross jurisdictions, so contracts and applicable data-protection requirements must be reviewed.
Automation can create physical risk. A rule or machine-learning model should not bypass safety interlocks, maintenance procedures or human accountability. Models should be monitored for data drift, false alarms and unequal impact. Human override, rollback and safe fallback states are essential for high-consequence systems.
10. Contemporary developments and best practices
Current IoT architectures increasingly use containerized edge software, lightweight orchestration, private 5G, time-sensitive networking, confidential computing and specialized AI accelerators. These technologies can improve performance, but they also add operational complexity. Adoption should follow a measured requirement, not novelty.
A practical implementation sequence is:
define the physical process and failure consequences;
establish device identity, data ownership and lifecycle procedures;
prototype the smallest useful gateway and message flow;
test disconnection, duplicate messages, clock errors and invalid data;
measure worst-case latency and resource consumption;
add cloud analytics and digital-twin functions where they create value;
automate secure deployment, monitoring, backup and recovery;
review the design periodically as devices, regulations and threats change.
The strongest architecture is usually hybrid: local control and resilience at the edge, coordination at fog or regional nodes, and scalable history and analytics in the cloud.
Chapter Summary
IoT gateways connect devices to broader services and commonly perform aggregation, protocol translation, normalization, local control, security and buffering. Device registries provide identity and lifecycle management; message brokers decouple producers from consumers; and rules engines convert events into explicit actions. Edge computing places processing near devices for low latency and resilience, while fog computing provides intermediate coordination across edge sites. Cloud services offer scalable storage, analytics and enterprise integration, and serverless functions support event-driven processing when their latency and execution constraints are acceptable. Digital twins maintain structured, connected representations of physical assets. Processing placement should be selected from requirements for latency, availability, bandwidth, privacy, safety and cost. Hybrid architectures are often the most effective, provided that security, governance, observability and safe failure are designed from the beginning.
Key Terms
Gateway: An intermediary system connecting local devices or networks to other networks and services.
Protocol translation: Conversion between communication protocols while preserving message meaning.
Data normalization: Transformation of data into a consistent structure, unit and representation.
Device registry: An authoritative catalogue of device identities, metadata and lifecycle state.
Message broker: Software that receives, routes and delivers messages between producers and consumers.
Publish/subscribe: Communication pattern in which publishers send messages without directly addressing consumers.
Rules engine: Software that evaluates conditions and triggers defined actions.
Edge computing: Processing performed close to the data source or actuator.
Fog computing: Distributed intermediate computing between edge devices and centralized cloud services.
Cloud computing: On-demand, scalable computing and storage delivered through shared infrastructure.
Serverless computing: Event-driven execution in which the provider manages the underlying servers.
Digital twin: A software representation of a physical asset or process linked to its data and lifecycle.
Store-and-forward: Buffering data locally and forwarding it when connectivity is restored.
Latency: The time taken for an event or message to travel through a system and produce a result.
Resilience: The ability of a system to continue or recover operation after faults or disruption.
Idempotence: A property in which repeating an operation produces the same effective result as performing it once.
Telemetry: Measurements transmitted from a physical device to a monitoring or processing system.
Lifecycle management: Processes for provisioning, updating, monitoring, suspending and retiring devices.
Hysteresis: Use of different activation and deactivation thresholds to prevent unstable switching.
Review Questions
Short Answer Questions
What are four common functions of an IoT gateway?
Why is a device registry important in a large IoT deployment?
Distinguish edge computing from fog computing.
What problem does a message broker solve?
Define a digital twin and state one practical use.
Long Answer Questions
Explain protocol translation in an IoT gateway and discuss the risks of incorrect units, scaling or timestamps.
Compare edge, fog and cloud computing in terms of latency, resilience, bandwidth, scalability and operational complexity.
Describe how a rules engine, message broker and device registry work together in an IoT platform.
Explain serverless IoT processing, including its benefits, limitations and suitability for different workloads.
Discuss security, privacy and governance requirements for a distributed IoT architecture.
Analytical / Application Questions
A water-treatment plant must shut a pump down within 20 ms when pressure exceeds a safety limit, but it also needs monthly fleet analytics. Recommend processing locations and justify the separation of responsibilities.
Design a gateway-to-cloud architecture for a rural sensor network with intermittent connectivity and expensive bandwidth. Identify buffering, data reduction, security and synchronization methods.
A factory wants to use a machine-learning model to predict motor failure. Decide which functions should run at the edge, fog layer and cloud, and explain how you would handle model updates, false alarms and loss of connectivity.
Multiple Choice Questions with Answers
Question 1
Which function most directly enables a gateway to connect a Modbus sensor network to an MQTT cloud service?
A. Protocol translation
B. Physical calibration
C. Battery charging
D. Cloud billing
Correct Answer: A. Protocol translation
Question 2
What is the primary purpose of an IoT device registry?
A. To replace all message brokers
B. To catalogue identities, metadata and lifecycle state
C. To provide electrical power to sensors
D. To compress every video stream
Correct Answer: B. To catalogue identities, metadata and lifecycle state
Question 3
Which placement is generally most appropriate for an emergency conveyor-stop function with a strict response deadline?
A. A distant cloud dashboard
B. A monthly analytics database
C. A local safety controller or edge node
D. An external reporting application
Correct Answer: C. A local safety controller or edge node
Question 4
Which statement best describes a message broker?
A. It routes messages between producers and consumers
B. It physically measures temperature
C. It replaces device certificates
D. It guarantees that every network is available
Correct Answer: A. It routes messages between producers and consumers
Question 5
What is a major advantage of edge processing during an Internet outage?
A. It increases dependence on cloud availability
B. It can preserve local operation and buffering
C. It removes the need for device identity
D. It guarantees unlimited storage
Correct Answer: B. It can preserve local operation and buffering
Question 6
Which statement about at-least-once message delivery is correct?
A. Messages may be duplicated, so consumers should handle duplicates
B. Messages can never be lost or duplicated
C. It requires every device to be offline
D. It is identical to physical-layer encryption
Correct Answer: A. Messages may be duplicated, so consumers should handle duplicates
Question 7
Which workload is usually well suited to cloud processing?
A. A millisecond emergency shutdown
B. A control loop that must work without connectivity
C. Long-term analytics across a large device fleet
D. A local safety interlock
Correct Answer: C. Long-term analytics across a large device fleet
Question 8
What distinguishes a digital twin from a simple dashboard?
A. A twin is always a physical sensor
B. A twin maintains a structured representation linked to an asset or process
C. A twin cannot contain historical data
D. A twin eliminates the need for measurements
Correct Answer: B. A twin maintains a structured representation linked to an asset or process
Question 9
In the latency decomposition Ttotal = Tsense + Tqueue + Tnetwork + Tprocess + Tactuate, what does Tnetwork represent?
A. Time spent sensing the physical variable
B. Time spent waiting in a local queue
C. Time required to transmit through the network
D. Time required to move an actuator mechanically
Correct Answer: C. Time required to transmit through the network
Question 10
Why is hysteresis useful in an IoT rules engine?
A. It prevents repeated switching near a threshold
B. It converts MQTT into Modbus
C. It permanently deletes old telemetry
D. It creates a device certificate
Correct Answer: A. It prevents repeated switching near a threshold