<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jorge Augusto Rodriguez</title>
    <description>The latest articles on DEV Community by Jorge Augusto Rodriguez (@jsalio).</description>
    <link>https://dev.to/jsalio</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F973811%2Ff69378e2-32c9-4fdc-b383-0bdd29d3379d.png</url>
      <title>DEV Community: Jorge Augusto Rodriguez</title>
      <link>https://dev.to/jsalio</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jsalio"/>
    <language>en</language>
    <item>
      <title>Hexagonal Architecture: Enabling Horizontal Scalability and Seamless Microservices Transition Without Breaking Your Core</title>
      <dc:creator>Jorge Augusto Rodriguez</dc:creator>
      <pubDate>Sat, 26 Jul 2025 18:49:53 +0000</pubDate>
      <link>https://dev.to/jsalio/hexagonal-architecture-enabling-horizontal-scalability-and-seamless-microservices-transition-52hg</link>
      <guid>https://dev.to/jsalio/hexagonal-architecture-enabling-horizontal-scalability-and-seamless-microservices-transition-52hg</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;🧑‍💻 &lt;strong&gt;Note&lt;/strong&gt;:&lt;br&gt;&lt;br&gt;
This article is aimed at &lt;strong&gt;developers who are just getting started&lt;/strong&gt; and want to learn about &lt;strong&gt;software architecture and microservices&lt;/strong&gt;. I want to share &lt;strong&gt;my personal view&lt;/strong&gt; on how Hexagonal Architecture provides a solid foundation for growth and scalability.  &lt;/p&gt;

&lt;p&gt;I believe developers should get familiar with architectural patterns early—not to overengineer, but to understand &lt;strong&gt;how to build software that can evolve cleanly&lt;/strong&gt; as the project grows.  &lt;/p&gt;

&lt;p&gt;I'm fully open to &lt;strong&gt;suggestions, questions, or constructive criticism&lt;/strong&gt;. This article is based on practical experience and research, but there’s always room for discussion and improvement. Feel free to challenge or complement this point of view.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;One of the biggest challenges in building long-lasting applications is protecting business logic from technological shifts in the surrounding environment—such as databases, user interfaces, APIs, or messaging systems.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hexagonal Architecture&lt;/strong&gt; provides a strong solution to this problem by structuring applications so that the &lt;strong&gt;core logic remains independent&lt;/strong&gt; from infrastructure and input/output mechanisms. This not only improves maintainability but also makes the system &lt;strong&gt;horizontally scalable&lt;/strong&gt; and allows a &lt;strong&gt;natural transition to microservices&lt;/strong&gt;—without having to rewrite the central business logic.&lt;/p&gt;

&lt;p&gt;In this article, we’ll explore how Hexagonal Architecture prepares your application to evolve from a clean monolith to a distributed system, without compromising your domain logic.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Is Hexagonal Architecture?
&lt;/h2&gt;

&lt;p&gt;Hexagonal Architecture, also known as the &lt;strong&gt;“Ports and Adapters”&lt;/strong&gt; pattern, was proposed by &lt;strong&gt;Alistair Cockburn&lt;/strong&gt;. This approach structures the system around a &lt;strong&gt;central, independent core&lt;/strong&gt;, surrounded by &lt;strong&gt;ports&lt;/strong&gt; (interfaces) and &lt;strong&gt;adapters&lt;/strong&gt; (technology-specific implementations).&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Layers:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Core or Domain&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
This is where your pure business logic lives: entities, use cases, rules, and validations. This layer is &lt;strong&gt;technology-agnostic&lt;/strong&gt; and contains no external dependencies.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ports&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
These are interfaces that define how the core communicates with the outside world (e.g., repositories, notifiers, command inputs, etc.).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Adapters&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Adapters implement those ports using specific technologies, such as a relational database, an HTTP controller, or a message broker.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This explicit separation makes the domain &lt;strong&gt;reusable&lt;/strong&gt;, &lt;strong&gt;testable&lt;/strong&gt;, and &lt;strong&gt;highly portable&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Advantages in Horizontal Scalability
&lt;/h2&gt;

&lt;p&gt;Hexagonal Architecture enforces a key principle: &lt;strong&gt;business logic must not depend on infrastructure&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This has major implications for horizontal scalability:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can &lt;strong&gt;replicate multiple instances&lt;/strong&gt; of the core logic without tight coupling.&lt;/li&gt;
&lt;li&gt;You can scale out specific adapters independently (e.g., REST APIs, databases, message brokers).&lt;/li&gt;
&lt;li&gt;You can &lt;strong&gt;swap infrastructure technologies&lt;/strong&gt; without affecting the core.&lt;/li&gt;
&lt;li&gt;You can isolate parts of the system into &lt;strong&gt;standalone services&lt;/strong&gt; if needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This architecture is not only clean and maintainable—it’s &lt;strong&gt;built for growth&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  A Natural Path to Microservices
&lt;/h2&gt;

