Designing Microservices Platforms with NATS

Book description

A complete reference for designing and building scalable microservices platforms with NATS messaging technology for inter-service communication with security and observability

Key Features

  • Understand the use of a messaging backbone for inter-service communication in microservices architecture
  • Design and build a real-world microservices platform with NATS as the messaging backbone using the Go programming language
  • Explore security, observability, and best practices for building a microservices platform with NATS

Book Description

Building a scalable microservices platform that caters to business demands is critical to the success of that platform. In a microservices architecture, inter-service communication becomes a bottleneck when the platform scales. This book provides a reference architecture along with a practical example of how to implement it for building microservices-based platforms with NATS as the messaging backbone for inter-service communication.

In Designing Microservices Platforms with NATS, you'll learn how to build a scalable and manageable microservices platform with NATS. The book starts by introducing concepts relating to microservices architecture, inter-service communication, messaging backbones, and the basics of NATS messaging. You'll be introduced to a reference architecture that uses these concepts to build a scalable microservices platform and guided through its implementation. Later, the book touches on important aspects of platform securing and monitoring with the help of the reference implementation. Finally, the book concludes with a chapter on best practices to follow when integrating with existing platforms and the future direction of microservices architecture and NATS messaging as a whole.

By the end of this microservices book, you'll have developed the skills to design and implement microservices platforms with NATS.

What you will learn

  • Understand the concepts of microservices architecture
  • Get to grips with NATS messaging technology
  • Handle transactions and message delivery guarantees with microservices
  • Implement a reference architecture for microservices using NATS
  • Discover how to improve the platform's security and observability
  • Explore how a NATS microservices platform integrates with an enterprise ecosystem

Who this book is for

This book is for enterprise software architects and developers who want to gain hands-on microservices experience for designing, implementing, and managing complex distributed systems with microservices architecture concepts. Intermediate-level experience in any programming language and software architecture is required to make the most of this book.

