Scaling Backend and MQTT

Hi everyone,

I am looking at OpenEMS and thinking about how to organize the OpenEMS Backend with UI.

Example scenario:

  • n households and each household has x Edge devices.
  • Edge devices are publishing data to the MQTT broker

Questions:

  1. OpenEMS Backend doesn’t have the MQTT controller so it is not possible to receive the data, right? Is there a plan to implement this. I was following other PRs and discussion in github and also searched this forum but can’t find an answer.
  2. Too much data for one Backend to handle with one database → how can we scale/configure multiple backends?
  3. When we scale the Backend how can one unify the UI on top of it?

Any thoughts/ideas on this.

Regards,
Jovica

Hi Jovica,

welcome to the OpenEMS community. It’s a interesting topic that we have been discussing a lot previously in our company, as well as in the OpenEMS Association.

Our typical setup is only one Edge device per household. In which use-case do you see multiple (x) Edge devices?

I agree with the use-case of n households in an apartment building, where you would have multiple EMS optimization targets on household and building/grid connection level.

No, currently there is no MQTT receiving or publishing functionality in OpenEMS Backend. The JSON-RPC method we currently use for data exchange between Edge and Backend has a quite high performance (we successfully handle thousands of parallel connections with more than 100.000 datapoints per second per Backend instance). I have been thinking about a Backend bundle that allows exporting certain of those datapoints to a MQTT broker on the backend to allow manual processing (e.g. via Node-Red).

Is your question about sending data from Backend (i.e. Backend → MQTT Broker → MQTT) or receiving data to Backend (i.e. Third party IoT device → MQTT-Broker → Backend) via MQTT?

Unfortunately right now it is not possible to have automatic scaling (e.g. via load balancing, Kubernetes, etc.) as there is a 1-to-1 connection via Websocket. We have been thinking about extracting the EdgeWebsocket and UiWebsocket to individual microservices and again use Websockets/Streams to communicate within the different Backend services. This means that at certain places in OpenEMS Backend we will have to refactor direct method calls to API calls - either manually or via OSGi Remote Services.

It’s of course already now possible to just run independent OpenEMS Backend instances.

Either with independent OpenEMS Backend instances or with the same approach as described above.

I am by far no expert in scaling cloud services, so I am curious to find your opinion on the topic and the options discussed above.

Regards,
Stefan

Hi Stefan,

thank you for your detailed answer.

  • Regarding the scenario: I was thinking about multi tenant approach. Maybe also, 2 edge devices in 2 homes but 1 owner.
  • Regarding questions: Main question was MQTT -> Backend (Third party IoT device → MQTT-Broker → Backend). Now, one can have multiple edge devices sending data to MQTT but can’t connect the backend and therefore UI. As I’m focused on MQTT part, in this scenario I would replace OpenEMS backend with some custom solution.

Need to think about your ideas regarding automatic scaling. This was theoretical discussion, right? Did you try to implement/test something?

Best regards,
Jovica

Hi Jovica,

On scenarios:

  • Multiple edge devices per owner would right now be handled via Backend. It allows having access to different edges. It originates from the requirement of an ‘installer’ role, that has access to different edges that he installed.
  • Things become difficult in multi tenant approach when you have multiple househoulds in an apartment building and need to have (1) optimization on different grid connection points (i.e. single apartment and entire building) and (2) detailed, fine-grained permission handling. Consolinno is doing something like this with OpenEMS and there is an aging/out-dated pull-request that targeted such a permission system as default OpenEMS feature. (-> Advanced Access Control and Role Management by sWalbrun · Pull Request #590 · OpenEMS/openems · GitHub by @SebastianWalbrun)

MQTT → Backend:
In principle it should be sufficient to copy the Backend.EdgeWebsocket service and reimplement it for MQTT. There might still have to be some translation/conversion from device specific MQTT topics to OpenEMS Nature Channels. Also some EdgeConfig representation will be needed for OpenEMS UI to know what it should visualize. Maybe it’s a better option to connect the third party IoT device via a (virtual) OpenEMS Edge instance. Which IoT device do you have in mind - so that I could understand the individual requirements better?

Regarding scaling this is something we keep discussing about internally, because as a company we will soon reach numbers/scenarios that require these changes. But there is no code yet.

Regards,
Stefan

Hi Stefan,

sorry for the late reply.
For some other reasons the project is currently stopped . We planned to have custom IoT devices and to use MQTT for communication. We were looking in the future regarding the multi tenant approach and scaling but as everything is stopped now, no further investigation will be done.

Thank you for your responses and open discussion.

Until next time/opportunity,
Best regards,
Jovica

1 Like