Implementing Event-Driven Microservices Architecture in .NET 7

Book description

Implement modern design patterns that leverage domain-driven data, to achieve resiliency and scalability for data-dependent applications

Key Features

  • Learn the tenets of event-driven architecture, coupled with reliable design patterns to enhance your knowledge of distributed systems and build a foundation for professional growth
  • Understand how to translate business goals and drivers into a domain model that can be used to develop an app that enables those goals and drivers
  • Identify areas to enhance development and ensure operational support through the architectural design process

Book Description

This book will guide you through various hands-on practical examples for implementing event-driven microservices architecture using C# 11 and .NET 7. It has been divided into three distinct sections, each focusing on different aspects of this implementation.

The first section will cover the new features of .NET 7 that will make developing applications using EDA patterns easier, the sample application that will be used throughout the book, and how the core tenets of domain-driven design (DDD) are implemented in .NET 7.

The second section will review the various components of a local environment setup, the containerization of code, testing, deployment, and the observability of microservices using an EDA approach.

The third section will guide you through the need for scalability and service resilience within the application, along with implementation details related to elastic and autoscale components. You’ll also cover how proper telemetry helps to automatically drive scaling events. In addition, the topic of observability is revisited using examples of service discovery and microservice inventories.

By the end of this book, you’ll be able to identify and catalog domains, events, and bounded contexts to be used for the design and development of a resilient microservices architecture.

What you will learn

  • Explore .NET 7 and how it enables the development of applications using EDA
  • Understand messaging protocols and producer/consumer patterns and how to implement them in .NET 7
  • Test and deploy applications written in .NET 7 and designed using EDA principles
  • Account for scaling and resiliency in microservices
  • Collect and learn from telemetry at the platform and application level
  • Get to grips with the testing and deployment of microservices

Who this book is for

This book will help .NET developers and architects looking to leverage or pivot to microservices while using a domain-driven event model.

Table of contents

  1. Implementing Event-Driven Microservices Architecture 
