diff --git a/active/0022-commands-refactoring.md b/active/0022-commands-refactoring.md new file mode 100644 index 0000000..6e8f614 --- /dev/null +++ b/active/0022-commands-refactoring.md @@ -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. \ No newline at end of file diff --git a/active/images/commands-current.drawio b/active/images/commands-current.drawio new file mode 100644 index 0000000..0b9b44b --- /dev/null +++ b/active/images/commands-current.drawio @@ -0,0 +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= \ No newline at end of file diff --git a/active/images/commands-current.png b/active/images/commands-current.png new file mode 100644 index 0000000..e53f678 Binary files /dev/null and b/active/images/commands-current.png differ diff --git a/active/images/commands-new.drawio b/active/images/commands-new.drawio new file mode 100644 index 0000000..5721ef3 --- /dev/null +++ b/active/images/commands-new.drawio @@ -0,0 +1 @@ +7VvbdqM2FP0aPzYLEPjyGHuSTjrNajrOrGkfFZBBDSCWkG/9+kogAbKwk9QX7CzHD7EOEpL22drn+GD3wCRZ/UphFj2SAMU9xwpWPfCl5zi2M3T4P2FZS4s9tEpLSHEgbbVhiv9F0qi6zXGAcq0jIyRmONONPklT5DPNBiklS73bjMT6rBkMkWGY+jA2rT9xwKLSOnQGtf0rwmGkZrb7o/JKAlVnuZM8ggFZNkzgrgcmlBBWvktWExQL9BQu5bj7LVerhVGUsvcMcNPHxR9T59tv0fP3x4dvXxf0x8svjlveZgHjudyxXC1bKwhQwBGRTUJZREKSwviuto4pmacBEvNYvFX3+Z2QjBttbvwHMbaW7oVzRrgpYkksr5Zziom2bk6acjKnPtqxI1tugEEaIrZr66ByAqcvIglidM0HUhRDhhf6SqCkUVj1q5HmbyTYHwHeOwvgURrcilPCmylJUWm5x2IvxS1zRskrmpCY0GJNYFy8juGyPTwhhz4RzKd2LKk+wJInT2oPUJqiblFSRI6q/ckBgetGt0x0yLfP49pu6zw1Pco71mSp9rgHf/pX/pyYP57lnYQ/ap6j8kfJZIM/38mc4TTkximiC8wh3yRUvsRJDAs3y9GIMrTa7UDTLwpfb6Ttu9+XeC/rQGurMxs1guzA2u7KvUTZNqPhXRpklYOPh4U90rnmDrrGwrUMLG6fHgwYdAVZRpihaQaL47rkKWFbmH8DqB2e2QrfYPOkGuC5Ldg5x8IO2AZOJ9Fivva/xPgbTzX/lrcrGl9WWmt9Uo2W8erNtGxvMd9PAcyw2pECgM4VAIzOSgH6l6QA9vBceOR0zyMTiy55NLwoHrWcQZ/NIeNabfDoFTE/UvFjzmKcclVXZRFhnJGUNXSev+7FWsYhhQFG9TWZyhuBoRow4xl+wz4r/rg9gHlUuVB4B/s8gMEXFD+RHDNMUn7thTBGkkaH2xiH4gITgW4MZcvnC0JUd7vYgIx/PE7ItkRATAnzrNztDK/EOsZ5BDNxMVmFokB1A5e5e0NRGa4efLGeMW+W7/ReUOF8kGPp6ryqTmmDWP0WYvWPRSynJb27EuvyieV0Tiz7SqzPSCzX6ppYZsXiSqxPQCzP7ppYwCCWSSgJXgAZzDkS6EAp6hsVsqFeGRyMvG6hAq6BzCkLG1WjKGvcDKoyx5bKxllUp4Fk05lXPoAprxOSJDANeqcqCHuergzA6fyjq3fl+4f5Di6D76bqP/75/MwtDzzY8uBXhOjTEt4FnRPerH/+yHjQM48+3zXTaauzSxKwmR5Jk5HVbCY/CQ6CeFuE1U/XIYLsRj7Sb1GdtiALjuaDgeEDLh2v8+zz+sAd6j4YdO0D16xZmpHAUNucax5TNj+GeY593T86coYeW8VfdUV948gxlPy9em0i3kDUa0FU2Q797HzTU2UYMZ6dGzcyJHIzt93yEP5Qz8ldswDbNRFWmFXJAX9f5gaebNWZgWg0EoP/QZ73BPvRWbHM8S6TZWr6M2LZRcsNAJdKBLN6eiXCHkRwDxV3wKmJYH4cPysitEehwe4wdMjAs+Uxbkc02/xq6cXQ7B21z6vefCADOT+94c36RwZl9/q3GuDuPw== \ No newline at end of file diff --git a/active/images/commands-new.png b/active/images/commands-new.png new file mode 100644 index 0000000..37f56b4 Binary files /dev/null and b/active/images/commands-new.png differ