[Cloud Design Pattern] Anti-corruption Layer

Anti-corruption Layer is one of the design pattern to enable application communicate with external system.

Problem

For some reasons, some of the services cannot use common method to communicate and it cannot be change due to their own constrains. However, application still need to get resource and execute command from it. It is require to convert the response and executed result to application compatible format.

It will be time consuming if each service implement it’s own logic to communicate such “out-standing” service. Also, it will be more complicate on change when such system and it will impact to all involved services.

Solution

Implement the middle layer between services which role as a middleman to:

  1. Collect consumer request;
  2. Transform request format / communication channel and send to target system;
  3. Receive target system response;
  4. Transform response format / communication channel and send back to consumer;

Anti-corruption layer is the middleman which do tasks above. When the target system change, it can eliminate the change scale by only need to update anti-corruption layer, consumer do not need to update in their side.

Use case

  1. Communicate with legacy or specific protocol (e.g. SOAP, HL7, etc)
  2. Communicate with legacy channel (e.g. COM / RPC call, etc)

Implementation

Consideration

Compare with façade and adapter

Façade is set of interface and adapter is a converter between different system.

Anti-corruption layer combine the characteristic of façade and adapter, it provides the interfaces / event handlers to collect request and send out response between target system; In addition, anti-corruption layer contains a certain logics to translate the content to fulfill each others needs;

Compare with Ambassador

Ambassador is focus on non-fictional requirement, and anti-corruption layer is a sort of converter, so certain business logic might contain in there.

Reference

  1. Anti-corruption Layer, Microsoft Azure
    https://learn.microsoft.com/en-us/azure/architecture/patterns/anti-corruption-layer
  2. The Anti-Corruption Layer Pattern, Ahmed Shirin, Dev.to
    https://dev.to/asarnaout/the-anti-corruption-layer-pattern-pcd
About C.H. Ling 262 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.