# Secure Data Distribution Architecture in IoT Using MQTT
## 3 Distributed MQTT Architecture
### Authentication Service
The results from third scenario which was done using multiple virtual machines on Amazon cloud are in line with the result from the previous two scenario. Table 2 shows the average and minimum, maximum and average delays of publication to local and global clients and their ratios. In comparing the results to the ones shown in Figures 7 and 9, we find that even in the presence of two publishers on the same topic similar results are present in terms of difference between the minimum and maximum delays. Furthermore, the ratios show a more significant difference which is likely due to precision of time in single machine tests vs. test in the cloud. In single machine tests, we used time precision up to microseconds, while in the cloud we used milliseconds. There are three main observations that can be made about the results of our experiments:

1. Payload size does not have a major impact on the delay on average: We have shown this through the results of scenario 1. We believe there are two main reasons for this: First, there is only one publisher and two subscribers in the whole system, hence, theoretically the delays are expected to be at their minimum. Second, the use of websockets as transport layer between the brokers which behave like streaming TCP \begin{table}
\begin{tabular}{p{56.9 pt} p{56.9 pt} p{56.9 pt} p{56.9 pt}} \hline
**Measure (ms)** & **Local Subscriber** & **Global Subscriber** & **Ratio (Global/Local)** \\ \hline Average & 45.25 & 56.4 & 1.24640884 \\ Minimum & 41 & 51 & 1.243902439 \\ Maximum & 50 & 68 & 1.36 \\ \hline \end{tabular}
\end{table} 
Table 2: Average/minimum/maximum delay of messages to local and global subscribers. Figure 10: Descriptive statistics of global and local delays. Figure 9: Comparison of delay for 10 local subscribers with 10 global subscribers for a single buffer of size 100 bytes. sockets, reduce the amount of overhead associated with each transmission (e.g., only 2 bytes application layer header with every transmission). 2. Increasing the number of subscribers (global and local to the publisher) introduces more delays, which is to be expected. However, an interesting observation in our system is that the difference between arrival times for global and local clients is almost the same in the best, worst and average cases. We believe there are two main reasons for this: First, the payload is delivered to the broker which publishes it locally to its clients, which greatly improves efficiency over the case where each subscriber establishes a connection with the global broker to get the data. Second, most of the delays are introduced by the the MQTT protocol itself, as evident by the end to end publishing times for localized publisher and subscriber. Furthermore, since we are technically doing two publications (one from the local publisher and another by the remote broker to its local clients) to deliver a message end to end, the results from Figure 9 show that the overhead of data migration data migration between the brokers is negligible compared to overhead of MQTT publication. 3. The synthetic nature of these tests could have minimized the actual delay times to low values; however, in our calculations we used differences and ratios which help in giving the results more context. ## 6 Conclusions and Future Work

We proposed a service oriented architecture for data discovery and distribution in MQTT. It has three main services for: authentication, discovery and data distribution. The data distribution services authenticate themselves to other data distribution services and the discovery service through the authentication service, which implements scalable identity and claims management scheme. Furthermore, each data distribution service manages a set of local MQTT clients, through aggregating the topics they are interested in and fetching their corresponding publications from other data distribution services. The architecture is designed to be dynamic and fault tolerant, through keeping minimal state and working on the basis MQTT clients interests.