in .NET 7
  2. Foreword
  3. Contributors
  4. About the authors
  5. About the reviewers
  6. 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. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
    9. Download a free PDF copy of this book
  7. Part 1:Event-Driven Architecture and .NET 7
  8. Chapter 1: The Sample Application
    1. Technical requirements
    2. Exploring business drivers and the application
      1. Reviewing the domain model
    3. Assessing architectural structures and paradigms
      1. A high-level logical architecture
      2. Event sourcing
      3. Command-Query Responsibility Segregation
    4. Reviewing the implementation details
      1. The Visual Studio solution topology
      2. Identity and Access Management considerations
      3. Event structure and schema
      4. Local development and debugging
      5. New .NET 7 features
    5. Summary
    6. Questions
    7. Further reading
  9. Chapter 2: The Producer-Consumer Pattern
    1. Technical requirements
    2. Examining producers and consumers
      1. Relating to real-world examples
      2. Enabling event-driven architectures
      3. Understanding the adoption curve
    3. Exploring implementation details in code
      1. The producer code
      2. The consumer code
      3. Event handling
    4. Reviewing implementation details in infrastructure
      1. Topics
      2. Streams and tables
      3. Aggregate storage
    5. Summary
    6. Questions
    7. Further reading
  10. Chapter 3: Message Brokers
    1. Technical requirements
    2. What is a message broker?
      1. Queue-based technology
      2. Cache-based technology
      3. Stream-based technology
    3. Inspecting messaging protocols, schemas, and delivery patterns
      1. Messaging protocols
      2. Standard and custom schemas
      3. Message delivery patterns
    4. Implementing message broker technologies
      1. Reviewing essential Kafka components
      2. Enabling resiliency and scalability
    5. Summary
    6. Questions
    7. Further reading
  11. Chapter 4: Domain Model and Asynchronous Events
    1. Technical requirements
      1. Solution structure
      2. Core library review
    2. Reviewing domain structures and components
      1. Equipment
      2. Station
      3. Maintenance
      4. Scheduling
      5. Notifications
      6. Passenger
      7. Identification
    3. Using asynchronous actions
      1. Benefits of asynchronous programming
      2. Asynchronous parallel processing
    4. Summary
    5. Questions
    6. Further reading
  12. Part 2:Testing and Deploying Microservices
  13. Chapter 5: Containerization and Local Environment Setup
    1. Technical requirements
    2. Reviewing containerization fundamentals
      1. Development benefits
    3. Setting up the local environment
      1. Creating local infrastructure using Docker
      2. Leveraging GitHub Codespaces and Dev Containers
    4. Using Dockerfiles to build and run locally
      1. Sequential versus multi-stage files
      2. Adding services to the Docker Compose file
    5. Summary
    6. Questions
    7. Further reading
  14. Chapter 6: Localized Testing and Debugging of Microservices
    1. Technical requirements
    2. Configuring orchestration and containers
      1. Everything as Code (EaC)
      2. Creating container images
    3. Debugging in containers
      1. Debugging individual microservices
      2. Orchestrating and debugging all services
      3. Fixing the Debug custom image
    4. Testing against containers
      1. Functionality testing
      2. Load testing
    5. Summary
    6. Questions
    7. Further reading
  15. Chapter 7: Microservice Observability
    1. Technical requirements
    2. Observability
      1. Metrics
      2. Logs
      3. Traces
    3. Liveness and readiness
      1. Liveness endpoints
      2. Readiness endpoints
    4. Aggregation of logs
      1. Creating an Azure Application Insights instance
      2. Streaming telemetry to Application Insights
      3. Streaming logs to Application Insights
    5. Correlation and causation
      1. Producing logging and an event payload with correlation and causation IDs
      2. Consumer logging with consistent correlation and causation IDs
    6. Summary
    7. Questions
    8. Further reading
  16. Chapter 8: CI/CD Pipelines and Integrated Testing
    1. Reviewing common CI/CD patterns
      1. Environment-based
      2. Artifact management
      3. Triggers and gating
      4. Feature flags
    2. Enabling GitHub Actions for CI/CD implementation
      1. GitHub Actions for continuous integration
      2. GitHub Actions for continuous deployment
    3. Choosing an Integration Test Suite Methodology
    4. Summary
    5. Questions
    6. Further reading
  17. Chapter 9: Fault Injection and Chaos Testing
    1. Technical requirements
    2. Fault tolerance and fault injection
      1. Anticipating and tolerating faults
      2. Using your faults against you
    3. Chaos testing
      1. The order of chaos engineering
    4. Implementing fault injection and chaos tests
      1. Starting with Chaos Mesh
      2. Using Azure Chaos Studio
    5. Summary
    6. Questions
    7. Further reading
  18. Part 3:Testing and Deploying Microservices
  19. Chapter 10: Modern Design Patterns for Scalability
    1. Mechanisms for autoscaling
      1. Compute and CPU load
      2. Disk and I/O load
      3. Request and network load
      4. Memory-intensive operations
    2. Implementing autoscaling for Kubernetes services
      1. Native Kubernetes options
      2. Cloud platform options
      3. Third-party plugins
    3. Implementing autoscaling for Azure App Service
      1. Common platform options
      2. Adjustments for Web Apps
      3. Adjustments for API Apps
    4. Summary
    5. Questions
    6. Further reading
  20. Chapter 11: Minimizing Data Loss
    1. Technical requirements
    2. Preventing data loss
    3. Data consistency paradigms
      1. ACID paradigm/immediate consistency
      2. BASE paradigm / eventual consistency
      3. The Saga pattern
      4. Command query responsibility segregation (CQRS)
    4. Identifying acceptable data loss
      1. Acceptable and unacceptable data loss
      2. Methods of data loss
    5. Delivery guarantees
      1. At-most-once delivery
      2. At-least-once delivery
      3. Effectively-once delivery
    6. Data loss implications
    7. Summary
    8. Questions
    9. Further reading
  21. Chapter 12: Service and Application Resiliency
    1. Technical requirements
    2. Resiliency through cloud-native patterns
    3. Redundancy and enabling business continuity
      1. Event retries and continuity
      2. Local data redundancy
      3. Infrastructure continuity
    4. Graceful communication between services
      1. Common results
    5. Summary
    6. Questions
    7. Further reading
  22. Chapter 13: Telemetry Capture and Integration
    1. Technical requirements
    2. Application- versus service- versus component-level telemetry
    3. Implementing non-intrusive telemetry capture
    4. Implementing custom telemetry capture
    5. Bubbling up meaningful information
      1. Metric ingestion with the Prometheus exporter
      2. Distributed tracing using the Jaeger exporter
    6. Summary
    7. Questions
    8. Further reading
  23. Chapter 14: Observability Revisited
    1. Technical requirements
    2. Sharing API services
    3. Generating service information
      1. OpenAPI specification
      2. A brief history of Swagger
      3. Generating the Swagger documentation
    4. Service discovery
      1. It’s not quite load balancing…
      2. Exploring Consul
      3. Service discovery/registration
      4. Service resolution
    5. Service publishing
      1. Azure API Management
    6. Service cataloging
    7. Summary
    8. Questions
    9. Further reading
  24. Assessments
    1. Chapter 1, The Sample Application
    2. Chapter 2, The Producer-Consumer Pattern
    3. Chapter 3, Message Brokers
    4. Chapter 4, Domain Model and Asynchronous Events
    5. Chapter 5, Containerization and Local Environment Setup
    6. Chapter 6, Localized Testing and Debugging of Microservices
    7. Chapter 7, Microservice Observability
    8. Chapter 8, CI/CD Pipelines and Integrated Testing
    9. Chapter 9, Fault Injection and Chaos Testing
    10. Chapter 10, Modern Design Patterns for Scalability
    11. Chapter 11, Minimizing Data Loss
    12. Chapter 12, Service and Application Resiliency
    13. Chapter 13, Telemetry Capture and Integration
    14. Chapter 14, Observability Revisited
  25. Index
    1. Why subscribe?
  26. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
    3. Download a free PDF copy of this book

Product information

  • Title: Implementing Event-Driven Microservices Architecture in .NET 7
  • Author(s): Joshua Garverick, Omar Dean McIver
  • Release date: March 2023
  • Publisher(s): Packt Publishing
  • ISBN: 9781803232782