Layer Architecture vs. Hexagonal Architecture. Which one to choose?

Layered architecture is a common architectural pattern for organising application components into distinct technical layers – presentation, application, business, persistence, etc

The separation of concerns between components is the most powerful feature of layered architecture.

The problem with layered architecture is that because the application architecture is ๐˜ด๐˜ฆ๐˜จ๐˜ณ๐˜ฆ๐˜จ๐˜ข๐˜ต๐˜ฆ๐˜ฅ ๐˜ท๐˜ช๐˜ข ๐˜ต๐˜ฆ๐˜ค๐˜ฉ๐˜ฏ๐˜ช๐˜ค๐˜ข๐˜ญ ๐˜ญ๐˜ข๐˜บ๐˜ฆ๐˜ณ๐˜ด, there is no clear concept of the domain dimension.

To change a certain feature developers generally need to change code in multiple layers as the functionality is spread among different layers.

A better alternative to layered architecture is ๐—ต๐—ฒ๐˜…๐—ฎ๐—ด๐—ผ๐—ป๐—ฎ๐—น ๐—ฎ๐—ฟ๐—ฐ๐—ต๐—ถ๐˜๐—ฒ๐—ฐ๐˜๐˜‚๐—ฟ๐—ฒ, also called ๐—ฝ๐—ผ๐—ฟ๐˜๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—ฎ๐—ฑ๐—ฎ๐—ฝ๐˜๐—ฒ๐—ฟ๐˜€ ๐—ฎ๐—ฟ๐—ฐ๐—ต๐—ถ๐˜๐—ฒ๐—ฐ๐˜๐˜‚๐—ฟ๐—ฒ. With hexagonal architecture the application architecture is ๐˜ด๐˜ฆ๐˜จ๐˜ณ๐˜ฆ๐˜จ๐˜ข๐˜ต๐˜ฆ๐˜ฅ ๐˜ท๐˜ช๐˜ข ๐˜ฃ๐˜ถ๐˜ด๐˜ช๐˜ฏ๐˜ฆ๐˜ด๐˜ด ๐˜ฅ๐˜ฐ๐˜ฎ๐˜ข๐˜ช๐˜ฏ.

The hexagonal architecture divides a system into several loosely-coupled interchangeable components, such as the application core, the database, the UI, test and interfaces with other systems.

๐—ง๐—ต๐—ฒ ๐—บ๐—ฎ๐—ถ๐—ป ๐—ฝ๐—ฟ๐—ถ๐—ป๐—ฐ๐—ถ๐—ฝ๐—น๐—ฒ ๐—ผ๐—ณ ๐—ต๐—ฒ๐˜…๐—ฎ๐—ด๐—ผ๐—ป๐—ฎ๐—น ๐—ผ๐—ฟ ๐—ฝ๐—ผ๐—ฟ๐˜๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—ฎ๐—ฑ๐—ฎ๐—ฝ๐˜๐—ฒ๐—ฟ๐˜€ ๐—ฎ๐—ฟ๐—ฐ๐—ต๐—ถ๐˜๐—ฒ๐—ฐ๐˜๐˜‚๐—ฟ๐—ฎ๐—น ๐—ฝ๐—ฎ๐˜๐˜๐—ฒ๐—ฟ๐—ป ๐—ถ๐˜€ ๐˜๐—ต๐—ฎ๐˜ ๐˜†๐—ผ๐˜‚๐—ฟ ๐—ฏ๐˜‚๐˜€๐—ถ๐—ป๐—ฒ๐˜€๐˜€ ๐—น๐—ผ๐—ด๐—ถ๐—ฐ – ๐˜๐—ต๐—ฒ ๐—ต๐—ฒ๐˜…๐—ฎ๐—ด๐—ผ๐—ป – ๐—ถ๐˜€ ๐—ฝ๐—ฟ๐—ผ๐˜๐—ฒ๐—ฐ๐˜๐—ฒ๐—ฑ ๐—ฎ๐—ป๐—ฑ ๐—ฐ๐—ฎ๐—ป ๐—ผ๐—ป๐—น๐˜† ๐—ฐ๐—ผ๐—บ๐—บ๐˜‚๐—ป๐—ถ๐—ฐ๐—ฎ๐˜๐—ฒ ๐˜„๐—ถ๐˜๐—ต ๐˜๐—ต๐—ฒ ๐—ผ๐˜‚๐˜๐˜€๐—ถ๐—ฑ๐—ฒ ๐˜„๐—ผ๐—ฟ๐—น๐—ฑ ๐˜ƒ๐—ถ๐—ฎ ๐—ถ๐—ป๐˜๐—ฒ๐—ฟ๐—ณ๐—ฎ๐—ฐ๐—ฒ๐˜€ – ๐˜๐—ต๐—ฒ ๐—ฝ๐—ผ๐—ฟ๐˜๐˜€ – ๐˜๐—ต๐—ฎ๐˜ ๐—ฎ๐—ฟ๐—ฒ ๐˜๐—ต๐—ฒ๐—ป ๐—ถ๐—บ๐—ฝ๐—น๐—ฒ๐—บ๐—ฒ๐—ป๐˜๐—ฒ๐—ฑ ๐—ถ๐—ป ๐˜†๐—ผ๐˜‚๐—ฟ ๐˜๐—ฒ๐—ฐ๐—ต๐—ป๐—ผ๐—น๐—ผ๐—ด๐˜† ๐—ผ๐—ณ ๐—ฐ๐—ต๐—ผ๐—ถ๐—ฐ๐—ฒ, ๐˜๐—ต๐—ฒ ๐—ฎ๐—ฑ๐—ฎ๐—ฝ๐˜๐—ฒ๐—ฟ๐˜€.