Where cross-module calls in a monolith would still be implemented as function calls, in a microservice architecture (MSA) they require inter-process communication.
This is a choice that cannot be easily changed: it must be assumed that changing the communication protocol will require changing every single service.
Due to the popularity of distributed systems, there is ample choice as to what protocol can be used.
- The default for GUI -> Service communication is REST
- Service -> device communication can be unique for each type of service/device. This is not a system-wide protocol
- The current language of choice for services is Python, but this is not a requirement. Contributors are free to pick a language.
- Supported by the top 5 popular backend languages
- Graceful degradation if target application not running
- Generic - should support all kinds of hypothetical services down the line
What is the most popular solution?
This article, and this one, and this one prescribe a combination of commands and events for communication in an MSA. Both come with specific advantages and drawbacks, but combined they cover all but the most extreme edge cases.
Honorable mention to this ancient article for its insights in RPC communication - many of these points are still valid concerns.
Can we apply this?
The concerns named in sources so far match our requirements: communication patterns must be very generic and flexible. We have no pressing reason to deviate from the norm.
Services already implement REST endpoints for consumption by the GUI, and sources so far indicate that it is the standard choice for RPI by a wide margin.
Named alternatives (gRPC, Thrift) require the additional overhead of a shared interface file. Their advertised advantages (speed, scalability) are less important to our system than the flexibility this would sacrifice.
Specific implementations for an event bus are often not named. For full flexibility of the system we should support asynchronous event-based communication, but further research is required to choose a protocol and vendor.
Our proposed use of microservices does not have unique requirements mandating devation from the norm.
The suggested norm is to use the RPI pattern for synchronous communication, and an event bus for asynchronous or event-driven communication.
The industry default for RPI is REST, but more research is required to determine the most suitable event bus protocol and vendor.