Feature Coordination Realtime Design Pattern
Feature design involves defining the sequence of messages that will be exchanged between tasks. When designing a feature one of the tasks in the feature should be identified as the Feature Coordinator. The main role of the Feature Coordinator is to ensure that the feature goes to a logical completion. No feature should be left in suspended animation because of message loss or failure of a single task involved in the message interactions.
In most cases, the task coordinating the feature will be running a timer to keep track of progress of the feature. If the timer times out, the coordinator will take appropriate recovery action to take the feature execution to a logical conclusion, i.e. feature success or failure.
Feature coordination can be achieved in several ways. Some of the frequently seen design patterns are described here. The description is in terms of four tasks A, B, C and D that are involved in a feature. A is the feature coordinator in all cases.
Here, on receipt of the feature initiation trigger, A handles the message and further sends a message trigger to B. As a part of the feature, B sends a message to C. Again, C does some action and further sends a message to D. D replies back to C, C replies back to B and B further replies back to A. Finally, A indicates about the feature completion. Most of the times, tasks A, B and C will be keeping a timer to monitor the message interaction. It can be seen that there is cascade of sub-feature control at tasks C, B and A. The main advantage of this scheme is that if any involved task misbehaves, appropriate recovery action can be taken at points C, B or A, thus isolating the failure condition. This design however is more complicated to implement because B and C have to share the coordination role.
Here, on receipt of the feature initiation trigger, A handles the message and sends a message to B. B further sends a message to C and C in turn sends a message to D as part of the feature. D takes appropriate action and replies to A. Here, the feature coordinator task A would be running a timeout. The main advantage of this type of coordination is that it involves fewer message exchanges. The message handling at B and C would be fairly straightforward. However, it has a disadvantage that if some involved task misbehaves, only A would timeout and would know about the failure. But A has no means of isolating it.
Here, the feature is initiated by A by sending a message to B. B completes its job and replies back to A. A registers the completion of first phase of the feature and initiates the second phase by sending a message to C. C takes some action and replies back to A. A registers the completion of the second phase of the feature and initiates the next phase by sending a message to D. D then performs its job and replies back to A. Here, A keeps a timer for each phase of the feature. This scheme allows the feature coordinator task, A to know about the progress of the feature at all times. Thus the advantage is that A can take intelligent recovery action if a failure condition hits at some point. The main disadvantage is additional complexity at A.
Here, on receipt of the feature initiation trigger, A sends message triggers to B, C and D tasks. B, C and D perform their jobs and reply back to A. In this case A may keep one timer for all the message interactions or it may keep different timers. The main difference of this scheme from the serial coordination scheme is that there is no dependence of the different phases of the feature on each other, so they can be initiated at the same time. Like in case of serial coordination, in this scheme also, intelligent recovery action can be taken if a failure condition is hit because A knows about the feature progress at all times. In parallel coordination, the delay in feature execution is minimized due to parallel activation of sub-features. But parallel activation places a higher resource requirement on the system, as multiple message buffers are acquired at the same time.