Learning Center
July 24, 2024
22 min read

What is a Service Mesh?

Kong

A service mesh is a mechanism for managing communications between the various individual services that make up modern applications in a microservice-based system.

When a service mesh is applied, all inter-service communication is routed through proxies, which can be used to implement networking features such as encryption and load balancing. The service mesh decouples the network logic from the application or business logic of each microservice so that it can be implemented and managed consistently across the whole system.

The dedicated infrastructure layer of the service mesh is something of a complimentary piece of technology to an API gateway. But a service mesh only handles communication between services that make up a system, while an API gateway decouples the underlying system from the API that is exposed to clients (which can be other systems within the organization or external clients).

The difference between API gateway vs service mesh is sometimes characterized as north-south (API gateway) versus east-west (service mesh) communication, but that's not strictly accurate.

While the service mesh pattern was designed to handle network connectivity between microservices, it can also be applied to other architectures (monolithic, mini-services, serverless) wherever there are multiple services communicating across a network.

In this article, we'll explore what a service mesh is, how it works, and how it can efficiently handle challenges like routing or load balancing. We'll also learn about the different components in a service mesh and see benefits and challenges a service mesh imposes and how you can overcome them.

How Does a Service Mesh Work?

Service mesh implementations usually have two main components: the data plane and the control plane.

The data plane is a network proxy replicated alongside each microservice (known as a sidecar), which manages all inbound and outbound network traffic on behalf of the microservice. As part of this, it may perform service discovery, load balancing, security and reliability functions. The service and sidecar should be deployed on the same host and if your deployment is containerized in the same pod.

The Data Plane

The data plane is made up of services running alongside sidecar proxies. The services handle business logic, while proxies sit between them and other services. All traffic, ingress, and egress occur through the proxies, which are responsible for routing (proxying) traffic to other services.

Fig. 1: Service mesh data plane

Many features provided by the service mesh work at the request level, making sidecars Layer 7 proxies. By operating at this layer, service meshes provide capabilities like intelligent load balancing based on observed latency, or provide sensible and consistent timeouts for requests.

Sidecars also provide functionality at the connection level. For example, sidecars can provide functionality like Mutual Transport Layer Security (mTLS), allowing each party in the communication to validate the certificate of the other.

The Control Plane

Proxies need to be configured. This is done through the control plane, which consists of several services that provide administrative functionality over the service mesh and provides an interface to configure the behavior of the data plane and for the proxies to coordinate their actions.

Fig. 2: Service mesh architecture

Operators interact with the service mesh through the control plane by using a CLI or API. For example, operators work through the control plane to define routing rules, create circuit breakers, or enforce access control.

Depending on the implementation, you can use the control plane to export observability data such as metrics, logs, and traces.

Control Plane and Data Plane

Fig. 3: How a service mesh works

To learn more about how a service mesh works, see Understanding a Service Mesh Architecture.

How is Service Mesh different from an API Gateway?

At first glance, the functionality of a service mesh and an API gateway seem to be quite similar. However, they have some key differences that make each of them important in specific use cases. 

Both a service mesh and an API gateway handle a control plane. While the service mesh controls internal service-to-service communication between applications, an API gateway routes external client requests to the appropriate backend service. The traffic management of the service mesh is known as east-west traffic control inside a cluster, while API gateways handle north-south traffic. The API gateway controls regulation of API services like authentication and authorization. In contrast, a service mesh handles functions like load balancing and encryption between services.

Another distinction between an API gateway and a service mesh is the layer at which they operate. A service mesh primarily works and exists at L4, but it can also do select functions at L7 like request-level metrics and tracing. An API Gateway almost exclusively operates at L7, handling HTTP/HTTPS requests into the cluster. Despite where they operate, their placement in a Kubernetes system is distinct. An API gateway acts as a wall on the edge of a system between the Kubernetes service and additional microservices. The service mesh is in its own unique instance as a sidecar proxy, and it is not exposed to external clients. 

Understanding Service Mesh vs Microservices

In a microservice architecture, an application is broken up into multiple loosely coupled services that communicate over a network. Each microservice is responsible for a specific element of business logic. For example, an online shopping system might include individual services to handle stock control, shopping cart management, and payments.

