Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Designing Microservices Platforms with NATS

You're reading from  Designing Microservices Platforms with NATS

Product type Book
Published in Nov 2021
Publisher Packt
ISBN-13 9781801072212
Pages 356 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Chanaka Fernando Chanaka Fernando
Profile icon Chanaka Fernando

Table of Contents (15) Chapters

Preface 1. Section 1: The Basics of Microservices Architecture and NATS
2. Chapter 1: Introduction to the Microservice Architecture 3. Chapter 2: Why Is Messaging Important in the Microservice Architecture? 4. Chapter 3: What Is NATS Messaging? 5. Section 2: Building Microservices with NATS
6. Chapter 4: How to Use NATS in a Microservice Architecture 7. Chapter 5: Designing a Microservice Architecture with NATS 8. Chapter 6: A Practical Example of Microservices with NATS 9. Chapter 7: Securing a Microservices Architecture with NATS 10. Chapter 8: Observability with NATS in a Microservices Architecture 11. Section 3: Best Practices and Future Developments
12. Chapter 9: How Microservices and NATS Coexist with Integration Platforms 13. Chapter 10: Future of the Microservice Architecture and NATS 14. Other Books You May Enjoy

Chapter 4: How to Use NATS in a Microservice Architecture

In the first part of this book, we discussed the evolution of distributed systems, the microservice architecture, messaging technologies, and NATS messaging in detail as separate topics. In this second part of this book, we will start by using what we learned previously to design an effective microservice architecture by exploring these topics further and the correlation among them in detail.

As we discussed in Chapter 2, Why Is Messaging Important in the Microservice Architecture?, microservice architecture-based platforms have two main message flows called North-South traffic and East-West traffic. Sometimes, East-West traffic is also called inter-service communication in a microservice architecture. In this chapter, we will discuss these messaging flows in detail and how NATS can be used for inter-service communication within the microservice architecture. We are going to cover the following main topics in this chapter...

Technical requirements

We will be using some code examples to demonstrate the practical usage of NATS for inter-service communication in a microservice architecture. Ensure you meet the following requirements in your development environment to try out the examples in this chapter:

  • Install the latest JDK to run the Java examples
  • Install Python3 to run the Python examples
  • Install the Go programming language to run the Go examples
  • Install the NATS server to test the client examples

The source code for the examples in this chapter can be found in the following GitHub repository: https://github.com/PacktPublishing/Designing-Microservices-Platforms-with-NATS/tree/main/chapter4.

Understanding the challenges of the microservice architecture

The microservice architecture offers many advantages such as agility, availability, and efficiency, to name a few. These advantages come with a set of challenges that need to be handled properly to gain the maximum output from the microservice architecture. Most of these challenges are related to the technical aspect of the solution, while there are also a few challenges related to organizational and team structure. Let's look at these challenges and understand what they are:

  • Identifying the service boundaries
  • Inter-service communication
  • Securing services
  • Monitoring services
  • Organizational structures

Let's discuss each challenge in detail so that we can correlate these points when designing the solution with NATS.

Identifying the service boundaries

Microservices are great when you have them. But getting started with microservices is the most challenging part since you need...

What is inter-service communication and why is it important?

In layman's terms, inter-service communication means sharing information between two applications (services) over a network in a distributed system. Sometimes, we call this process messaging. In Chapter 2, Why Is Messaging Important in the Microservice Architecture?, we discussed different messaging technologies and had a brief overview of how those technologies can be used in a microservice architecture. In this section, we will explore this topic in detail. The following diagram depicts the two types of message flows within a microservice architecture:

Figure 4.4 – Traffic flows within a microservice architecture

North-South traffic

The requests that come from applications and services outside the microservice platform toward the microservice platform via a service gateway such as an API gateway are considered North-South traffic.

East-West traffic

The requests flowing from...

Advantages of using NATS for inter-service communication

NATS was designed with a purpose. That purpose is inter-service communication. All the design decisions and performance improvements that have been made to the NATS ecosystem were done while keeping this core feature in mind. Before NATS, message broker solutions were mainly used for asynchronous, semi real-time, batch-based use cases and were considered as legacy components. But with the introduction of NATS, these traditional views on the message broker solutions were dismantled and people started utilizing it for their main real-time applications and use cases. The following is a list of advantages that NATS provides that can be utilized in a microservice architecture for inter-service communication:

  • NATS supports both request-reply and event-based communication models to support designing applications for both real-time and semi-real-time use cases.
  • Support for 40+ client types allows microservices to follow the...

Summary

In this chapter, first, we discussed the challenges that are faced in microservice-based application design and implementation. Then, we discussed the possible approaches that we can follow to tackle those challenges, especially using the NATS messaging platform. We used several examples to showcase the functionality of NATS using different programming languages. We discussed one of the most important aspects of the microservice architecture, which is inter-service communication, in detail. We went through the specific features of NATS that can help you design and implement successful microservice-based applications and platforms by handling inter-service communication. Finally, we looked at the advantages of NATS, especially in the microservice architecture context.

Now, you should be able to understand the importance of inter-service communication in a microservice architecture and how NATS can be utilized for this. We will discuss a practical reference architecture for...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Designing Microservices Platforms with NATS
Published in: Nov 2021 Publisher: Packt ISBN-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.
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}