Reader small image

You're reading from  Designing Microservices Platforms with NATS

Product typeBook
Published inNov 2021
PublisherPackt
ISBN-139781801072212
Edition1st Edition
Concepts
Right arrow
Author (1)
Chanaka Fernando
Chanaka Fernando
author image
Chanaka Fernando

Chanaka Fernando is a solution architect with 12+ years of experience in designing, implementing, and supporting enterprise-scale software solutions for customers across various industries including finance, education, healthcare, and telecommunications. He has contributed to the open source community with his work (design, implementation, and support) as the product lead of the WSO2 ESB, one of the founding members of the "Ballerina: cloud-native programming language" project, and his own work on GitHub. He has spoken at several WSO2 conferences and his articles are published on Medium, DZone, and InfoQ. Chanaka has a bachelor's degree in electronics and telecommunications engineering from the University of Moratuwa.
Read more about Chanaka Fernando

Right arrow

Chapter 8: Observability with NATS in a Microservices Architecture

Observability is a characteristic of a platform that defines how well the internal states of a system can be inferred from the knowledge of its external outputs. A platform without proper observability is hard to recover and troubleshoot when things do not go as expected. In a world of distributed systems, failure is inevitable, and systems need to be designed in such a way that they can withstand failures. It is the responsibility of each microservices team to have proper observability in their implementations and share a common set of tools to monitor the applications.

Given that a microservices architecture encourages building more services, it becomes a challenge to build correlations among messages when communicating across multiple services. With the usage of NATS for interservice communication, it becomes important that the NATS server has proper mechanisms to monitor the message interactions. Since all the...

Technical requirements

In this chapter, we will be configuring the NATS server to enable observability of the interservice communication and improve our sample microservices to include observability features. The following software components need to be installed to try out the examples mentioned in this chapter:

  • The Go programming language
  • The NATS server
  • Prometheus
  • Grafana
  • Loki and Promtail

The source code of the examples used in this chapter can be found at https://github.com/PacktPublishing/Designing-Microservices-Platforms-with-NATS/tree/main/chapter8.

Observability in a microservices context

In the first few chapters of this book, we discussed the advantages of a microservices architecture and how it allows applications to be developed as a set of independent components that work cohesively. However, we have overlooked one thing, which is the complexity it adds to the process of monitoring and recovery from failure. One thing that we want to make clear at the beginning of this chapter is that monitoring is not the same as observability. While observability is a feature of the overall system, monitoring is a process that we execute to capture the details (external outputs). Having said that, both observability and monitoring are interconnected.

In a monolithic application, it is not that difficult to identify the root causes of a failure since there is only one place to look. From that place, we can dig into the details and identify the root cause. In the real world, this may not be as easy as it sounds. But comparatively, it...

Observability features of NATS

NATS provides two main methods to monitor the behavior of the NATS servers. Those are the following:

  • Logging
  • Monitoring

The internal implementation of the NATS server is done with a lot of instrumentation so that the users of the NATS server can monitor the servers in any deployment scenario. Let's discuss these options with a few examples.

Logging

Logging is the most common method of observability supported by the server software. It allows the users to track back the failures and possibly identify the root causes of such failures. There are many advanced log management tools available in the market so that users can monitor the logs in real time and trigger alerts and notifications based on certain log events, so that operations teams can take action on those alerts before the server goes into failure mode. The NATS server supports various logging options that you can enable through the command line or the configuration...

Using NATS observability in a microservices architecture

So far, we have discussed microservice observability and NATS observability as two separate topics. Let's aggregate these topics and produce a common approach to implement observability for a microservices-based platform. The best way to learn a concept is to try with a practical example. Let's build a simple application that has two microservices written in Go. These microservices are called publisher and subscriber. We are going to use the open source observability tools Prometheus, Grafana, and Loki in this example.

The following figure shows the example application that we are going to build:

Figure 8.6 – Microservices observability example with Prometheus, Grafana, and Loki

The preceding figure depicts a simple application, consisting of a publisher microservice and a subscriber microservice interacting with each other using the NATS server. We have set up our monitoring ecosystem...

Summary

In this chapter, we discussed observability in the context of a microservices architecture and defined the distinct types of observability requirements in such a platform. We discussed how monitoring is related to observability and what types of information we can monitor in a microservices environment. Then, we discussed the various observability features available in the NATS platform and how that information can be accessed through log files and REST APIs. Finally, we built a comprehensive microservices-based observability platform with a sample application that uses NATS for interservice communication. We discussed setting up open source monitoring tools such as Prometheus, Grafana, and Loki to set up the observability platform for our sample application.

This chapter concludes our second section of the book, where we discussed the practical usage of NATS with microservices platforms by going through numerous examples and configurations. The next chapter starts our last...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Designing Microservices Platforms with NATS
Published in: Nov 2021Publisher: PacktISBN-13: 9781801072212
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Chanaka Fernando

Chanaka Fernando is a solution architect with 12+ years of experience in designing, implementing, and supporting enterprise-scale software solutions for customers across various industries including finance, education, healthcare, and telecommunications. He has contributed to the open source community with his work (design, implementation, and support) as the product lead of the WSO2 ESB, one of the founding members of the "Ballerina: cloud-native programming language" project, and his own work on GitHub. He has spoken at several WSO2 conferences and his articles are published on Medium, DZone, and InfoQ. Chanaka has a bachelor's degree in electronics and telecommunications engineering from the University of Moratuwa.
Read more about Chanaka Fernando