With all the various methodologies, architectures and over 2,500 different programming languages, choosing the right components and keeping applications clean and functional in line with the needs of each project can prove a real challenge for companies, as well as for programmers and engineers.
However, hexagonal architecture for software development has been in the spotlight in recent years, thanks to the flexibility it offers when it comes to ensuring a software's quality and scalability, while maintaining independence between the business logic and the system's technical details. Want to find out more about hexagonal architecture and how it works? In this article, we explain the key features.
Hexagonal architecture, also called "ports and adapters”, is a software development methodology created in 2005 by Alistair Cockburn. It is a concept that maintains independence between the various components of a computer program, while ensuring they can easily interconnect via ports and adapters.
The aim is to thus avoid some of the structural errors that tend to arise in object-oriented software engineering. For example, it's common for the various modules to be over-dependent on one another, which increases complexity and reduces flexibility when it comes to making changes or interchanging components.
Hexagonal architecture also favours Clean Code programming by explicitly keeping the user interface, business logic and server separate. This facilitates test automation, maintenance, and bug fixes.
With this architectural approach, software components are represented in the shape of a hexagon. The core of the application is placed in the centre, surrounded by the different modules. Moreover, sufficient space is left between these to represent the connections between the various components.
To understand how hexagonal architecture for software works, it's vital to systematically recognise the components that support this development methodology. In this sense, we can differentiate between domain, ports, adapters and infrastructure.
The domain or core is located in the central layer of the hexagon and contains all of the application's business logic, as well as the main business rules, restrictions, behaviour and data model. The domain must operate independently from all other layers.
Ports serve as an entry point and allow for interaction between the app's core and the adapters. In this sense, they are responsible for transmitting information and operating the adapters. There can be as many ports as required.
Imagine these to be like USB ports, to which you can connect a wide range of devices.
Adapters enable communication between the users and the core, with the ports as intermediaries. They can be replaced without affecting the core, since they will still be able to exchange information thanks to the ports.
Adapters are located in the “infrastructure” layer, on the outside of the hexagon, containing all of the application's input and output elements, and which enables the latter to communicate with external services.
As you can see, hexagonal architecture boasts a variety of mechanisms that facilitate the flexible programming and maintenance of software. However, this approach may not be suited to all projects, making it necessary to assess how well the advantages and limitations fit with the characteristics and needs of the software itself.
Amongst the advantages of hexagonal architecture, the following stand out:
Independence: dividing the software into different layers allows these to be kept isolated and independent. This makes changes and updates easier.
Flexibility: while the program's core remains static, the other components are not entirely essential. This avoids dependency or difficulties in migrating to another system.
Technology integration: thanks to its modular nature, new technologies can easily be integrated.
Unit tests: hexagonal architecture - being at the core of the application and independent of the infrastructure - facilitates the execution of automated tests for business logic.
Scalability: this methodology allows a software to be easily scaled in terms of both capabilities and functionalities.
Performance: a well-structured software improves the quality of the code, increasing functionality and enhancing the performance of applications.
Maintenance: likewise, software with these characteristics is usually easy to understand and maintain.
On the other hand, hexagonal architecture presents certain limitations, such as:
Complexity: hexagonal architecture can be more complex than other software engineering approaches, due to its multiple elements.
Understanding the code: it may require more code than other types of architecture. This can make it more difficult to understand, especially when the code grows significantly or isn't properly documented.
Dispersion: over time, the software's architecture can become too scattered and fragmented, making certain aspects of the program more complex or dependent.
Initial design: this approach requires experience and in-depth knowledge of the business logic and its infrastructure, meaning that the initial design will be more complicated and take more time.
High-cost risk: if hexagonal architecture is not applied properly, it can pose an overly complex and expensive solution, both in terms of time and resources.
Since it first appeared in 2005, many companies have adopted hexagonal architecture to develop their software. One great example of hexagonal architecture is Netflix, the popular streaming platform. In fact, you can read for yourself all the details of how they have used this methodology over at their blog.
When Netflix began to expand, it needed its software to be increasingly independent. So, the platform exploited hexagonal architecture to split it into smaller, more specific services, in order to expand the possibilities of its developers.
Similarly, another of their goals was for their software to be able to exchange data sources without this affecting the business logic. Harnessing this approach, they managed to isolate the central logic and forget about external concerns. What this means is that they can now switch data sources without having a significant impact on their core.
So, thanks to the hexagonal architecture, Netflix has not only improved its performance, but also developed a scalable solution. Meanwhile, the methodology allows its developers to make better decisions based on the data obtained from tests, which are also easier to conduct.
Overall, hexagonal architecture is undoubtedly an approach that allows top quality software to be designed. Hence, any developers or professionals in the sector need to fully grasp this type of methodology if they seek to launch competitive applications on the market and offer the performance that users demand. Updating your knowledge is therefore necessary to tackle new challenges and grow personally and professionally.
With the aim of promoting employability in this professional field, Banco Santander backs three key concepts: lifelong learning, reskilling and upskilling. To this end, it has developed the Santander Open Academy website, a unique and pioneering global programme.
If you would like to keep growing personally and professionally, head over to the Santander Open Academy website, where you'll find 100s of opportunities to train together with internationally renowned institutions. Access training in technology, languages, research, investigation, soft skills, internships and female leadership, which will help you to improve your employability or refocus your career.
Do you want to become a lifelong learner and increase your job opportunities? The Santander Open Academy website has plenty of options to help you achieve your goals. Check out the website and remember: you can sign up for as many courses as you like. Make the most of this opportunity!