Implementing Event-Driven Microservices Architecture in .NET 7 - Joshua Garverick - E-Book

Implementing Event-Driven Microservices Architecture in .NET 7 E-Book

Joshua Garverick

0,0
32,39 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

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.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 369

Veröffentlichungsjahr: 2023

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Implementing Event-Driven Microservices Architecture in .NET 7

Develop event-based distributed apps that can scale with ever-changing business demands using C# 11 and .NET 7

Joshua Garverick

Omar Dean McIver

BIRMINGHAM—MUMBAI

Implementing Event-Driven Microservices Architecture 
in .NET 7

Copyright © 2023 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Associate Group Product Manager: Gebin George

Publishing Product Manager: Kunal Sawant

Content Development Editor: Rosal Colaco

Technical Editor: Maran Fernandes

Copy Editor: Safis Editing

Project Coordinator: Manisha Singh

Proofreader: Safis Editing

Indexer: Subalakshmi Govindhan

Production Designer: Shyam Sundar Korumilli

Business Development Executive: Debadrita Chatterjee

Developer Relations Marketing Executive: Rayyan Khan and Deepak Kumar

First published: February 2023

Production reference: 2090323

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80323-278-2

www.packtpub.com

To my wife, Melissa, and daughter, Audrey, for bringing me inspiration and supporting me while I go off and do things like write books.

– Josh Garverick

To my wife, Raegan, your love, support, and patience have made it possible for me to pursue my passion. And to my children, Olivia, Maxwell, and Benjamin, who bring light to my life with every new experience we share.

– Omar McIver

Foreword

In today’s rapidly changing technology landscape, it’s more important than ever to build software that can adapt to change and scale to meet the demands of users. Microservices have emerged as a popular architectural pattern for building flexible and scalable software systems. However, managing the complexity of microservice-based systems can be a daunting task.

Event-Driven Architecture (EDA) has become an increasingly popular solution to this challenge, as it allows services to communicate with each other in a loosely coupled manner, making it easier to build scalable and fault-tolerant systems. In this book, Josh Garverick and Omar McIver provide a comprehensive guide to implementing event-driven microservice architectures using .NET 7.

I have known Josh for a long time, and he has a wealth of experience in designing and building software systems using .NET. In this book, he shares his knowledge and expertise to help readers build better, more scalable, and more resilient microservice-based systems. He covers all the key concepts and techniques involved in implementing event-driven microservice architectures, including Domain-Driven Design (DDD), containerization, and implementing event-driven communication patterns.

What I particularly appreciate about this book is the practical, hands-on approach that Josh and Omar take. They provide an example application that illustrates how to apply EDA to real-world scenarios. They also cover the latest features of .NET 7, including minimal APIs, async streaming, and hot reload compatibility.

Having coined the phrase “Rub a little DevOps on it,” I was thrilled to read the chapter on CI/CD Pipelines and Integrated Testing. Josh helps developers through the entire lifecycle of a microservices application including testing, observability, and even fault injection, and chaos testing.

This book is an essential resource for anyone involved in building microservice-based systems using .NET 7. Whether you’re a seasoned developer or just getting started with microservices, Josh’s and Omar’s insights and expertise will help you build better, more scalable, and more resilient software systems. I highly recommend this book to anyone who wants to stay ahead of the curve in modern software development.

Donovan Brown

Partner Program Manager, Azure Incubations office of CTO, Microsoft Corporation

Contributors

About the authors

Josh Garverick, an eight-time Microsoft MVP in Azure, is the author of the book Migrating to Azure, a contributing author to The Developer’s Guide to Azure (2021), and the author of several online courses. Josh is a seasoned IT professional with more than 15 years of enterprise experience. He has worked in several large industry verticals, such as finance, healthcare, transportation, logistics, retail/consumer products, oil and gas, and insurance. He specializes in digital transformation as well as application life cycle management and is currently involved in enterprise cloud adoption projects.

