Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commands refactoring rfc #21

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions active/0022-commands-refactoring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# [Cloud] Refactoring Commands

## Motivation

Improve how commands are delivered internally within cloud components.

## Current implementation

![](images/commands-current.png)

* Applications send commands to "command endpoint" or one of the integration APIs, like MQTT or Web Socket.
* All commands are then sent to the single Kafka topic.
* All device endpoints receive all commands and filter ones they can send to the devices connected to them.

### PROs

* Simple implementation

### CONs

* Every endpoint receive too many unnecessary commands.
* It can become a scalability problem as each endpoint need to process all commands. Each device endpoint is a potential bottleneck.
* Commands can be delayed because of the slow processing
* Device endpoint can't filter type of commands and can further dispatch unnecessary commands to the device.

## Suggested implementation

![](images/commands-new.png)

* Introduce new "Command routing service" that maintains a routing table of command subscriptions. Keeping track which device subscribes to which commands at which endpoint.
* Endpoints updates routing table on each device subscribe/unsubscribe by calling routing service API.
* On each command, command service or integration API does a lookup with the routing service and "push" command only to appropriate endpoint(s).

### PROs

* Endpoints receive only messages for devices that are connected to them and subscribed to the particular command
* Commands scalability is detached from the endpoints and can be supported by scaling up command/routing service

### CONs

* More complicated to implement. Besides the new routing service, endpoints need to implement state update and ping protocols.

## Implementation

* Implement "Command Routing" service similar to the "Device State" service, just instead of tracking connections, track command subscriptions along with the endpoint command URL. K8s Downward API can help (https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/), with exposing endpoint pods for this purpose.
* Design and implement Routing query API, which will give appropriate endpoint URL for a given device and command.
* Implement logic for command service and integration APIs to do a lookup and send commands to the endpoint URLs.
* Internal routing within endpoint to devices will stay unchanged.
1 change: 1 addition & 0 deletions active/images/commands-current.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="app.diagrams.net" modified="2022-11-09T11:33:52.681Z" agent="5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36" etag="mzVn73dyBurrKBaU2_R5" version="20.5.3" type="device"><diagram id="TMBm7D66qTGbvyY6Wzrb" name="Page-1">7Znfb9owEMf/Gh5XkThAeGwoXTu1U7sirdrL5CYm8erkIsf82l8/O3ESUtN2VSG0CHgg/vpsn+8+h2zooFG8/MpxGl1DQFjH7gbLDjrr2LZlu7b8UMpKK5bbLZSQ00BrtXBH/xItlmYzGpCsYSgAmKBpU/QhSYgvGhrmHBZNsymw5qopDokh3PmYmepPGoioUF17UOsXhIZRubLVHxY9MS6N9U6yCAewWJPQuINGHEAUT/FyRJiKXhmXYtz5M72VY5wk4n8GcHtxdv/92/39retNflx06a/bxy+omGWO2UxveAIp9bXHYlWGIXskwlf76XaQBzPBaEJGVciVOIVEjIABzwcg+T5XfnghxwEldV8CiZzTywSHR7JpwJQytqZP85fUA5xFJNCrzQkXVGbpCj8QdgMZFRQS2fcAQkC8ZnDKaKg6BKRSxbrlS4eIXMCLRMxk29Ib0PxZdtnWEVBL4iwtdjulS+WHJxOaqs54GSr4T/Aic044yWDGfXLpK3882SyemlZCBfm3WkXHX3pLls8m1qpwkYVGICaCr6SJHuCUtaJrDA10e1ED29dStMZqqWFdImE1c02RfNAgvQEq2zaoMoAigSwz3QQuIgghwWxcqx6HWRJUCa9trkClMk/ZHyLESucMzwQ0E1qsqRZ6ObDSrzxlL+zI0nUiMA+JeK2ezExxwrCg86YjW4+7ZVbzCOIYJ4EU7wifU7lJo7IXNGY4r8ktsNgbPGGxa7JoWRtgHOwMxv5nZ6//KdjrG+yNkyAFKre7W+SsYRM5Z8PXX8vI9Q7u+2/QEoP50FPO8WrNIKcoW5v5psCqJAC5Twjo9ponobfZy4fCg5qAaivvKJDBRymQTeeDlgvEObgCcdsskFeJRproaorCr5uKtvMtw+1+FLjtvcONLCMWp76YYSFvNMdr1U6vVbiM83buVU2yKtL2da1C5hHrCNYBgGXvHSzzaHIE6wDAcjZcvtsFyzwWHME6ALB61p7BcpxPfl9Aw5buC++r36FRv9e3k4lULiXdkra8Jtr9RdGxd3fAl836/5jiblT/rYXG/wA=</diagram></mxfile>
Binary file added active/images/commands-current.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions active/images/commands-new.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="app.diagrams.net" modified="2022-11-09T11:34:16.189Z" agent="5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36" etag="mpAUG98fuCvRAQDg8Jl9" version="20.5.3" type="device"><diagram id="YmAj1CXoCWVD7MHZriO5" name="Page-1">7VvbdqM2FP0aPzYLEPjyGHuSTjrNajrOrGkfFZBBDSCWkG/9+kogAbKwk9QX7CzHD7EOEpL22drn+GD3wCRZ/UphFj2SAMU9xwpWPfCl5zi2M3T4P2FZS4s9tEpLSHEgbbVhiv9F0qi6zXGAcq0jIyRmONONPklT5DPNBiklS73bjMT6rBkMkWGY+jA2rT9xwKLSOnQGtf0rwmGkZrb7o/JKAlVnuZM8ggFZNkzgrgcmlBBWvktWExQL9BQu5bj7LVerhVGUsvcMcNPHxR9T59tv0fP3x4dvXxf0x8svjlveZgHjudyxXC1bKwhQwBGRTUJZREKSwviuto4pmacBEvNYvFX3+Z2QjBttbvwHMbaW7oVzRrgpYkksr5Zziom2bk6acjKnPtqxI1tugEEaIrZr66ByAqcvIglidM0HUhRDhhf6SqCkUVj1q5HmbyTYHwHeOwvgURrcilPCmylJUWm5x2IvxS1zRskrmpCY0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jAs+Uxbkc02/xq6cXQ7B21z6vefCADOT+94c36RwZl9/q3GuDuPw==</diagram></mxfile>
Binary file added active/images/commands-new.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.