Skip to content

Scalability: redesign MQTT Command/response pattern #2792

@knolleary

Description

@knolleary

Description

Part of #2782

The flow to create a Device Editor session involves the following initial steps (ref)

image
  • An HTTP request is made to trigger the session
  • An MQTT message is sent to the device to get it to connect
  • The device connects its websocket
  • The device published an MQTT message to confirm
  • The HTTP request from the first step is completed with the session identifier.

The key point is that, in the above flow, the initial HTTP request is only responded to when a reply to the initial MQTT publish has been received over MQTT. In a scalable system, the Forge App will use a Shared Subscription to the broker - so that work can be distributed and will mean the reply could end up at a different instance.

The other place the command/response pattern is used is when the request to create a new Device Snapshot. The command is published and the device sends back the snapshot over MQTT. The original HTTP request to create the snapshot is blocked and only responds once the snapshot has been created.

Possible Solutions

  1. Do not use a shared subscription for command/response MQTT pattern - and include a reply-to topic in the command message to ensure the response comes back to the topic subscribed to the correct instance.

    • Cons
      • Doesn't really solve the stateful nature of the command/response pattern
      • The current Device Agent has a hardcoded response topic to use - so we'd have a legacy issue with existing devices.
  2. Redesign the whole command/response pattern to support stateless behaviour. The initial HTTP response will respond once the initial MQTT message is sent with some sort of 'pending' response including a request identifier. An API can then be used to track the completion of the pending request. The exact details of which will necessarily differ between the two current use-cases of the Command/Response pattern.

    • Pros
      • Cleanest solution that doesn't require any Device Agent changes
      • Properly stateless
    • Cons
      • Not trivial to implement properly - needs some thought on database table structure.
      • Changes the external API for settings up Device Editor and capturing Device Snapshot

Epic/Story

#2782

Have you provided an initial effort estimate for this issue?

I have provided an initial effort estimate

Metadata

Metadata

Assignees

Labels

size:XLHigh-level sizingtaskA piece of work that isn't necessarily tied to a specific Epic or Story.

Type

No type

Projects

Status

Done

Status

Closed / Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions