Before moving into backend systems full time, I worked as a Mobile Developer at SmilePOS from mid-2023 to early 2024. The main job was a POS system written in Flutter, running on 6 platforms, that had to sync data between devices in real time using MQTT. At the end of the year I want to look back at what building a Flutter POS with MQTT taught me, both about architecture and about working habits.
Why a POS needs real-time
A shop with several devices needs them all to show the same data almost instantly. For example, the front counter takes an order and the kitchen has to see it, or when an item runs out on one device, the others must stop selling it. Having every device poll the server periodically would be slow and waste a lot of network.
MQTT fits this problem because it is a lightweight publish/subscribe protocol designed for devices on unreliable networks. Each device subscribes only to the topics it cares about, and the broker delivers a message right away when something changes.
Why Flutter and 6 platforms
Shops use all kinds of devices: tablets, phones, and desktop computers. One codebase that builds for many platforms lets a small team keep up. Flutter does this well, but "one codebase" does not mean "no platform-specific work". Receipt printer connections, permissions, and behavior when the app goes to the background always differ between platforms.
Keeping topics organized
The thing I learned fastest is that without a clear topic structure, the system turns into a mess within a few months. The pattern I think works well goes from broad to narrow.
pos/{shopId}/orders/created
pos/{shopId}/orders/{orderId}/status
pos/{shopId}/stock/{productId}
pos/{shopId}/devices/{deviceId}/presence
With this structure, a device in one shop subscribes to pos/{shopId}/# and gets everything for its own shop, and can never see another shop's data, provided the broker permissions are set to match this structure too.
Connecting in Flutter
On the Flutter side I used the mqtt_client package. A shortened example of connecting and subscribing looks like this.
final client = MqttServerClient('broker.example.com', deviceId)
..port = 8883
..secure = true
..keepAlivePeriod = 30
..autoReconnect = true;
client.connectionMessage = MqttConnectMessage()
.withClientIdentifier(deviceId)
.startClean();
await client.connect(username, password);
client.subscribe('pos/$shopId/#', MqttQos.atLeastOnce);
client.updates!.listen((events) {
final msg = events.first.payload as MqttPublishMessage;
final payload =
MqttPublishPayload.bytesToStringAsString(msg.payload.message);
handleMessage(events.first.topic, payload);
});
Pay attention to autoReconnect and keepAlivePeriod. In a real shop Wi-Fi drops more often than you would think, and the app has to reconnect by itself without staff doing anything.
QoS: match it to the importance of the message
MQTT has three QoS levels. I used a simple rule.
- QoS 0 for data that can be lost, such as a device's online status, because it will be sent again soon anyway
- QoS 1 for orders and stock, which must arrive at least once
QoS 1 means a message can arrive more than once, so the receiver has to be idempotent. For example, every order has an id generated by the originating device, and if the same id arrives again it is skipped. I used this lesson again in many webhook systems later.
Offline is the normal state, not the exception
A POS has to keep selling even when the network is down. A shop cannot tell customers "wait until the internet comes back". The approach I think is right is:
- Always write every transaction to the local database first
- Put it in a queue waiting to be sent
- When a connection is available, send in order and remove from the queue once confirmed
The benefit is that the app behaves the same online and offline. The complexity moves into the sync, which is easier to control.
Google Maps and delivery zones
Another part I built was defining delivery areas with Google Maps. A shop draws an area boundary on the map, and the system checks which area a customer's address falls in. The lesson from this part is that spatial data should be re-checked on the server too, and the client's result should not be trusted alone.
What I learned
- Design for failure. Networks, printers, and devices will always break at the worst moment.
- Duplicate messages must not corrupt data. Idempotency is a basic requirement, not an extra.
- Test on real devices. Emulators never simulate a shop with weak Wi-Fi the way it really is.
- Cross-platform saves time but does not remove platform-specific work. Always leave time for it.
Summary
Building a Flutter POS that syncs in real time with MQTT on 6 platforms taught me to think about distributed systems while I was still a junior developer: keep topics organized, choose QoS by importance, make the receiver idempotent, and treat offline as the normal state. These principles still apply to the backend work I do every day, even though I no longer write Flutter.