Linuus

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

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

tty

I would definately go with option 1 for pretty much your reasonings. Using RabbitMQ of course :slight_smile:

dimitarvp

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.

Where Next?

Popular in Questions Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement