Preface

Hello there! We are here to explore design and development patterns that we can leverage when building a microservice application with .NET. Microservice architecture involves separating a potentially complex application into smaller, more maintainable services that must work together. Essentially, we take one big application and break it down into smaller parts.

This approach introduces a fresh crop of complexities in the application’s design since these now separate services need to collaborate to deliver a unified experience to the end user. As such, we need to understand the various drawbacks of this architectural approach and strategize on how we can address the various concerns.

We will focus on using .NET, given that Microsoft has a proven track record of releasing and supporting top-notch tooling and support for the most recent technologies that allow us to develop cutting-edge solutions. Some of the reasons we focus on development with .NET are as follows:

  • Well maintained: Microsoft is constantly pushing the boundaries and introducing new ways to accomplish old things and new ways to implement solutions and increase productivity. It is a well-maintained, supported, and documented ecosystem.
  • Performance: .NET increases its performance with each new release. Microservices must be as performant and responsive as possible to ensure that the end user’s experience is as clean as possible.
  • Cross-platform: .NET Core is cross-platform and can be deployed on virtually any technology stack. This reduces the limitations surrounding deploying and supporting services written using .NET technology.
  • Support for various technologies: Each problem has a technology that helps us to implement a solution. .NET has support for many technologies, making it a great candidate for universal development needs.

We want to ensure that we understand the possibilities and strategies needed while developing an application based on microservices architecture. We will review the theory behind each problem and then explore the potential solutions and technologies that help us to implement the best possible solution to our challenges while developing a solution.

Who this book is for

This book is designed for .NET developers who wish to demystify the various moving parts of microservices architecture. To get the most out of the book, you should ideally fit into one of these categories:

  • Team leads: Leaders who need to understand the various moving parts and the theory behind design decisions that need to be made
  • Senior developers: Developers who need to appreciate how to guide the development efforts and implement complex blocks of code
  • Intermediate .NET developers: .NET developers who have a working knowledge of the .NET ecosystem and want to dig deeper into developing more complex solutions

The overall content of this book will assist you in understanding the dynamics of microservices application design and assist you in reaching the next level of development.

What this book covers

Chapter 1, Introduction to Microservices the Big Picture, looks at microservice architecture at a high level and seeks to understand some of the early problems we might encounter and explores design patterns that address them.

Chapter 2, Working with the Aggregator Pattern, explores how domain-driven design and the aggregate pattern lay the foundation for scoping requirements and the foundation of microservice design.

Chapter 3, Synchronous Communication between Microservices, explores how we make microservices communicate synchronously and the potential drawbacks of this method.

Chapter 4, Asynchronous Communication between Microservices, looks at asynchronous communication between services, which allows us to send data and move along, regardless of the availability or potential long runtime of the other microservices being called.

Chapter 5, Working with the CQRS Pattern, explores the CQRS pattern and why it is useful in microservices development.

Chapter 6, Applying Event Sourcing Patterns, discusses the intricacies of event sourcing and how we can implement this to ensure that our data between services stays in sync.

Chapter 7, Handling Data for Each Microservice with Database per Service Pattern, covers the best practices surrounding implementing different databases in different services.

Chapter 8, Implement Transactions across Microservices Using the Saga Pattern, explores the Saga pattern and how it helps us implement transactions across our microservices.

Chapter 9, Building Resilient Microservices, reviews implementing retry and exit strategy logic for more resilient communication between services.

Chapter 10, Performing Health Checks on Your Services, reviews how we can implement health checks in our ASP.NET Core APIs and why they are essential.

Chapter 11, Implementing API and BFF Gateway Patterns, dives into implementing API gateways, the backed for frontend pattern, and how they help us to create a robust microservices application.

Chapter 12, Securing Microservices with Bearer Tokens, reviews how bearer tokens can secure communications with each service.

Chapter 13, Microservice Container Hosting, explores containerization and how we can leverage containers to efficiently host our microservices.

Chapter 14, Implementing Centralized Logging for Microservices, explores the steps and best practices for aggregating logs from several services into one viewing area.

Chapter 15, Wrapping It All Up, discusses the key points from each chapter and highlights how each plays a role in developing a microservices application.

To get the most out of this book

You will need knowledge of API development using ASP.NET Core and basic database development knowledge. This book is best suited for intermediate-level developers looking to improve their understanding of development design patterns.

Software/hardware covered in the book

Operating system requirements

ASP.NET Core 6/7

Windows, macOS, or Linux

C# 9/10

Windows, macOS, or Linux

Docker

Windows, macOS, or Linux

Most examples are shown using NuGet package manager commands and Visual Studio 2022. These commands can be translated into dotnet CLI commands, which can be used on any operating system and with alternative IDEs to Visual Studio.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Microservices-Design-Patterns-in-.NET. If there’s an update to the code, it will be updated in the GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://packt.link/dD3Jv.

Conventions used

There are several text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, commands, and keywords. Here is an example: “As it stands, our CreateAppointmentHandler will handle everything that is needed in the situation.”

A block of code is set as follows:

public class AppointmentCreated : IDomainEvent
    {
        public Appointment { get; set; }
        public DateTime ActionDate { get; private set; }

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “Select System info from the Administration panel.”

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Share Your Thoughts

Once you’ve read Microservices Design Patterns in .NET, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

Download a free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere?

Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily

Follow these simple steps to get the benefits:

  1. Scan the QR code or visit the link below

https://packt.link/free-ebook/9781804610305

  1. Submit your proof of purchase
  2. That’s it! We’ll send your free PDF and other benefits to your email directly
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.71.6