Building Microservices with .NET Core 2.0 - Second Edition

Book description

Architect your .NET applications by breaking them into really small pieces - microservices -using this practical, example-based guide.

About This Book

  • Start your microservices journey and get a broader perspective on microservices development using C# 7.0 with .NET Core 2.0
  • Build, deploy, and test microservices using ASP.Net Core, ASP.NET Core API, and Microsoft Azure Cloud
  • Get the basics of reactive microservices

Who This Book Is For

This book is for .NET Core developers who want to learn and understand the microservices architecture and implement it in their .NET Core applications. It's ideal for developers who are completely new to microservices or just have a theoretical understanding of this architectural approach and want to gain a practical perspective in order to better manage application complexities.

What You Will Learn

  • Get acquainted with Microsoft Azure Service Fabric
  • Compare microservices with monolithic applications and SOA
  • Learn Docker and Azure API management
  • Define a service interface and implement APIs using ASP.NET Core 2.0
  • Integrate services using a synchronous approach via RESTful APIs with ASP.NET Core 2.0
  • Implement microservices security using Azure Active Directory, OpenID Connect, and OAuth 2.0
  • Understand the operation and scaling of microservices in .NET Core 2.0
  • Understand the key features of reactive microservices and implement them using reactive extensions

In Detail

The microservices architectural style promotes the development of complex applications as a suite of small services based on business capabilities. This book will help you identify the appropriate service boundaries within your business. We'll start by looking at what microservices are and their main characteristics.

Moving forward, you will be introduced to real-life application scenarios; after assessing the current issues, we will begin the journey of transforming this application by splitting it into a suite of microservices using C# 7.0 with .NET Core 2.0. You will identify service boundaries, split the application into multiple microservices, and define service contracts. You will find out how to configure, deploy, and monitor microservices, and configure scaling to allow the application to quickly adapt to increased demand in the future.

With an introduction to reactive microservices, you'll strategically gain further value to keep your code base simple, focusing on what is more important rather than on messy asynchronous calls.

Style and approach

This guide serves as a stepping stone that helps .NET Core developers in their microservices architecture. This book provides just enough theory to understand the concepts and apply the examples.

