An example application of design patterns in the software industry
A common type of mechanism used
to solve problems in the software industry is the workflow mechanism. at least
in a very broad manner of description. A service has to do a particular job,
but to do that particular job it has to query a couple of other services, and
then process all the information, persist it and then update a downstream
service with the processed information. I'll give an example from the advertising
domain.
Any advertising platform must
find out a way to filter out bad ads, could be because of vulgar test, photo
not following resolution guidelines etc. The seller interface registers the new
ads in the main database. The ad quality service periodically gets the new ads
from the registration service which are marked as under processing. The ad
quality service has to make the ad go through multiple local checks with local
persistence, and then finally it has to update the ad server with the final
verdict on whether the ad follows all guidelines and is good to go, or update
the ad server with the reason the ad was rejected. This final update itself can
be a combination of many service calls, like one service update that the ad
text is good, the other to update ad photo does not follow policy guidelines,
and another to update which regions this ad can be shown and so on. If any of
these steps fail, it can lead to an inconsistent state of the complete ad
information.
This scenario requires reverting
all the changes done by the ad quality service if any of the steps failed. This
is solved by using the undo pattern, where all steps are implemented with their
inverse/reverse also implemented in the class/service and when any step fails
all the previous steps are reverted. As patterns are named differently in
different sources, I am using Gang of Four as a reference and the patterns from this
book used are 'Chain of Responsibility' and 'Command' patterns in combination.
I like to call it 'Chain of Command'.
Comments
Post a Comment