Omar McIver is a Microsoft Certified Trainer and has more than 12 years of experience in developing enterprise-grade applications in regulated and global retail industries. He specializes in cloud-native development and application modernization. He is a certified Azure Solution Architect and FinOps Practitioner. His Udemy course on Practical OAuth, OpenID, and JWT in C# .NET Core has a rating of 4.5 stars. Omar continues to stay at the forefront of cloud-native development, with a keen focus on cost optimization, performance tuning, and highly scalable microservice architectures.

About the reviewers

Mikhail Filippov works at JetBrains as the team lead of Rider (cross-platform IDE for .NET). During 20 years of software development experience, Mikhail got deep technical expertise in various areas, including .NET runtime internals, ASP.NET MVC, MSBuild, and best practices for designing large-scale development infrastructures. Mikhail is a speaker at multiple events for developers and an active open source contributor. In his free time, Mikhail likes reading science fiction books and working on hobby projects using C# and Kotlin.

Jamie Taylor is a Microsoft MVP, software engineer, mentor, and podcaster with over a decade and a half of experience working with the .NET technology stack.

His primary focus is on his family, who inspire him every day. With a background in teaching, he focuses his energies on mentoring, writing incredibly high-quality code, and sharing his knowledge with everyone who will listen.

Outside of development and mentoring, Jamie is a keen podcaster - hosting three incredibly successful podcasts: The .NET Core Podcast, Tabs and Spaces, and The Waffling Taylors - and has collaborated with musicians, creating music and playing the bass guitar on a few recorded pieces.

Table of Contents

Preface

Part 1: Event-Driven Architecture and .NET 7

1

The Sample Application

Technical requirements

Exploring business drivers and the application

Reviewing the domain model

Assessing architectural structures and paradigms

A high-level logical architecture

Event sourcing

Command-Query Responsibility Segregation

Reviewing the implementation details

The Visual Studio solution topology

Identity and Access Management considerations

Event structure and schema

Local development and debugging

New .NET 7 features

Summary

Questions

Further reading

2

The Producer-Consumer Pattern

Technical requirements

Examining producers and consumers

Relating to real-world examples

Enabling event-driven architectures

Understanding the adoption curve

Exploring implementation details in code

The producer code

The consumer code

Event handling

Reviewing implementation details in infrastructure

Topics

Streams and tables

Aggregate storage

Summary

Questions

Further reading

3

Message Brokers

Technical requirements

What is a message broker?

Queue-based technology

Cache-based technology

Stream-based technology

Inspecting messaging protocols, schemas, and delivery patterns

Messaging protocols

Standard and custom schemas

Message delivery patterns

Implementing message broker technologies

Reviewing essential Kafka components

Enabling resiliency and scalability

Summary

Questions

Further reading

4

Domain Model and Asynchronous Events

Technical requirements

Solution structure

Core library review

Reviewing domain structures and components

Equipment

Station

Maintenance

Scheduling

Notifications

Passenger

Identification

Using asynchronous actions

Benefits of asynchronous programming

Asynchronous parallel processing

Summary

Questions

Further reading

Part 2: Testing and Deploying Microservices

5

Containerization and Local Environment Setup

Technical requirements

Reviewing containerization fundamentals

Development benefits

Setting up the local environment

Creating local infrastructure using Docker

Leveraging GitHub Codespaces and Dev Containers

Using Dockerfiles to build and run locally

Sequential versus multi-stage files

Adding services to the Docker Compose file

Summary

Questions

Further reading

6

Localized Testing and Debugging of Microservices

Technical requirements

Configuring orchestration and containers

Everything as Code (EaC)

Creating container images

Debugging in containers

Debugging individual microservices

Orchestrating and debugging all services

Fixing the Debug custom image

Testing against containers

Functionality testing

Load testing

Summary

Questions

Further reading

7

Microservice Observability

Technical requirements

Observability

Metrics

Logs

Traces

Liveness and readiness

Liveness endpoints

