# A Multilayer Data Processing and Aggregating Fog-Based Framework for Latency-Sensitive IoT Services
## 3 Design and Implementation  
### Overview  
The architecture of the proposed \"Client-Fog-Cloud\" (CFC) framework is illustrated in this section. As shown in Figure 1, CFC consists of three main parts: (1) The device gateway; (2) the fog server; (3) the Cloud. The device gateway receives IoT data from clients that are not able to connect with the fog directly and uploads it to the nearest fog node. The fog server handles IoT data that will either be received from clients directly or device gateways. The fog server can be viewed as a middle layer or intermediate layer that links clients with the cloud. The fog nodes pre-process and filter the uploaded data before being transferred to the cloud. Accordingly, the fog server can handle urgent requests and meet the requirements of latency-sensitive services. The cloud receives all data for further processing or storage. The general architecture of the fog server is shown in Figure 2. The fog server consists of six main modules: accessing module, device module, storage module, security module, processing module, and logic controller (i.e., message broker). Figure 1: Conceptual architecture of the proposed system. The main functions of the proposed fog server are detailed in the following points. 1. Uploading data: data can be uploaded to the fog server and stored in the database. Data synchronization is enabled between the fog server and the cloud. Up-to-date data (i.e., newest data) will be stored in the fog server, while historical data will be stored in the cloud. 2. Data query: clients can query the newest data from the fog server with a promised response time. Clients also can query the historical data from the cloud as data in the fog server will be synchronized with the cloud. 3. Data Processing: the fog server supports data processing. 4. Filtering data: with some configurations, data in the fog server will be synchronized with the cloud. For example, assume that the proposed CFC framework is utilized to provide a child abduction alert service (i.e., latency-sensitive and location awareness service). Users of the service have to configure and set the threshold of the fog server. The locations of parents and children will be uploaded to the fog server continuously. The fog server computes the distance between children and their parents to check whether there is a distance change or not (i.e., if distance increases over the configured threshold). An alert with the current location of the child will be sent to the parent by the fog server whenever the computed distance is over a user-defined threshold. Data will be synchronized to the cloud periodically; they will be filtered first and synchronized when the change is out of threshold to reduce the amount of data being transferred to the cloud and thus reducing the cloud overhead. 5. Connection Aggregation: the fog server plays a key role in minimizing the number of concurrent cloud connections. Data from multiple clients will be aggregated and processed at the nearest fog node before being transferred to the cloud. The fog server aggregates data received from multiple clients' nodes, usually placed on the same geographic region, in order to aggregate all data for a given geographic region before sending data to the cloud layer, which are potentially placed in a distant geographic region. Assume that there are 2000 devices connecting to the cloud directly. This situation requires 2000 concurrent cloud connections to be established. In contrast, with the proposed framework, connection aggregation is supported. The data of these 2000 devices will be aggregated and transferred to the cloud in only one connection. 6. Authentication: the challenge-response protocol is employed to authenticate users by the fog server. In practice, logical and physical redundancy is required when implementing fog computing-based systems. Thus, eliminating the single point of failure risk which affects the availability and the reliability of the entire system.