0%

Book Description

Learn the essential concepts, techniques, and design patterns that will help you build scalable and maintainable distributed systems

Key Features

  • Learn to design, implement, test, and deploy your microservices
  • Understand the challenges and complexities of testing and monitoring distributed services
  • Build modular and robust microservice architectures with the latest features of C# 8 and .NET Core 3.1

Book 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 learn

  • Package, deploy, and manage microservices and containers with Azure Service Fabric
  • Use REST APIs to integrate services using a synchronous approach
  • Protect public APIs using Azure Active Directory and OAuth 2.0
  • Understand the operation and scaling of microservices using Docker and Kubernetes
  • Implement reactive microservices with Reactive Extensions
  • Discover design patterns and best practices for building enterprise-ready apps

Who 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 Contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On Microservices with C# 8 and .NET Core 3 Third Edition
  3. Dedication
  4. Packt Upsell
    1. Why subscribe?
  5. Foreword
  6. Contributors
    1. About the authors
    2. About the reviewer
    3. Packt is searching for authors like you
  7. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  8. An Introduction to Microservices
    1. Technical requirements
    2. The origin of microservices
    3. Discussing microservices
    4. Exploring monolithic architecture
      1. Service-oriented architecture
        1. Understanding services
    5. Understanding microservice architecture
      1. Messaging in microservices
        1. Synchronous messaging
        2. Asynchronous messaging
        3. Message formats
    6. Using microservices
    7. The workings of microservice architecture
    8. The advantages of microservices
    9. SOA versus microservices
    10. The prerequisites of microservice architecture
    11. Understanding the problems with the monolithic architectural style
      1. The challenges in standardizing a .NET stack
        1. Fault tolerance
      2. The scaling property of a system
        1. Vertical scaling or scale-up
        2. Horizontal scaling or scale-out
        3. Deployment challenges
        4. Organizational alignment
        5. Modularity
        6. Big database
    12. Prerequisites for microservices
      1. Functional overview of the application
        1. Solutions for the current challenges
        2. Handling deployment problems
        3. Making better monolithic applications
          1. Introducing dependency injections
          2. Database refactoring
          3. Database sharding and partitioning
          4. DevOps culture
          5. Automation
          6. Testing
          7. Versioning
          8. Deployment
    13. Identifying decomposition candidates within monolithic
      1. Important microservices advantages
        1. Technology independence
        2. Interdependency removal
        3. Alignment with business goals
        4. Cost benefits
        5. Easy scalability
        6. Security
          1. Data management
          2. Integrating monolithic applications with microservices
    14. An overview of Azure Service Fabric
    15. Summary
    16. Questions
  9. Refactoring the Monolith
    1. Technical requirements
    2. Understanding the current and new technology stack
      1. Discussion – current stack (C#, EF, and SQL Server)
        1. C# 8
        2. Entity Framework Core
        3. Visual Studio 2019
        4. Microsoft SQL Server
      2. New features in .NET Core 
      3. New features in C# 8.0
        1. Enabling support for the C# 8.0 language using Visual Studio
        2. Indices and ranges
        3. The readonly members
        4. Default interface methods
    3. The size of microservices
    4. What makes a good service?
    5. DDD and its importance for microservices
      1. Domain model design
      2. Importance for microservices
    6. Understanding the concept of seam
      1. Module interdependency
      2. Technology
      3. Team structure
      4. Databases
      5. Master data
      6. Transactions
    7. Communication between microservices
      1. The benefits of the API gateway for microservices
      2. API gateway versus API management
    8. Revisiting the FlixOne case study
      1. Prerequisites
      2. Transitioning to our product service
      3. Migrations
        1. Code migration
        2. Creating our project
        3. Adding the model
        4. Adding a repository
        5. Registering repositories
        6. Adding a product controller
        7. The ProductService API
        8. Adding EF Core support
        9. EF Core DbContext
        10. EF Core migrations
      4. Database migration
      5. Revisiting repositories and the controller
      6. Introducing ViewModel
      7. Revisiting ProductController
        1. Adding Swagger support
    9. Summary
    10. Questions
    11. Further reading
  10. Effective Communication between Services
    1. Technical requirements
    2. Understanding communication between services
      1. Styles of collaboration
    3. Learning about integration patterns
      1. The API gateway
      2. The event-driven pattern
      3. Event-sourcing pattern
      4. Eventual consistency pattern
      5. Compensating transactions
      6. Competing consumers
    4. Understanding Azure Service Fabric
      1. Service Fabric architecture
      2. Discussing the orchestrator
      3. Service Fabric programming models overview
      4. Implementing information on competing consumers
        1. Azure Service Bus
        2. Azure message queues
      5. Implementing information on Service Fabric
        1. Prerequisites
        2. Sending messages to the queue
        3. Adding configuration settings
        4. Receiving messages from the queue
      6. Implementing information on containers
      7. Containers on Service Fabric
        1. Prerequisites
        2. Execution
    5. Microservices with Kubernetes
      1. An overview of Azure Kubernetes Service (AKS)
        1. Important concepts
        2. Ease of deploying and managing microservices
        3. The sidecar pattern
          1. When to use the sidecar pattern
          2. Best practices to be observed
        4. The ambassador pattern
          1. When to use the ambassador pattern
          2. Best practices to be observed
    6. Considering IoT when building microservices apps
      1. An overview of IoT Hub
      2. An overview of IoT Edge
    7. Summary
    8. Questions
    9. Further reading
  11. Testing Microservices with the Microsoft Unit Testing Framework
    1. Technical requirements
    2. Testing the microservice application
      1. Handling testing challenges with microservices
    3. Understanding testing strategies
    4. Testing pyramid
    5. Types of microservice tests
      1. Unit testing
      2. Component (service) testing
      3. Integration testing
      4. Contract testing
        1. Consumer-driven contracts
          1. How to implement a consumer-driven test
          2. How Pact-net-core helps us achieve our goal
      5. Performance testing
      6. End-to-end (UI/functional) testing
      7. Sociable versus isolated unit tests
      8. Stubs and mocks
    6. Testing the microservice application
      1. Getting ready for the test project
      2. Unit tests
      3. Integration tests
    7. Summary
    8. Questions
    9. Further reading
  12. Deploying Microservices with Docker
    1. Technical requirements
    2. Monolithic application deployment challenges
    3. Understanding the deployment terminology
    4. Prerequisites for successful microservice deployments
    5. Isolation requirements for microservice deployment
    6. The need for a new deployment paradigm
    7. The way out – containers
      1. What are containers?
      2. Suitability of containers over virtual machines
      3. Transformation of the operation team's mindset 
      4. Containers are new binaries
        1. Does it work on your machine? Let's ship your machine!
    8. Introducing Docker
      1. Deploying a sample application
    9. Microservice deployment example using Docker
      1. Setting up Docker on your machine
        1. Prerequisites
      2. Creating an ASP.NET Core web application
    10. Summary
    11. Questions
    12. Further reading
  13. Securing Microservices Using Azure Active Directory
    1. Technical requirements
    2. Security in monolithic applications
    3. Security in microservices
      1. Why won't a traditional .NET auth mechanism work?
      2. JSON Web Tokens
    4. Working with OAuth 2.0
    5. Exploring OpenID Connect
    6. Understanding Azure Active Directory
    7. Microservice Auth example with OpenID Connect, OAuth 2.0, and Azure AD
      1. Registering our application with the Azure AD tenant
      2. Generating AppKey for FlixOne.BookStore.Web
      3. Configuring Visual Studio solution projects
      4. Generating client certificates on IIS Express
      5. Running both applications
    8. Managing Azure API Management as an API gateway
      1. An example of a rate limit and quota policy
    9. Understanding container security
      1. Other security best practices
    10. Summary
    11. Questions
    12. Further reading 
  14. Monitoring Microservices
    1. Technical requirements
      1. Setting up .NET Core 3.1
      2. A valid Azure account
    2. Beginning with instrumentation and telemetry
      1. Instrumentation
      2. Telemetry
    3. The need for monitoring
      1. Health monitoring
      2. Availability monitoring
      3. SLA monitoring
      4. Performance monitoring
      5. Security monitoring
      6. Auditing sensitive data and critical business transactions
      7. End user monitoring
      8. Troubleshooting system failures
    4. Understanding the monitoring challenges
      1. Scaling issues
      2. DevOps mindset
      3. Data flow visualization
      4. Testing monitoring tools
    5. Working on monitoring strategies
      1. Application/system monitoring
      2. Real user monitoring
      3. Semantic monitoring and synthetic transactions
      4. Profiling
      5. Endpoint monitoring
    6. Understanding logging
      1. Logging challenges
      2. Logging strategies
        1. Centralized logging
        2. Using a correlation ID in logging
        3. Semantic logging
    7. Monitoring on Azure
      1. Microsoft Azure Diagnostics
      2. Storing diagnostic data using Azure storage
        1. Using the Azure portal
        2. Defining an Azure storage account
        3. Azure storage schema for diagnostic data
      3. Introduction to Application Insights
    8. Monitoring our FlixOne application
    9. Other microservice monitoring solutions
      1. A brief overview of the ELK stack
        1. Elasticsearch
        2. Logstash
        3. Kibana
      2. Splunk
        1. Alerting
        2. Reporting
    10. Summary
    11. Questions
    12. Further reading
  15. Scaling Microservices with Azure
    1. Technical requirements
    2. Getting an overview of scalability
    3. Scaling infrastructure
      1. Vertical scaling (scaling up)
      2. Horizontal scaling (scaling out)
    4. Understanding microservice scalability
      1. The Scale Cube model of scalability
        1. Scaling of the x axis
        2. Scaling of the z axis
        3. Scaling of the y axis 
      2. Characteristics of a scalable microservice
    5. Implementing scaling infrastructure
      1. Scaling virtual machines using scale sets
      2. Autoscaling
      3. Container scaling using Docker Swarm
    6. Scaling service design
      1. Data persistence model design
      2. Caching mechanism
        1. CacheCow
        2. Azure Cache for Redis
      3. Redundancy and fault tolerance
        1. Circuit breakers
          1. Closed state
          2. Open state
          3. Half-Open state
        2. Service discovery
    7. Summary
    8. Questions
    9. Further reading
  16. Introduction to Reactive Microservices
    1. Technical requirements
      1. Installing Visual Studio 2019
    2. Understanding reactive microservices
      1. Responsiveness
      2. Resilience
      3. Autonomy
      4. Message-driven – a core of reactive microservices
    3. Making code reactive
    4. Understanding event communication
      1. Security
        1. Message-level security
      2. Scalability
      3. Communication resilience
    5. Managing data
    6. Trying out the coding of reactive microservices
      1. Creating the project
        1. Communicating between the application and the database
      2. Client – coding it down
    7. Summary
    8. Questions
    9. Further reading
  17. Design Patterns and Best Practices
    1. Technical requirements
      1. Installing Visual Studio 2019
    2. The Aggregator pattern
      1. Pros and cons
      2. Best practices to be observed
      3. The problem and its solution – example in FlixOne
      4. Implementing the solution
        1. The Common folder
        2. The Controllers folder
        3. The Models folder 
        4. The Persistence folder
        5. The Services folder
    3. The Shared Data microservices pattern
      1. Pros and cons of the pattern
      2. Best practices to be observed
      3. The problem and its solution – example in FlixOne
      4. Implementing the solution
        1. The Extensions folder
        2. The Models folder
        3. The Persistence folder
        4. The Controllers folder
    4. The Anti-Corruption Layer pattern
      1. Pros and cons
      2. Best practices to be observed
      3. Problem and its solution – the need for the Anti-Corruption Layer pattern
      4. Implementing the solution
        1. The BL folder
          1. The Models folder
        2. The DAL folder
          1. The Contexts folder
          2. The Repository folder
        3. The Services folder
          1. The Controllers folder
    5. Summary
    6. Further reading
  18. Building a Microservice Application
    1. Technical requirements
      1. Installing Visual Studio 2019
      2. Setting up Azure
    2. Revisiting the monolithic architecture style and SOA
    3. Introducing the strangler pattern
    4. Understanding the business needs of an application
    5. Revisiting the application
    6. Building the application
    7. Summary
  19. Microservices Architecture Summary
    1. Technical requirements
    2. Understanding architectures before microservices
      1. Monolithic architecture
      2. Challenges in standardizing the .NET stack
      3. Scaling
      4. Service-oriented architecture 
      5. Microservice-style architecture
        1. Messaging in microservices
    3. Understanding how monolith transitioning works
      1. Integration techniques
      2. Deployment
      3. Testing microservices
      4. Security
    4. Monitoring the application
      1. Monitoring challenges
        1. Scale
        2. Component lifespan
        3. Information visualization
    5. Understanding monitoring strategies
    6. Understanding scalability
      1. Infrastructure scaling
      2. Service design
    7. An overview of reactive microservices
    8. Building a greenfield application
      1. Scoping our services
        1. The book-listing microservice
        2. The book-searching microservice
        3. The shopping-cart microservice
        4. The order microservice
        5. User authentication
        6. Synchronous versus asynchronous
      2. The book-catalog microservice
      3. The shopping-cart microservice
      4. The order microservice
      5. The user-authentication microservice
    9. An overview of cloud-native microservices
    10. Summary
  20. Appendix
    1. API Gateway pattern
      1. Adapting the API Gateway on the basis of its pros and cons
      2. Preferred practices while implementing the API Gateway
      3. Implementing the API Gateway
        1. Preferring Ocelot
        2. Initial steps
        3. Aggregation
        4. Logging
        5. Protecting services from attacks by defining rate-limits
        6. Implementing security services
    2. Backends for Frontends pattern
  21. Assessments
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
    9. Chapter 9
  22. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
18.223.124.244