Table of contents

  1. Designing Microservices Platforms with NATS
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Code in Action
    6. Download the color images
    7. Conventions used
    8. Get in touch
    9. Share Your Thoughts
  6. Section 1: The Basics of Microservices Architecture and NATS
  7. Chapter 1: Introduction to the Microservice Architecture
    1. The evolution of distributed systems
      1. Failure handling
      2. Concurrency
      3. Security of data
      4. Standardizing data
      5. Scalability
      6. Microservices and containers
      7. Container-based deployments
    2. What is a microservice architecture?
      1. Microservices are small and do one thing well
      2. Microservices are autonomous and act as cohesive units
    3. Characteristics of the microservice architecture
      1. Componentization via services
      2. Business domain-driven scope for each service
      3. Decentralized governance
      4. Decentralized data management
      5. Smart endpoints and dumb pipes
      6. Infrastructure automation
      7. Container-based deployments
      8. Design for failure
      9. Agile development
      10. Evolving architecture
    4. Breaking down a monolith into microservices
      1. Business functions implemented as separate microservices
      2. Each microservice has a datastore
      3. Message broker for inter-service communication
      4. The web interface is designed as a single-page application (SPA)
    5. Advantages of the microservice architecture
      1. Build robust, resilient applications
      2. Build scalable, available applications for modern businesses
      3. Better utilization of computing resources
      4. Helps an innovation-driven organization culture
      5. Build manageable systems
    6. Summary
    7. Further reading
  8. Chapter 2: Why Is Messaging Important in the Microservice Architecture?
    1. Messaging patterns used in distributed systems
      1. RPC versus shared resources
      2. Synchronous versus asynchronous (client-server versus event-based)
      3. Orchestration versus choreography
    2. Communication requirements of a microservice architecture
    3. Common messaging technologies used in a microservice architecture
      1. North-South traffic
      2. East-West traffic
    4. Summary
  9. Chapter 3: What Is NATS Messaging?
    1. Technical requirements
    2. History of NATS
    3. Introduction to NATS
      1. Subject-based messaging
      2. Publish-subscribe messaging
      3. Request-reply messaging
      4. Queue groups messaging
    4. How does the NATS protocol work?
      1. Protocol conventions
      2. Protocol messages
      3. Setting up the environment
      4. Connecting to the NATS server
      5. Sending and receiving messages
    5. Advanced NATS concepts
      1. Clustering the NATS server
      2. Monitoring NATS
      3. Security with NATS
    6. Advantages of NATS
    7. Summary
    8. Further reading
  10. Section 2: Building Microservices with NATS
  11. Chapter 4: How to Use NATS in a Microservice Architecture
    1. Technical requirements
    2. Understanding the challenges of the microservice architecture
      1. Identifying the service boundaries
      2. Inter-service communication
      3. Securing services
      4. Monitoring services
      5. Organizational structures
    3. What is inter-service communication and why is it important?
      1. How NATS solves the inter-service communication challenge
    4. Advantages of using NATS for inter-service communication
    5. Summary
  12. Chapter 5: Designing a Microservice Architecture with NATS
    1. Understanding the key components of a microservice architecture
      1. Inner architecture
    2. Understanding how NATS is positioned in the microservice architecture
      1. Microservices interact with the NATS server as NATS clients
      2. Existing business applications and services interact with the NATS server via the anti-corruption layer
      3. Security components interact with the NATS server for implementing advanced security
    3. Reference architecture for microservices with NATS
      1. Clients
      2. Delivery services
      3. Edge services
      4. Supportive services
      5. Core services
      6. NATS server
      7. Integration platform
      8. Existing services
      9. Cross-cutting services
    4. Summary
    5. Further reading
  13. Chapter 6: A Practical Example of Microservices with NATS
    1. Technical requirements
    2. Understanding the use case of a hospital OPD
      1. Patient registration process
      2. Patient inspection process
      3. Temporary treatment and testing
      4. Releasing the patient
      5. Service composition
      6. API composition layer
      7. Client-side composition
      8. Security for services
    3. Defining the solution architecture
      1. Clients (Consumers)
      2. API management (with WSO2 API Manager 4.0)
      3. Microservices in Go
      4. NATS server
      5. NATS token store
      6. Integration (with WSO2 Micro Integrator 4.0)
      7. Existing services
      8. Cross-cutting functions
      9. Components that were skipped
    4. Deployment architecture
    5. Implementing microservices
      1. Registration service
      2. Inspection service
      3. Treatment service
      4. Release service
    6. Setting up the NATS server cluster
      1. Starting up the three-node NATS server cluster
    7. Trying out the sample application
      1. Prerequisites
      2. Starting the microservices
      3. Testing the OPD application
    8. Summary
  14. Chapter 7: Securing a Microservices Architecture with NATS
    1. Technical requirements
    2. Understanding security in the context of a microservices architecture
      1. Security with OAuth 2.0
    3. Securing external communication
      1. Implementing security at each microservice level
      2. Implementing security using a sidecar
      3. Implementing security using an API gateway
    4. Securing ISC
      1. Security with TLS
      2. Security with authentication
      3. Security with authorization
    5. Using NATS to secure ISC
      1. Implementing TLS with NATS for microservices
      2. Implementing basic authentication and authorization with NATS
    6. Summary
  15. Chapter 8: Observability with NATS in a Microservices Architecture
    1. Technical requirements
    2. Observability in a microservices context
      1. Observability in containerized deployments
      2. Best practices for microservices observability
    3. Observability features of NATS
      1. Logging
      2. Monitoring
    4. Using NATS observability in a microservices architecture
      1. Prometheus
      2. Grafana
      3. Loki and Promtail
      4. Adding the health check API
      5. Adding CorrelationID to the requests
      6. Adding improved logging for microservices
      7. Collecting metrics and exposing them for application monitoring
      8. Exporting NATS server metrics
      9. Starting microservices
      10. Configuring Prometheus
      11. Configuring Loki and Promtail
      12. Configuring Grafana
    5. Summary
  16. Section 3: Best Practices and Future Developments
  17. Chapter 9: How Microservices and NATS Coexist with Integration Platforms
    1. Technical requirements
    2. Understanding the brownfield enterprise software system
    3. How do integration platforms work in an enterprise software system?
      1. Solution architecture of an enterprise software system with an integration platform
    4. How do microservices and NATS integrate with the integration platform?
      1. Microservices as process APIs
      2. Microservices as system APIs
      3. Microservices as core systems
      4. Microservices and the integration platform
    5. How to build an enterprise platform with microservices, NATS, and the integration platform
      1. Setting up the sample OPD application with WSO2 integration platform
      2. Setting up the NATS server
      3. Setting up microservices
      4. Setting up WSO2 API Manager 4
      5. Creating API proxies and publishing them on the portal
      6. Setting up WSO2 Micro Integrator
    6. Setting up observability
    7. Summary
  18. Chapter 10: Future of the Microservice Architecture and NATS
    1. Technical requirements
    2. Challenges of the proposed microservice architecture with NATS
      1. Message delivery guarantees and error handling
      2. Security
      3. Deployment and automation
    3. What are the new developments in the microservice architecture?
      1. Service mesh for interservice communication
      2. Saga pattern and managing data
      3. Serverless computing and microservices
    4. What are the new developments in the NATS messaging technology?
      1. JetStream
      2. Using NATS to build an observability solution
    5. How can a microservice architecture with NATS be improved?
      1. Using JetStream for improved message guarantees and stream processing
      2. Using the saga pattern to develop applications with transactional requirements
      3. Using serverless platforms to build microservices
      4. Hybrid deployments to support brownfield enterprises
    6. Summary
    7. Why subscribe?
  19. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts

Product information

  • Title: Designing Microservices Platforms with NATS
  • Author(s): Chanaka Fernando
  • Release date: November 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781801072212