Hands-On Microservices with C# 8 and .NET Core 3: Refactor you monolith architecture into microservices using Azure, 3rd Edition
Book information
Description
Learn the essential concepts, techniques, and design patterns that will help you build scalable and maintainable distributed systems Key FeaturesLearn to design, implement, test, and deploy your microservicesUnderstand the challenges and complexities of testing and monitoring distributed servicesBuild modular and robust microservice architectures with the latest features of C# 8 and .NET Core 3.1Book Description The microservice architectural style promotes the development of complex applications as a suite of small services based on specific business capabilities. With this book, you'll take a hands-on approach to build microservices and deploy them using ASP .NET Core and Microsoft Azure. You'll start by understanding the concept of microservices and their fundamental characteristics. This microservices book will then introduce a real-world app built as a monolith, currently struggling under increased demand and complexity, and guide you in its transition to microservices using the latest features of C# 8 and .NET Core 3. You'll identify service boundaries, split the application into multiple microservices, and define service contracts. You'll also explore how to configure, deploy, and monitor microservices using Docker and Kubernetes, and implement autoscaling in a microservices architecture for enhanced productivity. Once you've got to grips with reactive microservices, you'll discover how keeping your code base simple enables you to focus on what's important rather than on messy asynchronous calls. Finally, you'll delve into various design patterns and best practices for creating enterprise-ready microservice applications. By the end of this book, you'll be able to deconstruct a monolith successfully to create well-defined microservices. What you will learnPackage, deploy, and manage microservices and containers with Azure Service FabricUse REST APIs to integrate services using a synchronous approachProtect public APIs using Azure Active Directory and OAuth 2.0Understand the operation and scaling of microservices using Docker and KubernetesImplement reactive microservices with Reactive ExtensionsDiscover design patterns and best practices for building enterprise-ready appsWho this book is for This book is for C# and .NET Core developers who want to understand microservices architecture and implement it in their .NET Core applications. If you're new to building microservices or have theoretical knowledge of the architectural approach, this book will help you gain a practical perspective to manage application complexity efficiently. Table of ContentsAn Introduction to MicroservicesRefactoring the monolithEffective communication between servicesTesting Microservices with Microsoft Unit Testing FrameworkDeploying microservices with DockerSecuring Microservices using Azure Active DirectoryMonitoring microservicesScaling microservices with AzureIntroduction to Reactive MicroservicesDesign Patterns and Best PracticesBuilding Microservice ApplicationMicroservices Architecture SummaryAppendix Cover Title Page Copyright and Credits Dedication Packt Upsell Foreword Contributors Table of Contents Preface Chapter 1: An Introduction to Microservices Technical requirements The origin of microservices Discussing microservices Exploring monolithic architecture Service-oriented architecture Understanding services Understanding microservice architecture Messaging in microservices Synchronous messaging Asynchronous messaging Message formats Using microservices The workings of microservice architecture The advantages of microservices SOA versus microservices The prerequisites of microservice architecture Understanding the problems with the monolithic architectural style The challenges in standardizing a .NET stack Fault tolerance The scaling property of a system Vertical scaling or scale-up Horizontal scaling or scale-out Deployment challenges Organizational alignment Modularity Big database Prerequisites for microservices Functional overview of the application Solutions for the current challenges Handling deployment problems Making better monolithic applications Introducing dependency injections Database refactoring Database sharding and partitioning DevOps culture Automation Testing Versioning Deployment Identifying decomposition candidates within monolithic Important microservices advantages Technology independence Interdependency removal Alignment with business goals Cost benefits Easy scalability Security Data management Integrating monolithic applications with microservices An overview of Azure Service Fabric Summary Questions Chapter 2: Refactoring the Monolith Technical requirements Understanding the current and new technology stack Discussion – current stack (C#, EF, and SQL Server) C# 8 Entity Framework Core Visual Studio 2019 Microsoft SQL Server New features in .NET Core New features in C# 8.0 Enabling support for the C# 8.0 language using Visual Studio Indices and ranges The readonly members Default interface methods The size of microservices What makes a good service? DDD and its importance for microservices Domain model design Importance for microservices Understanding the concept of seam Module interdependency Technology Team structure Databases Master data Transactions Communication between microservices The benefits of the API gateway for microservices API gateway versus API management Revisiting the FlixOne case study Prerequisites Transitioning to our product service Migrations Code migration Creating our project Adding the model Adding a repository Registering repositories Adding a product controller The ProductService API Adding EF Core support EF Core DbContext EF Core migrations Database migration Revisiting repositories and the controller Introducing ViewModel Revisiting ProductController Adding Swagger support Summary Questions Further reading Chapter 3: Effective Communication between Services Technical requirements Understanding communication between services Styles of collaboration Learning about integration patterns The API gateway The event-driven pattern Event-sourcing pattern Eventual consistency pattern Compensating transactions Competing consumers Understanding Azure Service Fabric Service Fabric architecture Discussing the orchestrator Service Fabric programming models overview Implementing information on competing consumers Azure Service Bus Azure message queues Implementing information on Service Fabric Prerequisites Sending messages to the queue Adding configuration settings Receiving messages from the queue Implementing information on containers Containers on Service Fabric Prerequisites Execution Microservices with Kubernetes An overview of Azure Kubernetes Service (AKS) Important concepts Ease of deploying and managing microservices The sidecar pattern When to use the sidecar pattern Best practices to be observed The ambassador pattern When to use the ambassador pattern Best practices to be observed Considering IoT when building microservices apps An overview of IoT Hub An overview of IoT Edge Summary Questions Further reading Chapter 4: Testing Microservices with the Microsoft Unit Testing Framework Technical requirements Testing the microservice application Handling testing challenges with microservices Understanding testing strategies Testing pyramid Types of microservice tests Unit testing Component (service) testing Integration testing Contract testing Consumer-driven contracts How to implement a consumer-driven test How Pact-net-core helps us achieve our goal Performance testing End-to-end (UI/functional) testing Sociable versus isolated unit tests Stubs and mocks Testing the microservice application Getting ready for the test project Unit tests Integration tests Summary Questions Further reading Chapter 5: Deploying Microservices with Docker Technical requirements Monolithic application deployment challenges Understanding the deployment terminology Prerequisites for successful microservice deployments Isolation requirements for microservice deployment The need for a new deployment paradigm The way out – containers What are containers? Suitability of containers over virtual machines Transformation of the operation team's mindset Containers are new binaries Does it work on your machine? Let's ship your machine! Introducing Docker Deploying a sample application Microservice deployment example using Docker Setting up Docker on your machine Prerequisites Creating an ASP.NET Core web application Summary Questions Further reading Chapter 6: Securing Microservices Using Azure Active Directory Technical requirements Security in monolithic applications Security in microservices Why won't a traditional .NET auth mechanism work? JSON Web Tokens Working with OAuth 2.0 Exploring OpenID Connect Understanding Azure Active Directory Microservice Auth example with OpenID Connect, OAuth 2.0, and Azure AD Registering our application with the Azure AD tenant Generating AppKey for FlixOne.BookStore.Web Configuring Visual Studio solution projects Generating client certificates on IIS Express Running both applications Managing Azure API Management as an API gateway An example of a rate limit and quota policy Understanding container security Other security best practices Summary Questions Further reading Chapter 7: Monitoring Microservices Technical requirements Setting up .NET Core 3.1 A valid Azure account Beginning with instrumentation and telemetry Instrumentation Telemetry The need for monitoring Health monitoring Availability monitoring SLA monitoring Performance monitoring Security monitoring Auditing sensitive data and critical business transactions End user monitoring Troubleshooting system failures Understanding the monitoring challenges Scaling issues DevOps mindset Data flow visualization Testing monitoring tools Working on monitoring strategies Application/system monitoring Real user monitoring Semantic monitoring and synthetic transactions Profiling Endpoint monitoring Understanding logging Logging challenges Logging strategies Centralized logging Using a correlation ID in logging Semantic logging Monitoring on Azure Microsoft Azure Diagnostics Storing diagnostic data using Azure storage Using the Azure portal Defining an Azure storage account Azure storage schema for diagnostic data Introduction to Application Insights Monitoring our FlixOne application Other microservice monitoring solutions A brief overview of the ELK stack Elasticsearch Logstash Kibana Splunk Alerting Reporting Summary Questions Further reading Chapter 8: Scaling Microservices with Azure Technical requirements Getting an overview of scalability Scaling infrastructure Vertical scaling (scaling up) Horizontal scaling (scaling out) Understanding microservice scalability The Scale Cube model of scalability Scaling of the x axis Scaling of the z axis Scaling of the y axis Characteristics of a scalable microservice Implementing scaling infrastructure Scaling virtual machines using scale sets Autoscaling Container scaling using Docker Swarm Scaling service design Data persistence model design Caching mechanism CacheCow Azure Cache for Redis Redundancy and fault tolerance Circuit breakers Closed state Open state Half-Open state Service discovery Summary Questions Further reading Chapter 9: Introduction to Reactive Microservices Technical requirements Installing Visual Studio 2019 Understanding reactive microservices Responsiveness Resilience Autonomy Message-driven – a core of reactive microservices Making code reactive Understanding event communication Security Message-level security Scalability Communication resilience Managing data Trying out the coding of reactive microservices Creating the project Communicating between the application and the database Client – coding it down Summary Questions Further reading Chapter 10: Design Patterns and Best Practices Technical requirements Installing Visual Studio 2019 The Aggregator pattern Pros and cons Best practices to be observed The problem and its solution – example in FlixOne Implementing the solution The Common folder The Controllers folder The Models folder The Persistence folder The Services folder The Shared Data microservices pattern Pros and cons of the pattern Best practices to be observed The problem and its solution – example in FlixOne Implementing the solution The Extensions folder The Models folder The Persistence folder The Controllers folder The Anti-Corruption Layer pattern Pros and cons Best practices to be observed Problem and its solution – the need for the Anti-Corruption Layer pattern Implementing the solution The BL folder The Models folder The DAL folder The Contexts folder The Repository folder The Services folder The Controllers folder Summary Further reading Chapter 11: Building a Microservice Application Technical requirements Installing Visual Studio 2019 Setting up Azure Revisiting the monolithic architecture style and SOA Introducing the strangler pattern Understanding the business needs of an application Revisiting the application Building the application Summary Chapter 12: Microservices Architecture Summary Technical requirements Understanding architectures before microservices Monolithic architecture Challenges in standardizing the .NET stack Scaling Service-oriented architecture Microservice-style architecture Messaging in microservices Understanding how monolith transitioning works Integration techniques Deployment Testing microservices Security Monitoring the application Monitoring challenges Scale Component lifespan Information visualization Understanding monitoring strategies Understanding scalability Infrastructure scaling Service design An overview of reactive microservices Building a greenfield application Scoping our services The book-listing microservice The book-searching microservice The shopping-cart microservice The order microservice User authentication Synchronous versus asynchronous The book-catalog microservice The shopping-cart microservice The order microservice The user-authentication microservice An overview of cloud-native microservices Summary Appendix Assessments Other Books You May Enjoy Index
Similar books
Hands-on Azure Cognitive Services: Applying AI and Machine Learning for Richer Applications
2021 · PDF
Hands-on Azure Cognitive Services: Applying AI and Machine Learning for Richer Applications
2021 · EPUB
Hands-on Azure Cognitive Services: Applying AI and Machine Learning for Richer Applications
2021 · PDF
Hands-On Design Patterns with C# and .NET Core
2019 · PDF
Język C# w 7 dni. Solidne podstawy programowania obiektowego
2018 · PDF
Język C# w 7 dni. Solidne podstawy programowania obiektowego
2018 · EPUB
Enterprise Integration with Mulesoft: Learn how to leverage MuleSoft to power Enterprise Integration (English Edition)
2023 · RAR
Enterprise Integration with Mulesoft: Learn how to leverage MuleSoft to power Enterprise Integration (English Edition)
2023 · PDF