Microservices provide several advantages over a traditional, monolithic design. As each service is developed and deployed independently, teams can embrace the benefits of agile practices and roll out updates more frequently. Individual services can be scaled independently, and if one service fails, it does not take the rest of the system down with it.

Manage Network Communication

Service mesh was introduced as a way of managing the communication between the services in a microservice-based system.

As the individual services are often written in different languages, implementing network logic as part of each service can duplicate effort. Even if the same code is reused by different microservices, there's a risk of inconsistencies as changes must be prioritized and implemented by each team alongside enhancements to the microservices core functionality.

Just as a microservice architecture enables multiple teams to work concurrently on different services and deploy them separately, using a service mesh enables those teams to focus on delivering business logic and not concern themselves with the implementation of networking functionality. With a service mesh, network communication can be simplified into one inclusive client with automated processes, freeing up available human resources. 

Why Do You Need a Service Mesh?

Once upon a time, programs were developed and deployed as a single application. Called monolithic architecture, this traditional approach worked fine for simple applications, but it becomes a burden as applications grow complex and the codebase swells.

That's why modern organizations typically move from monolithic architecture to microservices architectures. By allowing teams to independently work on the application in small parts (called microservices), applications can be modularly developed as a collection of services. But as the number of services grow, you need to ensure connection between services is fast, smooth, and resilient.

Enter service mesh.

Service Mesh: Benefits and Challenges

Distributed systems split applications into distinct services. While this architectural type has many advantages (like faster development time, making changes easier to implement, and ensuring resilience), it also introduces some challenges (like service discovery, efficient routing, and intelligent load balancing). Many of these challenges are cross-cutting, requiring multiple services to implement such functionalities independently and redundantly.

The service mesh layer allows applications to offload those implementations to the platform level. It also provides distinct advantages in the areas of observability, reliability, and security.

Improved Observability and Monitoring

One primary benefit of the service mesh is to enhance observability. A system is considered observable if you can understand its internal state and health based on its external outputs. As the connective tissue between services, a service mesh can provide data about the system's behavior with minimal changes to application code.

Distributed tracing

Distributed tracing is an essential feature provided by service meshes. It helps users to gain visibility into the complex interactions between microservices. When a new request enters the system, the service mesh assigns it a unique trace ID that is then propagated to respective services that can best handle it. Each service also generates span IDs for the parts of the request it processes. 

The service mesh sidecars automatically instrument these requests, capturing timing data and metadata without requiring code changes. This trace data is sent to a centralized tracing system for storage and analysis.

The trace function interface gives developers a window into the data tracing process. Here, users can view the end-to-end flow of requests, see all services involved, and identify any performance bottlenecks or errors. Using a service mesh, distributed tracing can be implemented consistently across all services, ultimately providing the observability needed to troubleshoot and optimize microservice applications.

Real-time metrics and logging

A service mesh provides comprehensive, real-time metrics, giving the user deep visibility into the behavior and health of their microservices. This can include request volume, latency, error rates, resource utilization, and traffic breakdowns. These can be done individually by service, version, or protocol. Detailed access, transaction, and error logs with stack traces are also captured.

These metrics and logs are exposed in standard formats, allowing easy integration with monitoring and logging systems like Prometheus, Grafana, Elasticsearch, or Splunk. By automatically instrumenting services and centralizing telemetry, a service mesh greatly simplifies observability without requiring developers to instrument each service individually.

This real-time observability enables proactive issue identification, incident investigation, performance optimization, and data-driven decision making for operating microservices applications at scale. The granular insights provided by the service mesh are critical for understanding and managing complex distributed systems.

Traffic monitoring and analysis

Service meshes offer detailed traffic metrics and insights, enabling operators to understand service interactions within a microservices architecture. These metrics include bandwidth usage, request volume, traffic distribution by protocol, and service dependencies.

Analyzing these metrics empowers operators to identify performance bottlenecks, optimize resource allocation, ensure fair traffic distribution, and detect anomalies. The service mesh also provides visibility into communication patterns, aiding in architecture design and evolution.

Integrating with service mesh dashboards and external traffic analysis platforms allows for interactive data exploration and AI/ML-driven recommendations, facilitating traffic optimization at scale.

Increased Resilience and Reliability

A service mesh also helps improve system reliability. By offloading fault tolerance concerns to a service mesh, services can focus on differentiating business logic. The service mesh can handle retrying requests transparently, without other services even being aware if dependencies are experiencing issues.

