Adapter Pattern — Your Gauntlet for Integrating multiple data sources

Logesh Rajendran
3 min readMay 16, 2019

--

Source — https://hdqwalls.com/wallpapers/iron-man-infinity-gauntlet-4k-dp.jpg

Many of you would have gotten excited about the gauntlet to control the power from all the infinity stones that the Iron man made to tackle Thanos. What if you are given an ability to forge a gauntlet to tackle your data integration problems! What if you got infinity data from various sources to be adapted to the system that you built! To me, that’s as exciting as the one that Iron man made.

Since the rise of microservices and the containerization, the software world is full of incredibly complex data integration problem. The data flows zigzag through your systems that are hard to manage without proper tools. Often the data from different systems have to be tied together to give the end user, the software they need.

In the world of Object Oriented Programming, you can find patterns more often than you can realize. Many patterns started evolving after the OOP languages came into existence and widely used. When similar problems are solved using objects, patterns can be identified. Once the pattern is identified, they can be widely used to simplify software development and drastically reduce the time taken for it. It is also a common practice that the patterns are packaged as a dependency by the Open Source Communities.

The Universe is full of problems and patterns and when you see the pattern for your problem, you got infinity power. One such pattern which gave me an incredible power to solve the data integration problem is Adapter Pattern. The problem I faced was that I had one ‘View’ but multiple data sources in which the data format in each source varies to some degree.

Figure 1: Adapter Gauntlet

In the above figure, you can find the adapter pattern resembling the Infinity Gauntlet where each stone is controlled by an Adapter stone.

Since each source varies only slightly in the data format, each can be mapped to an adaptee and normalized by the adapter. The data, when it is normalized by the adapter, it is ready to be consumed by the view which is provided to the end user.

Figure 2: Data integration using Adapter Pattern

With this pattern implemented, you can get an amazing level of flexibility to your integrating workload. Adding and removing more data sources to your system is just a snap away. But don’t snap it yet. You can actually extend this power furthermore by a simple adjustment to this pattern.

Google has identified the Adapter pattern to be used in containerization environment [1]. The use case mentioned by Google is that the Adapter is used to adapt the performance data for monitoring the containers running with a different version of containers each differing slightly. Here I can see the adapter pattern can be extended by grouping similar version of containers under one roof.

Figure 3: Adapter Tree Gauntlet

You got more power with an extension to the adapter pattern and I call it Adapter tree pattern. With adapter tree pattern in your hand, you can solve more complex data integration problem with more flexibility added to your system and code maintainability. Let’s consider you have a tree of versions of code running in your microservices being your data source where it is not possible to update all the microservices at once. Now with this adapter tree pattern, you will be able to snap without even getting affected by the gamma radiation.

Snap!!!!!!

References

1 . https://storage.googleapis.com/pub-tools-public-publication-data/pdf/45406.pdf

2. https://en.wikipedia.org/wiki/Adapter_pattern

--

--