---
title: 'MQTT Basic workflow'
disqus: hackmd
---
MQTT Basic workflow
===
## Table of Contents
[TOC]
## 1. Problems
Currently we using RESTful API and it's have too many problems
1. Using setInterval for get near-realtime data.
2. It's not actual realtime
3. Waste network resources for get the same data
4. Cannot handle big number of devices
## 2. Scope
### 2.1 What's MQTT?
### 2.2 Where we will apply MQTT?
We will apply MQTT to Server, Web, Mobile app client.
### 2.3 Why we should apply MQTT?
If we want to bring more value to user, improve the user experience, we need to apply MQTT, it's also better for the system.
### 2.4 When we will apply MQTT?
As soon as possible, we will apply to the new project, shouldn't apply to on-going proect.
## Workflows
```sequence
Device->MQTT\nServer: Connect via MQTT protocol
Web/Mobile\nClient->MQTT\nServer: Connect via WSS
Web/Mobile\nClient->MQTT\nServer: Subscribe to topic: /devices/+
Device-->MQTT\nServer: Publish message to topic\n/devices/{device_id}
MQTT\nServer-->Web/Mobile\nClient: Receive the message
Web/Mobile\nClient->Web/Mobile\nClient: Parse to JSON
Web/Mobile\nClient->Web/Mobile\nClient: Update device information\non Map
```
## What's important of MQTT system
:::info
1. Topic format
2. Optimize message data
3. Choose QoS for message
4. Build MQTT server
5. Define messageg format
:::
###### tags: `mqtt` `realtime`