Automatic Retries & Timeouts

Instead of making users manually resolve request issues, a service mesh can automatically handle retries and timeouts for failed requests between services. When a request cannot process due to a network issue or unavailable service, the service mesh can intelligently retry the request a configurable number of times before returning an error to the client. Giving this function to a service mesh takes one more thing off the plate of the developers, and can keep the request process going instead of having recurring downtimes until a user can respond to it. 

Additionally, a service mesh allows operators to set specified timeout thresholds for requests. If a service takes too long to respond, the mesh can automatically cancel the request and return an error to save time and allocation. By canceling the request loop at an ideal time, the service mesh ultimately prevents cascading failures and helps maintain the overall responsiveness of the system even if some services are experiencing issues.

Fault Tolerance & Failure Injection

With a service mesh, users can stress test their applications to see when they fail and how that cascades throughout their services. This is known as failure injection, and it is a key concept of chaos engineering. Here, developers intentionally introduce faults to create failures in their systems, and it ultimately identifies weaknesses within their system. By doing this, users can aim to strengthen their services and improve resilience by introducing instances of fault tolerance. 

A service mesh provides detailed metrics and logs for its applications through purposeful failure injections. This way developers can preemptively anticipate fault points and proactively create tolerable limits. By leveraging these capabilities, microservices architectures can achieve higher levels of resilience and reliability, ensuring graceful recovery from failures.

Health Checks & Self Healing

With a service mesh, users can continuously monitor the health of services using probes to validate availability and readiness. When a service fails one of the predetermined health checks, the mesh automatically removes it from the load balancing pool. These measures aim to prevent traffic from being routed to unhealthy instances and lessening the available resources for necessary functions. By using these health failsafes, the mesh ensures failures won’t propagate and continue to maintain the overall reliability of the system.

Ideally, these previously failing services will heal themselves over time until they once again pass the health checks. Then, the service mesh will automatically reintroduce it to the load balancing pool. This is known as the self-healing feature of the service mesh, as it does not require any manual intervention from developers. This dynamic process improves the system's overall resilience and ability to recover from failures.

By using these health checks and self-healing mechanisms, a service mesh ensures all microservice architectures maintain high available capacity and automatically adapt to changing conditions. This ultimately minimizes downtime and enhances the overall reliability of the application.

Enhanced Security Features

The service mesh simplifies the adoption of secure communication practices. It helps platforms establish a zero trust security model, which assumes that no entity, even those within the network, is blindly trusted. 

Mutual TLS (mTLS) Authentication

Mutual TLS (mTLS) authentication, an extension of the Transport Layer Security (TLS) protocol, helps verify the identity of clients and services. These certificates in mTLS verifications are issued by a trusted Certificate Authority (CA) within the service mesh environment. It achieves this by revealing the respective certificates of each client and service and having them confirm their true identities. The result is a trust relationship between one another where they make sure only verified entities can communicate with them. Not only does this foster confidentiality for the data being transmitted, it also strengthens the integrity of the communication channel. Additionally, mTLS establishes non-repudiation, meaning that neither the client nor server can deny participation in the communication process.

By enforcing mTLS, the service mesh creates a secure network where only authenticated services can interact. The secure network mitigates risks, such as malicious API requests or on-path attacks, and prevents unauthorized access. This function could be done manually, but a service mesh automates the management of these certificates, thus simplifying the implementation of mTLS for developers.

Encryption of Inter-Service Communication

A service mesh also provides built-in encryption to further secure inter-service communications using protocols such as TLS. The control plane of the service mesh automatically manages the generation and distribution of all TLS certificates, ensuring their integrity as they travel between services. This function works in tandem with mTLS; once the client and service have both been verified, then the encrypted messages can be securely sent between them.

Having encryption of inter-service communications as a built-in feature simplifies the implementation process for developers and makes it easy to follow security best practices. It allows for an easy streamlining of secure data transfer and creates more resilient applications. Having a service mesh that handles encryption of inter-service communication is a vital asset for mitigating risks and protecting sensitive data. 

Access Control and Authorization

A service mesh offers multiple types of access control within your applications. It comes built-in with functions, as well as capability to seamlessly integrate beneficial external forms of access control. Fine-grained access control is one of the standard features that a service mesh implements. In this form of access control, organizations can define precise rules and permissions for services, and it can even go as far as to control at the API level. A service mesh will also support role-based access control (RBAC) for authorization, which gives permissions based on specifically assigned roles. 

Using some external services can help simplify access control and authorization management between all your services. A service mesh can easily facilitate the integration of systems like OAuth2 or OpenID Connect, which will centralize the management of access control and authorization. If an organization has existing identity and access management (IAM) infrastructure they would want to incorporate into their new service mesh, then these external services would simplify that process.

Additionally, a service mesh supports dynamic policy enforcement on all access control functionality between applications. Organizations can use this feature to have real-time updating of access control policies, ultimately promoting agility and up-to-date best practices. Having a fast-responding dynamic policy enforcement means that security incidents are instantly addressed and authorization is always properly given to the ideal services.  

Different service mesh implementations have different feature sets. Some promote simplicity, while others focus on capabilities. For example, some implementations focus on having light sidecar proxies, while others offer chaos engineering capabilities. It's important to take these characteristics into consideration when choosing a service mesh implementation.

Traffic Management Capabilities

A service mesh comes equipped with traffic management capabilities that can help an organization to control and optimize the flow of traffic within their microservice architectures. These capabilities encompass load balancing, traffic splitting, canary releases, blue-green deployments, circuit breaking, and fault injection. By utilizing these features of a service mesh, organizations can ensure reliable service delivery, optimize application performance, and minimize the impact of potential failures. 

Load Balancing and Traffic Splitting

Load balancing is a vital tool for traffic regulation within a microservice environment. As one feature of a service mesh, load balancing uses algorithms that evenly distributes traffic across available instances of a service. This ensures optimal resource utilization and prevents any single instance from being overwhelmed. Additionally, a service mesh supports traffic splitting, which allows organizations to direct specific traffic to a designated service. This functionality gives organizations the ability to conduct A/B testing without impacting the entire user base. 

Canary Releases and Blue-Green Deployments

Using a service mesh, developers have access to multiple forms of delivery techniques and regulation. The most significant of these are canary releases and blue-green deployments. With a canary release, organizations can release new versions of a service to a select group. By doing this, organizations can monitor their behavior and performance of that smaller focus group and make sure that the new version is fully functional before choosing to roll it out to their larger audience. Alternatively, service mesh users can also opt for blue-green deployments, which involves running two identical production environments with heavy traffic being swapped between them during update periods. There are specific use cases for both of these, and the use of a service mesh simplifies the execution of these deployment strategies while reducing the risks associated with them. 

Circuit Breaking and Fault Injection

Circuit breaking is a resilience pattern that helps prevent cascading failures in a microservices system. Service meshes implement circuit breakers to monitor the health of services and automatically cut off requests to failing or unresponsive instances. This prevents a single failure from propagating throughout the system and allows the failing service to recover gracefully. Furthermore, service meshes support fault injection, a testing technique that introduces controlled failures into the system to assess its resilience and identify weaknesses. By simulating failures, organizations can proactively identify and address potential issues before they impact production environments.

The traffic management capabilities offered by service meshes empower organizations to build resilient and scalable microservices architectures. By leveraging load balancing, traffic splitting, canary releases, blue-green deployments, circuit breaking, and fault injection, organizations can ensure optimal performance, reliability, and agility in their applications. These features simplify the implementation of complex traffic management strategies, allowing developers to focus on delivering business value while the service mesh handles the underlying infrastructure concerns.

API & Microservices Security Redefined: beyond gateways & service mesh boundaries

Service Mesh Challenges

Despite all its benefits, the service mesh also comes with some caveats, which can present some challenges. When adopting a service mesh, you should consider the following.

  • Added complexity: Adding a service mesh to a platform introduces another layer to your overall architecture. Regardless of which service mesh implementation you select, this will incur extra management costs. An extra set of services (such as the control plane) must be managed, and sidecar proxies must be configured and injected.

  • Resource consumption: A sidecar proxy accompanies each application replica. These proxies consume resources (such as CPU and memory), increasing linearly with the number of application replicas.

  • Security loopholes: Bugs or configuration mistakes at the service mesh layer can create security threats. For example, a wrong configuration can expose an internal service to the outside world.

  • Debugging: An extra layer can make it harder to pinpoint issues. Traffic flowing through proxies adds extra network hops, which can obscure the root cause of some problems.

The threshold at which service mesh advantages exceed its disadvantages varies from organization to organization. When you're considering the adoption of a service mesh, it is crucial to know how they excel, what they can offer, and also when they can be counterproductive.

How to Implement Service Mesh

Implementing a service mesh involves a series of strategic steps to ensure a smooth and seamless integration with your existing microservices architecture. While there are different types of service meshes to choose from, there is one clear-cut process for how to choose one to best fit your needs. 

1. Assess Current Microservices Architecture

The process of implementing a service mesh begins even before looking into the different types of them out there. To best understand what service mesh you need and can handle, you should conduct a comprehensive assessment of your available microservice architectures. You should assess aspects like potential pain points, scalability allowance, and resilience requirements. Determining these factors will establish a baseline where you can decide what type of service mesh will best fit your individual needs as well as where improvements from a service mesh can be made. Before looking through your options to find a service mesh, start by making a checklist of goals that you want satisfied by a service mesh. This is also a great way to compare the pre and post service mesh metrics later on to understand just how impactful it has been.  

2. Choose The Right Service Mesh Solution

Once you start looking at what service mesh options there are, you will understand that there is no shortage of choices to pick from. While there are many different versions of service meshes that may seem like they satisfy the same use cases, they all have specific nuances that might benefit or work against your goals. Look into the specifics like the set of features, performance characteristics, and integration capabilities. Also, it might be beneficial to look into customer testimonials and how a specific service mesh solves their unique issues. By looking into these specific issues, you should be able to assess how easy a service mesh is to use, the capability it has to fit your existing infrastructure, and how much community support there is. After absorbing all this information and comparing it to the set of goals you made before starting the service mesh search, you should be able to narrow down your search to a few options. From here, you can narrow your research to fine details, engage with the community, and run proof-of-concept trials to make an optimally informed decision. 

3. Strategize Gradual Adoption and Migration Plan

Now that you have made a decision, the integration process is ready to start. This is not a one-time event but rather a gradual process of careful planning and execution. This step begins by carefully laying out a phased adoption strategy and migration plan to minimize disruption during the integration process. Choose a small subsection of your microservices that could serve as a pilot for the procedure. With this small subset of trial runs, you can see what type of issues arise. Using this as an initial test, you can predict what type of conflicts arise with the full integration process and mitigate them as soon as they come up. Then, gradually expand section by section and make adjustments as you see fit until the service mesh has been fully implemented. 

4. Monitor and Troubleshoot Service Mesh Issues

Once the service mesh is deployed, continuous monitoring and troubleshooting become essential to maintain its health and performance. Leveraging the observability features provided by the service mesh, such as distributed tracing, metrics, and logging, enables you to gain insights into the behavior and performance of your services. Establishing alerting and incident response processes helps you proactively identify and resolve any issues that may arise. Regular health checks, capacity planning, and performance tuning ensure that your service mesh continues to operate optimally as your application scales and evolves.

Once the service mesh is fully integrated, there is still more work to be done with the implementation process. You must continue to monitor the service mesh as it will likely have some issues at the start. The monitoring and troubleshooting of the service mesh now becomes a crucial part of the continuous process. Keeping close tabs on the service mesh ensures that it is always functioning properly and achieving optimal performance. You can also establish alerts and notifications to inform developers whenever an issue with the service mesh arises. Aside from this. Regular health checks, capacity planning, and performance tuning will be the ideal standard to make sure you are getting the most out of your service mesh as your applications continue to scale and evolve. 

To learn more about how to set up your own service mesh, see Implementing a Service Mesh.

Get Started with Kong Mesh

In this article, we've considered how distributed systems introduce multiple challenges that applications need to address. However, addressing these challenges at the individual service level can be complex, time-consuming, error-prone, and redundant.

A service mesh provides common solutions to these challenges, and these solutions are developed and maintained at the platform level. The service mesh also benefits applications by contributing to improved observability, reliability, and security.

Kong Mesh is an enterprise service mesh from Kong which is based on Kuma and built on top of Envoy. It's easy to set up and scale, and it supports various environments. It addresses the issues described in this article and allows applications to focus on differentiating business features.

Schedule a personalized demo to see how Kong Mesh could benefit your organization.

Conclusion
  • Recap of service mesh benefits and key takeaways

  • Importance of service mesh in modern application architecture

  • Recommendations for getting started with service mesh

By now, you should understand how significant a service mesh is when it comes to regulating and optimizing your microservice architectures. Providing a dedicated infrastructure layer is one way a service mesh handles cross-cutting concerns such as networking, security, and observability. In doing this, a service mesh allows developers to focus on delivering additional business value. Whether you're implementing a Day 0 service mesh in a new microservices environment or integrating it within an already established microservice architecture, the benefits remain substantial, though the implementation approach may differ. For these reasons, it makes sense why the use of a service mesh has become such a vital part of microservice management. 

Throughout this article, we have explored the many benefits of a service mesh including enhanced observability, improved system reliability, and thorough security features. Additionally, we examined the traffic management capabilities of a service mesh and how they enable organizations to optimize the flow of traffic and ensure reliable service delivery.

While a service mesh may offer numerous advantages, it is essential to consider the challenges it may introduce prior to implementing one. These consist of added complexity, and resource consumption. Organizations must carefully evaluate their specific needs before adopting a service mesh and follow a strategic approach to implementation, including assessment, solution selection, gradual adoption, and continuous monitoring. It should be said that this list of possible issues should not deter you from starting your journey, but it should give you a more informed starting position to make the most out of your service mesh choice.

Kong Mesh, an enterprise-grade service mesh built on top of Envoy, is one solution that addresses those challenges we discussed, and it provides a comprehensive solution for managing microservices communication. As the adoption of microservices continues to grow, service meshes will play an increasingly crucial role in enabling organizations to build and operate complex distributed systems effectively. Now that you are well informed on all that a service mesh has to offer, you can help make the best decision for your organization. 

Service Mesh FAQs

Q: What is a service mesh?
A: A service mesh is a dedicated infrastructure layer for managing communication between services in a microservice-based system. It handles inter-service communication through proxies, implementing features like encryption, load balancing, and observability.

Q: How does a service mesh work?
A: A service mesh typically consists of two main components: the data plane and the control plane. The data plane is made up of proxies (sidecars) deployed alongside each service, handling network traffic. The control plane manages and configures these proxies, providing administrative functionality and an interface for operators.

Q: What are the benefits of using a service mesh?
A: The key benefits of using a service mesh include improved observability and monitoring, increased resilience and reliability, enhanced security features, and advanced traffic management capabilities. It also allows developers to focus on business logic rather than networking concerns.

Q: How is a service mesh different from an API gateway?
A: While both handle network communication, a service mesh focuses on internal service-to-service communication (east-west traffic) within a cluster, whereas an API gateway handles external client requests to backend services (north-south traffic). API gateways operate primarily at Layer 7, while service meshes can work at both Layer 4 and Layer 7.

Q: What security features does a service mesh provide?
A: Service meshes offer several security features, including mutual TLS (mTLS) authentication, encryption of inter-service communication, and access control and authorization. These features help establish a zero-trust security model and protect against various types of attacks.

Q: What are the challenges of implementing a service mesh?
A: Some challenges of implementing a service mesh include added complexity to the overall architecture, increased resource consumption due to sidecar proxies, potential security loopholes if misconfigured, and more complex debugging processes due to the additional layer.

Q: How does a service mesh improve observability?
A: Service meshes improve observability by providing distributed tracing, real-time metrics and logging, and traffic monitoring and analysis. These features help developers understand the behavior and health of their microservices system without requiring changes to application code.

Q: What traffic management capabilities does a service mesh offer?
A: Service meshes offer various traffic management capabilities, including load balancing, traffic splitting, canary releases, blue-green deployments, circuit breaking, and fault injection. These features help optimize application performance and minimize the impact of potential failures.

Q: How do you implement a service mesh?
A: Implementing a service mesh involves several steps: 1) Assess your current microservices architecture, 2) Choose the right service mesh solution, 3) Strategize gradual adoption and migration plan, and 4) Monitor and troubleshoot service mesh issues. It's important to start with a small subset of services and gradually expand.

Q: What is Kong Mesh?
A: Kong Mesh is an enterprise service mesh solution from Kong, based on Kuma and built on top of Envoy. It's designed to be easy to set up and scale, supporting various environments and addressing common challenges in microservices communication.