Layered Microservices Architecture

The conceptualization of microservices architecture represents a pivotal shift in how modern software systems are designed, moving away from the rigid structures of monolithic systems and traditional service-oriented architectures. In the current landscape of software engineering, microservices are rapidly gaining traction as a viable alternative to these legacy frameworks. This shift is evidenced by industry data, such as a survey conducted by IBM, which revealed that approximately 25% of 209 respondents indicated that their company is very likely to develop applications using microservices within the next two years. Despite this momentum, the implementation of microservices is often shrouded in misunderstanding, as the pattern is still in its early stages of widespread industry adoption. To remedy this ambiguity and simplify the implementation of such complex systems, the industry has turned toward the paradigm of layered architecture.

Layering, as a software engineering paradigm, is the process of dividing functionality into different components that interact in a sequential and hierarchical manner. When applied to microservices, this creates a structured ecosystem where complexity is managed through abstraction. A microservices architecture can be effectively split into four distinct layers. While these layers may appear separated in a theoretical model, in practical application, some elements of the architecture will overlap or touch every single layer. This hierarchical organization allows engineering organizations to manage the fierce competition for resources. In any ecosystem, whether natural or technical, resources are finite. Engineering organizations face constraints in terms of human capital (teams and developers) and infrastructure resources (physical computers, cloud hardware, and database storage). Because these resources are expensive, the layered approach provides a mechanism to compartmentalize functionality.

By utilizing a layered microservices architecture, an organization can focus on specific sections of their system independently. This allows a business to invest heavily in the components that are most critical at a given moment while simultaneously diversifying their investment in the creation of a cutting-edge application. This approach is particularly beneficial for different levels of business, including startups, small-to-medium businesses (SMBs), and large enterprises, as it leads to a sizeable increase in both overall growth and operational efficiency over the long term.

The Hardware Layer

The hardware layer serves as the foundation of the entire microservice ecosystem. It is situated at the very bottom of the architectural stack and consists of the actual physical computers that execute every instruction processed by the layers above it. The physical nature of this layer is the ultimate point of execution for all software logic.

The implementation of the hardware layer can vary depending on the organizational infrastructure. These computers can be owned and operated within a company's own private datacenters, or they can consist of virtual machines operating on the infrastructure of major cloud providers. Specific examples of these cloud-based hardware solutions include:

  • Amazon Web Services (AWS) EC2
  • Google Cloud Platform (GCP)
  • Microsoft Azure

Beyond the compute power, this layer is also where databases reside. These databases may be dedicated to a specific service or shared across multiple services. The placement of databases at the hardware layer emphasizes that data persistence is a fundamental requirement that supports all higher-level abstractions.

The hardware layer also encompasses the operating system. In the context of microservice architecture, Linux variants are the most common choices, with Debian and Ubuntu being prime examples. The operating system provides the necessary environment for resource isolation and abstraction solutions to function. Specifically, tools such as Docker and Mesos run on top of these operating systems and physical hardware, providing the virtualization required to run multiple isolated services on a single machine.

Furthermore, this layer includes host-level monitoring and logging. In this context, the term host refers to the specific machine or virtual machine. Host-level monitoring focuses on the health and performance of the hardware and the operating system, ensuring that the physical and virtual infrastructure is stable enough to support the layers above it.

The Application Platform Layer

The application platform layer is designed to be used system-wide, providing centralized tools and services that support the development and operation of all microservices. The primary purpose of this layer is to create a solid application platform that abstracts the complexities of infrastructure, allowing microservice development teams to focus exclusively on the microservices they are building rather than worrying about the underlying plumbing of the system.

A key component of the application platform layer is the provision of self-service internal development tools. These tools are tailored specifically to the needs of the company, reducing the friction associated with deploying and managing services. This layer also defines and manages the structured development process. This process includes several critical technical components:

  • Version control systems to manage code history and collaboration.
  • Collaboration tools, with Github serving as a primary example.
  • Reliable development environments that ensure consistency across different developer machines.
  • Automated testing frameworks.
  • Build, package, and release tooling.

One of the most critical elements of the application platform layer is the deployment pipeline. This pipeline governs the movement of new code from the development environment to the production servers. By automating this process, the organization reduces the risk of manual error and increases the velocity of feature delivery.

Additionally, the application platform layer handles microservice-level logging and monitoring. This is a crucial distinction from the host-level monitoring found in the hardware layer. While host-level monitoring looks at the machine, microservice-level monitoring looks at the services themselves. This function is placed in the application platform layer because logging and monitoring in a microservices architecture must be centralized and consistent. If each microservice implemented its own unique monitoring logic, the system would become fragmented, making it nearly impossible to diagnose cross-service issues. Centralization ensures that regardless of the different microservices in play, the observability data is uniform.

The Microservice Layer

The microservice layer sits at the very top of the microservice ecosystem. This layer contains all the individual microservices as well as any additional information associated with them. The defining characteristic of the microservice layer is its independence; it is nearly fully independent of the layers beneath it. For the vast majority of microservice development teams, this is the only layer with which they directly interact. All the complexities of the operating system, hardware, and platform tooling are abstracted away, allowing developers to focus on business logic.

However, the implementation of this layer is often influenced by the organizational structure of the company, a phenomenon described by Conway’s Law. Conway’s Law suggests that organizations create systems that represent the organization's own communication structure. In large corporations, this often manifests as teams of directors and vice presidents who believe they own a specific business skill. This organizational behavior can have two opposite effects:

  • Positive Effect: It can ensure the reliability of numerous clients who rely on specific services, as the team takes deep ownership of that domain.
  • Negative Effect: It can lead to a situation where leaders simply want to maintain their internal weight and relevance within the company.

When this organizational structure is mapped onto the microservice layer, teams may begin to regard the business capabilities of other teams as black boxes. They create abstractions around these capabilities, and what eventually emerges is a layered architecture composed of groups of microservices that represent the business skills of a single team. While this seems organized, it can actually stifle innovation. Because consuming teams are unaware of the true potential hidden beneath these black-box abstractions, they are forced to innovate in isolation. Over time, a noticeable distinction emerges between these groups, and it becomes necessary to build a gateway between them to ensure continued independence and effective communication.

Architectural Comparisons and Logic

To fully understand the microservices layered architecture, it is necessary to contrast it with other architectural patterns. There is often confusion between how an application is distributed and how its internal components are designed.

A monolithic architecture and a microservices architecture primarily describe how an application is distributed. In a monolith, the application is a single unit. In microservices, the application is split into multiple independent services. In contrast, a layered architecture refers more generally to how the internal components of a system are designed, whether that system is a monolithic app or a single microservice.

Therefore, the presence of a monolith does not automatically imply a poor design. A monolith can be a properly written monolith if it utilizes a layered design to ensure a separation of duties. Conversely, implementing a microservices architecture does not guarantee that the codebase within those services is perfectly layered. The "monolithic" example often seen in poor code is not an example of the architecture itself, but rather an example of code that lacks a separation of duties.

For those evaluating different paths, it is helpful to compare Single Layer, Layered (N-Tier), Modular Monolith, and Microservices architectures.

Architecture Type Description Primary Benefit Best Use Case
Single Layer Combines all logic into one layer, interacting directly with the database and UI. Low Complexity Prototyping, small internal tools
Layered (N-Tier) Divides functionality into components that interact sequentially. Separation of Concerns Standard business applications
Modular Monolith A single deployment unit divided into independent modules. Easier Deployment than Microservices Medium-sized apps with clear domains
Microservices Distributed services operating independently and communicating over a network. High Scalability Large, complex systems with many teams

Single Layer Architecture is the simplest form of application design. It lacks distinct application or domain layers, combining all logic into a single area that handles everything from the user interface to database interaction. This results in low complexity and fast development, making it ideal for quick prototypes, proof-of-concept apps, or short-lived projects where maintainability is not a critical requirement. An example of this would be a small e-commerce website for a local shop where the focus is on rapid deployment rather than long-term scalability.

Analysis of Structural Implementation

The transition from a monolithic structure to a microservices layered architecture is a complex endeavor that requires a shift in both technical approach and organizational mindset. The efficacy of this architecture lies in its ability to provide a structured hierarchy that manages the intersection of hardware, platform, and business logic.

The hardware layer must be viewed as the physical constraint of the system. Whether using AWS EC2, GCP, or Azure, the hardware layer provides the raw compute and storage. The use of Linux variants like Ubuntu or Debian ensures a stable foundation for Docker and Mesos, which in turn allow for the resource isolation that makes microservices possible. Without this foundation, the higher layers would lack the necessary stability and isolation to operate independently.

The application platform layer acts as the bridge between the raw hardware and the business logic. By centralizing logging, monitoring, and deployment pipelines, the organization eliminates the redundancy that would occur if every microservice team had to build their own infrastructure. The use of tools like Github for collaboration and version control ensures that the development process is standardized. The primary value here is the creation of a self-service environment, which removes the bottleneck of infrastructure requests and allows for a higher velocity of development.

The microservice layer is where the business value is generated. However, as noted, the risk of this layer is the creation of "black boxes" due to organizational silos. When teams only interact with other services through limited abstractions, the potential for cross-functional innovation is diminished. The introduction of gateways between these grouped microservices is a critical architectural decision to maintain independence while allowing for controlled communication.

The overarching benefit of this four-layer approach is the ability to compartmentalize. By separating the hardware, the platform, and the microservices, an organization can scale each part of the system independently. For example, if the hardware layer is becoming a bottleneck, the organization can migrate from on-premise servers to a cloud provider without needing to rewrite the microservice layer. Similarly, if the deployment process is too slow, the application platform layer can be upgraded with new automation tooling without interrupting the developers working on the microservices.

Ultimately, the layered microservices architecture is an evolutionary step in software design. It acknowledges that as systems grow in complexity, the need for abstraction and hierarchy becomes paramount. By applying this structured approach, companies can move away from the risks of the monolith while avoiding the chaos of an unstructured microservices implementation.

Sources

  1. SayOne Tech
  2. Dev.to
  3. DecisionTree Tech

Related Posts