Readiness endpoints

Aggregation of logs

Creating an Azure Application Insights instance

Streaming telemetry to Application Insights

Streaming logs to Application Insights

Correlation and causation

Producing logging and an event payload with correlation and causation IDs

Consumer logging with consistent correlation and causation IDs

Summary

Questions

Further reading

8

CI/CD Pipelines and Integrated Testing

Reviewing common CI/CD patterns

Environment-based

Artifact management

Triggers and gating

Feature flags

Enabling GitHub Actions for CI/CD implementation

GitHub Actions for continuous integration

GitHub Actions for continuous deployment

Choosing an Integration Test Suite Methodology

Summary

Questions

Further reading

9

Fault Injection and Chaos Testing

Technical requirements

Fault tolerance and fault injection

Anticipating and tolerating faults

Using your faults against you

Chaos testing

The order of chaos engineering

Implementing fault injection and chaos tests

Starting with Chaos Mesh

Using Azure Chaos Studio

Summary

Questions

Further reading

Part 3: Testing and Deploying Microservices

10

Modern Design Patterns for Scalability

Mechanisms for autoscaling

Compute and CPU load

Disk and I/O load

Request and network load

Memory-intensive operations

Implementing autoscaling for Kubernetes services

Native Kubernetes options

Cloud platform options

Third-party plugins

Implementing autoscaling for Azure App Service

Common platform options

Adjustments for Web Apps

Adjustments for API Apps

Summary

Questions

Further reading

11

Minimizing Data Loss

Technical requirements

Preventing data loss

Data consistency paradigms

ACID paradigm/immediate consistency

BASE paradigm / eventual consistency

The Saga pattern

Command query responsibility segregation (CQRS)

Identifying acceptable data loss

Acceptable and unacceptable data loss

Methods of data loss

Delivery guarantees

At-most-once delivery

At-least-once delivery

Effectively-once delivery

Data loss implications

Summary

Questions

Further reading

12

Service and Application Resiliency

Technical requirements

Resiliency through cloud-native patterns

Redundancy and enabling business continuity

Event retries and continuity

Local data redundancy

Infrastructure continuity

Graceful communication between services

Common results

Summary

Questions

Further reading

13

Telemetry Capture and Integration

Technical requirements

Application- versus service- versus component-level telemetry

Implementing non-intrusive telemetry capture

Implementing custom telemetry capture

Bubbling up meaningful information

Metric ingestion with the Prometheus exporter

Distributed tracing using the Jaeger exporter

Summary

Questions

Further reading

14

Observability Revisited

Technical requirements

Sharing API services

Generating service information

OpenAPI specification

A brief history of Swagger

Generating the Swagger documentation

Service discovery

It’s not quite load balancing…

Exploring Consul

Service discovery/registration

Service resolution

Service publishing

Azure API Management

Service cataloging

Summary

Questions

Further reading

Assessments

Chapter 1, The Sample Application

Chapter 2, The Producer-Consumer Pattern

Chapter 3, Message Brokers

Chapter 4, Domain Model and Asynchronous Events

Chapter 5, Containerization and Local Environment Setup

Chapter 6, Localized Testing and Debugging of Microservices

Chapter 7, Microservice Observability

Chapter 8, CI/CD Pipelines and Integrated Testing

Chapter 9, Fault Injection and Chaos Testing

Chapter 10, Modern Design Patterns for Scalability

Chapter 11, Minimizing Data Loss

Chapter 12, Service and Application Resiliency

Chapter 13, Telemetry Capture and Integration

Chapter 14, Observability Revisited

Index

Other Books You May Enjoy

Part 1:Event-Driven Architecture and .NET 7

This part will cover the new features of .NET 7 that will make developing applications using EDA patterns easier, as well as 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.

This part has the following chapters:

Chapter 1, The Sample ApplicationChapter 2, The Producer-Consumer PatternChapter 3, Message BrokersChapter 4, Domain Model and Asynchronous Design