SOLID & Design Patterns Interview Question #104

What is Hexagonal Architecture?

Architectural Patterns, Application Boundaries & Distributed Design Patterns Senior Advanced

Quick Interview Answer

Hexagonal Architecture, also called Ports and Adapters, separates application logic from external systems through explicit ports. Adapters implement those ports for technologies such as databases, HTTP APIs, messaging systems, or user interfaces.

Detailed Explanation

Hexagonal Architecture, also called Ports and Adapters, separates application logic from external systems through explicit ports. Adapters implement those ports for technologies such as databases, HTTP APIs, messaging systems, or user interfaces.

This makes external technologies replaceable and allows the application core to be tested without requiring the real infrastructure.

Code Example

public interface IOrderStore // Port
{
    Task SaveAsync(Order order);
}

public class EfOrderStore : IOrderStore // Adapter
{
    public Task SaveAsync(Order order)
    {
        // EF Core implementation
        return Task.CompletedTask;
    }
}