Table of contents

  1. Title Page
    1. Second Edition
  2. Copyright
    1. Building Microservices with .NET Core 2.0
      1. Second Edition
  3. Credits
  4. Foreword
  5. About the Author
  6. About the Reviewer
  7. www.PacktPub.com
    1. Why subscribe?
  8. Customer Feedback
  9. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Downloading the color images of this book
      3. Errata
      4. Piracy
      5. Questions
  10. An Introduction to Microservices
    1. Origin of microservices
    2. Discussing microservices
    3. Monolithic architecture
      1. Service-Oriented architecture
        1. What is a service?
    4. Understanding the microservice architecture
      1. Messaging in microservices
        1. Synchronous messaging
        2. Asynchronous messaging
        3. Message formats
    5. Why should we use microservices?
    6. How does the microservice architecture work?
    7. Advantages of microservices
    8. SOA versus microservices
    9. Prerequisites of the microservice architecture
    10. Understanding the problems with the monolithic architectural style
      1. Challenges in standardizing a .NET stack
        1. Fault tolerance
      2. Scaling
        1. Vertical scaling or scale up
        2. Horizontal scaling or scale out
        3. Deployment challenges
        4. Organizational alignment
        5. Modularity
        6. Big database
    11. Prerequisites for microservices
      1. Functional overview of the application
        1. Solutions for current challenges
        2. Handling deployment problems
        3. Making much 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
    12. 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
    13. Overview of Azure Service Fabric
    14. Summary
  11. Implementing Microservices
    1. Introduction
      1. C# 7.0
      2. Entity Framework Core
      3. Visual Studio 2017
      4. Microsoft SQLServer
    2. Size of microservices
    3. What makes a good service?
    4. DDD and its importance for microservices
      1. Domain model design
        1. Importance for microservices
    5. The concept of seam
      1. Module interdependency
      2. Technology
      3. Team structure
      4. Database
      5. Master data
      6. Transaction
    6. Communication between microservices
      1. Benefits of the API gateway for microservices
      2. API gateway versus API management
    7. Revisiting the Flix One 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 the 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 the product controller
        1. Adding Swagger support
    8. Summary
  12. Integration Techniques and Microservices
    1. Communication between services
      1. Styles of collaboration
    2. Integration patterns
      1. The API gateway
      2. The event-driven pattern
      3. Event sourcing
      4. Eventual consistency
      5. Compensating transactions
      6. Competing consumers
      7. Azure Service Bus
      8. Azure queues
      9. Implementing an Azure Service Bus queue
        1. Prerequisites
        2. Sending messages to the queue
      10. Adding configuration settings
        1. Receiving messages from the queue
    3. Summary
  13. Testing Microservices
    1. How to test microservices
      1. Handling challenges
    2. Testing strategies (testing approach)
    3. Testing pyramid
    4. Types of microservice tests
      1. Unit testing
      2. Component (service) testing
      3. Integration testing
      4. Contract testing
        1. Consumer-driven contracts
        2. How to implement a consumer-driven test
        3. 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
    5. Tests in action
      1. Getting ready for the test project
      2. Unit tests
      3. Integration tests
      4. Consumer-driven contract tests
    6. Summary
  14. Deploying Microservices
    1. Monolithic application deployment challenges
    2. Understanding the deployment terminology
    3. Prerequisites for successful microservice deployments
    4. Isolation requirements for microservice deployment
    5. Need for a new deployment paradigm
    6. 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!
    7. Introducing Docker
      1. Microservice deployment with Docker overview
      2. Microservice deployment example using Docker
        1. Setting up Docker on your machine
          1. Prerequisites
        2. Creating an ASP.NET Core web application
    8. Summary
  15. Securing Microservices
    1. Security in monolithic applications
    2. Security in microservices
      1. Why won't a traditional .NET auth mechanism work?
      2. JSON Web Tokens
      3. What is OAuth 2.0?
      4. What is OpenID Connect?
      5. Azure Active Directory
      6. Microservice Auth example with OpenID Connect, OAuth 2.0, and Azure AD
        1. Registration of TodoListService and TodoListWebApp with Azure AD tenant
        2. Generation of AppKey for TodoListWebApp
        3. Configuring Visual Studio solution projects
        4. Generate client certificates on IIS Express
        5. Running both the applications
      7. Azure API management as an API gateway
        1. Rate limit and quota policy example
      8. Container security
      9. Other security best practices
    3. Summary
  16. Monitoring Microservices
    1. Instrumentation and telemetry
      1. Instrumentation
      2. Telemetry
    2. The need for monitoring
      1. Health monitoring
      2. Availability monitoring
      3. Performance monitoring
      4. Security monitoring
      5. SLA monitoring
      6. Auditing sensitive data and critical business transactions
      7. End user monitoring
      8. Troubleshooting system failures
    3. Monitoring challenges
      1. Scale
      2. DevOps mindset
      3. Data flow visualization
      4. Testing of monitoring tools
    4. Monitoring strategies
      1. Application/system monitoring
      2. Real user monitoring
      3. Semantic monitoring and synthetic transactions
      4. Profiling
      5. Endpoint monitoring
    5. Logging
      1. Logging challenges
      2. Logging strategies
        1. Centralized logging
        2. Using a correlation ID in logging
        3. Semantic logging
    6. Monitoring in Azure Cloud
      1. Microsoft Azure Diagnostics
      2. Storing diagnostic data using Azure storage
        1. Using Azure portal
        2. Specifying a storage account
        3. Azure storage schema for diagnostic data
      3. Introduction of Application Insights
    7. Other microservice monitoring solutions
      1. A brief overview of the ELK stack
        1. Elasticsearch
        2. Logstash
        3. Kibana
      2. Splunk
        1. Alerting
        2. Reporting
    8. Summary
  17. Scaling Microservices
    1. Scalability overview
    2. Scaling infrastructure
      1. Vertical scaling (scaling up)
      2. Horizontal scaling (scaling out)
    3. Microservice scalability
      1. Scale Cube model of scalability
        1. Scaling of x axis
        2. Scaling of z axis
        3. Scaling of y axis
      2. Characteristics of a scalable microservice
    4. Scaling the infrastructure
      1. Scaling virtual machines using scale sets
      2. Auto Scaling
      3. Container scaling using Docker Swarm
    5. Scaling service design
      1. Data persistence model design
      2. Caching mechanism
        1. CacheCow
        2. Azure Redis Cache
      3. Redundancy and fault tolerance
        1. Circuit breakers
          1. Closed state
          2. Open state
          3. Half-Open state
        2. Service discovery
    6. Summary
  18. Introduction to Reactive Microservices
    1. Understanding reactive microservices
      1. Responsiveness
      2. Resilience
      3. Autonomous
      4. Message-driven: a core of reactive microservices
    2. Let's make code reactive
    3. Event communication
      1. Security
        1. Message-level security
      2. Scalability
      3. Communication resilience
    4. Managing data
    5. The microservice ecosystem
    6. Coding reactive microservices
      1. Creating the project
        1. Communication between the application and the database
      2. Client – coding it down
    7. Summary
  19. Creating a Complete Microservice Solution
    1. Architectures before microservices
      1. The monolithic architecture
      2. Challenges in standardizing the .NET stack
      3. Scaling
      4. Service-oriented architecture
      5. Microservice-styled architecture
        1. Messaging in microservices
    2. Monolith transitioning
      1. Integration techniques
      2. Deployment
      3. Testing microservices
      4. Security
    3. Monitoring
      1. Monitoring challenges
        1. Scale
        2. Component lifespan
        3. Information visualization
    4. Monitoring strategies
      1. Scalability
        1. Infrastructure scaling
        2. Service design
    5. Reactive microservices
    6. 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
    7. Summary

Product information

  • Title: Building Microservices with .NET Core 2.0 - Second Edition
  • Author(s): Gaurav Aroraa
  • Release date: December 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781788393331