Anti-Corruption layer

What is an Anti-corruption layer?

Tech upgrade is something that happens often. And in most cases these upgrades will happen in phases. One common challenge everyone will encounter during this process is to build a new system with its integrity and also to make it compatible with its dependent legacy systems.

One way to solve this issue is to have an intermediary layer between the new and legacy systems. This will provide us the flexibility to design the new system with its purity and without having the overhead of making it work with legacy systems. The intermediary layer will take care of jelling the gap between two systems. This layer is called as the anti-corruption layer.

Anti-corruption layer can be permanent or temporary. As discussed above when we are building this layer in migration process, mostly it will only be temporary. But there can be cases when we can have this layer permanently.

For example, if the functionality of the system is to bake cake, then all it cares about is the things associated with that. But other aesthetics like, what kind of box it should be packaged in, is it being delivered or picked up etc., should not be added to the functionality of the system. Instead it can be added to anti-corruption layer which will handle the aesthetics of the system without corrupting the actual functionality of the system. In these cases anti-corruption layer will be part of the design and will be permanent.

When to use Anti-corruption layer?

We can use this in any of the below scenarios:

  • When there is a migration happening and we need to bridge the gap between new and legacy systems
  • We have two systems which are different but still need to interact with each other

Things to consider

  • Introducing a new layer means introducing additional overhead. We need to consider latency, maintainability, scalability and to see if it is temporary or permanent.
  • We need to see how big the difference between two systems is and if it is worth to have this additional layer
  • Need to consider if this layer will reside alongside the new modern system or legacy system. Thinking about how often this will change and how many releases needs to be made will also help in determining this.