Linuus
Advice on using MQTT vs pure Elixir to talk to embedded devices?
I’m researching a project where I need to talk to a lot of embedded devices (let’s say it’s 10s of thousands of devices). We need to be able to send/receive commands, state, configurations, see online/offline status etc.
We are currently discussing two options that I’d like some advice on, if you have experience.
Option 1: MQTT
Basically, we’d have
Device <-- MQTT --> MQTT Broker <-- MQTT --> Elixir App <-- HTTPS --> Other services
Here all devices connect to the MQTT Broker, and also the Elixir app. Other services can all the HTTP endpoints to send commands or query devices without having to deal with MQTT.
Pros:
- Devices does not drop connection on deploys etc of the Elixir App
- MQTT is a battle tested and performant protocol with good brokers around
- Built in QoS (exactly-once, at-least-once delivery etc)
- Elixir app would be a bit simpler
Cons:
- Another service to configure and maintain
- Expensive to pay for hosted/managed options (especially if you want persisted messages etc)
Option 2: Pure Elixir
Here we’d skip MQTT and just connect directly, like:
Device <-- Websocket? --> Elixir App <-- HTTPS --> Other services
The idea here is that we skip MQTT and all devices connect directly to the Elixir app (maybe using Phoenix Channels if possible). We’d run processes for each device which handles and routes commands and requests appropriately.
Pros:
- Only one service to maintain
- Can do whatever we want in Elixir compared to only features available in the MQTT broker
Cons:
- All devices will drop their connection on deploys/restarts and will have to reconnect
- A more complex Elixir application
For me, I’m leaning more towards option 1 since I see a lot of value in not having to deal with the long running connections, they are instead managed by the broker. But, I also haven’t really used MQTT before (other in some toy projects)…
Has anyone done anything similar and have some advice?
Most Liked
Linuus
Thanks for the replies. Yeah it sounds like using an MQTT broker is the way to go.
One of the biggest upsides to me is that we don’t need to “care” about all the live connections in the Elixir app. We will probably release/update/restart the Elixir app a lot more often than the broker so we avoid the issue of all devices dropping connections every time we do that.
tty
I would definately go with option 1 for pretty much your reasonings. Using RabbitMQ of course ![]()
dimitarvp
Your Option 2 is also in the danger of losing messages. I too dislike having too many apps but having a separate message broker is basically normal table stakes (and common sense) as much as having a dedicated DB is.
Centralizing message acceptors in Elixir would also mandate you having several copies of the app and gradual termination so no messages are lost. Needless complexity IMO.
So Option 1 I’d say. Plus you don’t have to choose between Kafka and RabbitMQ, for example. I’d use NATS. Looks like a better version of Kafka for anyone who doesn’t need literal hundreds of thousands of messages per second.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









