Since the invention of the computer, the basics of software design have not really changed all that much. While this technology has become much more intricate and advanced, the basic way in which programs are made has changed little since the beginning
In this article, we will explore a fascinating new idea in software design that turns the traditional structure on its head. Like all new trends, this is something that may turn out to be an improvement or a step backward. Only time will tell on that, but so far, hexagonal architecture seems to work just as well as the traditional structure. In some ways, it has even proven to be better.
What Is Hexagonal Architecture?
To understand what hexagonal architecture is, you must first understand what it is not. Traditionally, computer software (and most other software) has been made with a “layered” approach. Obviously, these are abstract terms since we are talking about computer systems, but the name describes a system that consists of programs layered on top of one another. Each layer performs a different function, and communication between layers is usually limited for security reasons.
In such a structure, the deeper levels might be described as the controller layers. These are the layers with which the user does not directly interact. At the top, you have the user interface layer, which is all the average person ever sees.
Hexagonal architecture is a particular method of software design that discards the layered approach in favor of a modular approach. This system has also been referred to as a “ports and adapters” system. Hexagonal architecture recognizes that there is no need to have so many layers in an application. In essence, all you really need is two layers: A user interface and a control core.
So, what did we mean when we said that hexagonal architecture uses a modular approach? The answer is simpler than you might think. Instead of having one control core, a hexagonal architecture system has many cores, and each one is interchangeable with the others. Because of this, there is much more versatility in the way that the programs can interact with one another.
Perhaps the most innovative aspect of this design was to incorporate a translation device into the core itself. As you probably know, there are many different “languages” that a computer might use. In most cases, the core will not be using the same language as the user interface. For instance, most web browsers speak HTTP, while most cores speak PHP or some other language. In the past, they had to add an extra layer to the structure just to accommodate the need for translation. By incorporating the core and translator (more properly called the transformer) into one unit, the entire structure is made much more simple and fluid.
Why Do They Call It “Hexagonal Architecture?”
Because we are talking about computer systems, you already know that we aren’t talking about a literal hexagon structure. A computer program has no shape unless you count the disk in which it is stored.
However, non-physical concepts can only be understood by representing them with physical images. From the beginning, software designers who utilize this structure have usually represented each core with a picture of a hexagon. This does not imply that each core can only have six connections. In some cases, they can have quite a few more.
To be honest, they could have used any sort of polygonal shape to represent this idea. The hexagonal architecture is structured in such a way that it contains its own translators, and also its own adapters that allow it to interface with any of the other components. The idea of a self-contained and multi-faceted core is the true reason behind this unusual name.
Who Invented Hexagonal Architecture?
Hexagonal architecture was invented by a computer scientist named Alistair Cockburn. He has been involved in the computer software industry since the 1990s and has worked for some of the biggest companies. Almost from the very beginning, he has been an advocate for alternative systems of software structuring. In many ways, you might say that hexagonal architecture is the culmination of his life’s work, as it does seem to offer the true alternative for which he has always advocated.
It’s worth noting that Cockburn no longer prefers to call his creation as “hexagonal architecture.” He prefers the term “ports and adapters,” but the former name is much catchier and has remained as the more popular term.
The Benefits Of Hexagonal Architecture
According to Mr. Cockburn, he created hexagonal architecture in order to resolve certain problems that are inherent to the traditional layered architecture. For one, these old-fashioned systems cannot help but create a certain amount of interdependency between layers. Not only does this limit functionality, but it also makes it virtually impossible to design a completely secure computer system. Cockburn’s design removes both of these limitations.
Another problem is that, in many cases, data from one layer can end up corrupting the layer below. As we already explained, each layer in a traditional structure will normally speak a different computing language. When data from one layer leaks into another layer, it usually cannot be read in its new location. Unable to process this data, the computer responds with some kind of a glitch response. Hexagonal architecture solves this problem by keeping everything in its proper place.
In a layered system, there is only one way to solve this issue, and it is…you guessed it: Creating another layer! By creating an anti-corruption layer between all the other layers, you can prevent data leakage that might otherwise compromise the system. However, that means adding a lot of unnecessary complexity.
There are also benefits in terms of testing and repair. Because each component is more strictly isolated, it is much easier to conduct diagnostic tests. This can only translate into faster repair times and easier diagnostics in general.
Since the system is based on a modular principle (i.e., a system made up of many interchangeable cores), it would theoretically be possible to switch out just one core at a time if it becomes problematic. This would be much like swapping out a defective car part and would be much easier than having to reconfigure an entire system. Considering how buggy computers can be, and how frequently viruses can be encountered, this is a serious advantage, indeed.
The main advantage of the hexagonal structure is that it allows for much more efficient edge detection. For some reason, the cores are able to obtain a much better picture of the edges by using this design.
Here, we see an interesting coincidence that might not be a coincidence at all. When we realize that a hexagonal core has an easier time detecting encroachments at its edges, we cannot help but think about all the hexagonal forts that have been created throughout history. Many different civilizations have found the hexagon shape to be exceptionally easy to defend. It might be that this better edge detection is a natural consequence of the shape itself.
Variations Of Hexagonal Architecture
With such a versatile system, it is no surprise that people are already adapting the basic idea of hexagonal architecture in different ways. Like any basic concept, this one is bound to be developed in many different directions, and that is a good thing. Assuming that this type of system lives up to the hype, it really could be the next big thing in software design, and could potentially replace layered design altogether.
For instance, here is a study that was conducted using a variant of the hexagonal architecture system. This one is referred to as HARTS, which stands for “Hexagonal Architecture for Real-Time Systems. As the name implies, it is a variant that is based on the need for a computer system that observes and responds in real-time. In some way, you might call it a “rapid-response” version of this architecture.
They achieve this high degree of speed and responsiveness by using a large number of nodes, each of which is made up of several processors. They are all connected in a wrap of hexagonal mesh. Thus, we might say that this is the only literal example of hexagonal architecture that we can find.
Conclusion
In accordance with the wishes of its creator, it seems that hexagonal architecture has solved many of the problems that are inherent to a traditional layered approach. However, we should not make the mistake of thinking that this new way is infallible, even if it does seem to be a superior alternative. At the very least, this is a fascinating new frontier in the field of software design, and one which will be very interesting to observe in the coming years. If you have enjoyed this article, and if you would like to read more of our work, please feel free to fill out the contact form below.