&lt;p&gt;Migrating from a monolith to microservices can be a nightmare when business logic is scattered and tightly coupled to infrastructure.&lt;/p&gt;

&lt;p&gt;With Hexagonal Architecture, &lt;strong&gt;that pain goes away&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why?
&lt;/h3&gt;

&lt;p&gt;Because the core is already encapsulated and independent.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;

&lt;p&gt;Let’s say you have a monolithic application with a “Payment Management” module. If that module was built using Hexagonal Architecture:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;payment domain logic&lt;/strong&gt; can be moved to a new service without modification.&lt;/li&gt;
&lt;li&gt;You can expose it using new adapters (REST, events, GraphQL, etc.).&lt;/li&gt;
&lt;li&gt;The old system can communicate with the new service via interfaces or events without breaking domain contracts.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Result:
&lt;/h3&gt;

&lt;p&gt;Your core logic remains &lt;strong&gt;intact&lt;/strong&gt;. You only swap adapters. This is true &lt;strong&gt;reusability&lt;/strong&gt; and &lt;strong&gt;evolutionary scalability&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Best Practices for a Scalable Architecture
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Keep your domain pure.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
No frameworks, databases, or external libraries inside your use cases.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Define ports as clear interfaces.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
They should express intent, not technical details.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Keep adapters as thin as possible.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Adapters should transform and delegate—not contain business logic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Avoid circular dependencies.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Use dependency inversion to inject behavior into the domain from the outside.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Physically separate your layers.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Split your repo into &lt;code&gt;core&lt;/code&gt;, &lt;code&gt;application&lt;/code&gt;, &lt;code&gt;infrastructure&lt;/code&gt;, and &lt;code&gt;interfaces&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Using &lt;strong&gt;Hexagonal Architecture&lt;/strong&gt; is not just about clean code or separation of concerns. It’s a &lt;strong&gt;strategic decision&lt;/strong&gt; that allows your application to scale with minimal friction, evolve with new requirements, and transition to microservices gradually and safely.&lt;/p&gt;

&lt;p&gt;By clearly separating the &lt;strong&gt;what&lt;/strong&gt; (business logic) from the &lt;strong&gt;how&lt;/strong&gt; (implementation technologies), you prepare your system for any future challenge—from infrastructure changes to massive user growth.&lt;/p&gt;




&lt;p&gt;In upcoming posts, I will demonstrate it, first as a monolithic system to implement the hexagonal architecture and then convert it into microservices.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://alistair.cockburn.us/hexagonal-architecture/" rel="noopener noreferrer"&gt;Alistair Cockburn – “Hexagonal Architecture” (Original Source)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.oreilly.com/library/view/building-microservices/9781491950340/" rel="noopener noreferrer"&gt;Building Microservices – Sam Newman (Chapter 3: How to Model Services)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.oreilly.com/library/view/clean-architecture-a/9780134494272/" rel="noopener noreferrer"&gt;Clean Architecture – Robert C. Martin (Chapters 13 and 20)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/common-web-application-architectures" rel="noopener noreferrer"&gt;Microsoft Docs – Clean Architecture in .NET&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Basic template for creating an API project with node/typescript/swagger</title>
      <dc:creator>Jorge Augusto Rodriguez</dc:creator>
      <pubDate>Wed, 16 Nov 2022 18:43:22 +0000</pubDate>
      <link>https://dev.to/jsalio/basic-template-for-creating-an-api-project-with-nodetypescriptswagger-1ge7</link>
      <guid>https://dev.to/jsalio/basic-template-for-creating-an-api-project-with-nodetypescriptswagger-1ge7</guid>
      <description>&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;Clone the repository and install the dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/jsalio/ExpressWebApiTemplate
&lt;span class="nb"&gt;cd &lt;/span&gt;ExpressWebApiTemplate
pnpm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;Node.js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.typescriptlang.org/" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nodemon.io/" rel="noopener noreferrer"&gt;Nodemon&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://expressjs.com/" rel="noopener noreferrer"&gt;Express&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://swagger.io/" rel="noopener noreferrer"&gt;Swagger&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tsoa-community.github.io/docs/getting-started.html" rel="noopener noreferrer"&gt;tsoa&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Folder structure
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;├── README.md
├── package.json
├── lib
│   ├── app.ts
│   ├── server.ts
│   ├── app-router.ts &lt;span class="c"&gt;# App router&lt;/span&gt;
│   ├── controllers &lt;span class="c"&gt;# Controllers&lt;/span&gt;
│   │   ├── HomeController.ts
│   ├── models
│   │   ├── Response.ts
├── Public
│   ├── swagger.json &lt;span class="c"&gt;# Swagger file (autogenerated)&lt;/span&gt;
├── nodemon.json
├── tsconfig.json
├── tsoa.json
├── tslint.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How to run
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;For build and run the project&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm run start:dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For update swagger file&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm run swagger
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For run in watch mode&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm run start
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>security</category>
    </item>
  </channel>
</rss>
