Microservices in .NET, Second Edition
eBook - ePub

Microservices in .NET, Second Edition

  1. 328 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Microservices in .NET, Second Edition

About this book

Microservices in.NET, Second Edition teaches you to build and deploy microservices using ASP.NET and Azure services. Summary
In Microservices in.NET, Second Edition you will learn how to: Build scalable microservices that are reliable in production
Optimize microservices for continuous delivery
Design event-based collaboration between microservices
Deploy microservices to Kubernetes
Set up Kubernetes in Azure Microservices in.NET, Second Edition is a comprehensive guide to building microservice applications using the.NET stack. After a crystal-clear introduction to the microservices architectural style, it teaches you practical microservices development skills using ASP.NET. This second edition of the bestselling original has been revised with up-to-date tools for the.NET ecosystem, and more new coverage of scoping microservices and deploying to Kubernetes. Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the technology
Microservice architectures connect independent components that must work together as a system. Integrating new technologies like Docker and Kubernetes with Microsoft's familiar ASP.NET framework and Azure cloud platform enables.NET developers to create and manage microservices efficiently. About the book
Microservices in.NET, Second Edition teaches you to build and deploy microservices using ASP.NET and Azure services. It lays out microservice architecture simply, and then guides you through several real-world projects, such as building an ecommerce shopping cart. In this fully revised edition, you'll learn about scoping microservices, deploying to Kubernetes, and operations concerns like monitoring, logging, and security. What's inside Optimize microservices for continuous delivery
Design event-based collaboration between microservices
Deploy microservices to Kubernetes
Set up Kubernetes in AzureAbout the reader
For C# developers. No experience with microservices required. About the author
Christian Horsdal is an independent consultant with more than 20 years of experience building projects from large-scale microservice systems to tiny embedded systems. Table of Contents
PART 1 GETTING STARTED WITH MICROSERVICES
1 Microservices at a glance
2 A basic shopping cart microservice
3 Deploying a microservice to Kubernetes
PART 2 BUILDING MICROSERVICES
4 Identifying and scoping microservices
5 Microservice collaboration
6 Data ownership and data storage
7 Designing for robustness
8 Writing tests for microservices
PART 3 HANDLING CROSS-CUTTING CONCERNS: BUILDING A REUSABLE MICROSERVICE PLATFORM
9 Cross-cutting concerns: Monitoring and logging
10 Securing microservice-to-microservice communication
11 Building a reusable microservice platform
PART 4 BUILDING APPLICATIONS
12 Creating applications over microservices

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Microservices in .NET, Second Edition by Christian Horsdal Gammelgaard in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming Languages. We have over one million books available in our catalogue for you to explore.

Information

Part 1 Getting started with microservices

This first part explains what microservices are and why you should care. I’ll begin by discussing six characteristics you can use to recognize and guide your design of microservices. Along the way, we’ll look at the benefits and costs of microservices.
Toward the end of chapter 1, I’ll give you a whirlwind tour of the technology stack used throughout the book; the stack consists of .NET, ASP.NET, and the ASP.NET MVC web framework. Chapter 2 moves on to an example of building your first microservice. You’ll see how little is needed to get started, and begin to see ASP.NETs strength. Chapter 3 shows how to containerize the microservice from chapter 2 and how to deploy it to Kubernetes in Azure.
By the end of part 1, you will have your first microservice running in the cloud.

1 Microservices at a glance

This chapter covers
  • Understanding microservices and their core characteristics
  • Examining the benefits and drawbacks of microservices
  • An example of microservices working in concert to serve a user request
  • Using ASP.NET for a simple application
In this chapter, I’ll explain what microservices are and demonstrate why they’re interesting. We’ll also look at the six characteristics of a microservice. Finally, I’ll introduce you to the most important technologies we’ll use in this book: ASP.NET and ASP.NET MVC.

1.1 What is a microservice?

A microservice is a service with one, and only one, very narrowly focused capability that a remote API exposes to the rest of the system. For example, think of a system for managing a warehouse. If you broke down its capabilities, you might come up with the following list:
  • Receive stock arriving at the warehouse.
  • Determine where new stock should be stored.
  • Calculate placement routes inside the warehouse for putting stock into the right storage units.
  • Assign placement routes to warehouse employees.
  • Receive orders.
  • Calculate pick routes in the warehouse for a set of orders.
  • Assign pick routes to warehouse employees.
Let’s consider how the first of these capabilities—receive stock arriving at the warehouse—would be implemented as a microservice. We’ll call it the Receive Stock microservice:
  1. A request to receive and log new stock arrives over HTTP. This might come from another microservice or perhaps from a web page that a foreman uses to register stock arrivals. The responsibility of Receive Stock microservice is to handle such requests by validating the request and correctly registering the new stock in a data store.
  2. A response is sent back from the Receive Stock microservice to acknowledge that the stock has been received.
Figure 1.1 shows the Receive Stock microservice receiving a request from another collaborating microservice.
CH01_F01_Horsdal3

Figure 1.1 The Receive Stock microservice exposes an API for use when new stock arrives. Other microservices can call that API, as indicated by the arrow. The Receive Stock microservice is responsible for registering all received stock in a data store.
Each capability in the system, no matter how small, is implemented as an individual microservice. Every microservice in a system
  • Runs in its own separate process
  • Can be deployed on its own, independently of the other microservices
  • Has its own dedicated data store
  • Collaborates with other microservices to complete its own action
It’s also important to note that a microservice doesn’t need to be written in the same programming language (C#, Java, Erlang, Javascript, etc.) as the one it collaborates with. They just need to know how to communicate with each other. Some may communicate via queues, a service bus, gRPC, or GraphQL, for instance, depending on system requirements; but often, microservices do communicate over HTTP.
NOTE This book focuses on implementing microservices in .NET using C# and ASP.NET. The microservices I’ll show you are small, tightly focused ASP.NET applications that collaborate over HTTP.
NOTE This book focuses on collaboration over HTTP, but the principles guiding how the collaboration is designed are not specific to HTTP. I choose to use HTTP because it is ubiquitous and familiar to many developers and I want to focus more on the design principles than the technology. These principles also apply with different technology, notably gRPC, which is gaining in popularity in the .NET space and is also a good choice.

1.2 What is a microservices architecture?

This book focuses on designing and implementing individual microservices, but it’s worth noting that the term microservices can also be used to describe an architectural style for an entire system consisting of many microservices. Microservices as an architectural style is a lightweight form of service-oriented architecture (SOA) where the services are each tightly focused on doing one thing and doing it well. A system with a microservices architecture is a distributed system with a (probably large) number of collaborating microservices.
The microservices architectural style has been quickly gaining in popularity for building and maintaining complex server-side software systems. And understandably so: microservices offer a number of potential benefits over both more traditional service-oriented approaches and monolithic architectures. Microservices, when done well, are malleable, scalable, and robust, and they allow for systems that do well on all four of the key metrics identified by Nicole Forsgren et al., Accelerate1 and the DORA state of DevOps reports,2 namely
  1. Deployment frequency
  2. Lead time for changes
  3. Time to restore service
  4. Change failure rate
This combination often proves elusive for complex software systems. Furthermore, it is, as documented by Forsgren et al., a reliable predictor of software delivery performance.
In this book you will learn how to design and implement malleable, scalable, and robust microservices that form systems that deliver on all four of these key metrics.

1.2.1 Microservice characteristics

I’ve said that a microservice is ā€œa service with a very narrowly focused capability,ā€ but what exactly does that mean? Well, there’s not a broadly accepted definition in the industry of precisely what a microservice is.3 We can, however, look at what generally characterizes a microservice. I’ve found there to be six core microservice characteristics:
  • A microservice is responsible for a single capability.
  • A microservice is individually deployable.
  • A microservice consists of one or more processes.
  • A microservice owns its own data store.
  • A small team can maintain a few handfuls of microservices.
  • A microservice is replaceable.
This list of characteristics should help you recognize a well-formed microservice when you see one, and...

Table of contents

  1. Microservices in .NET
  2. Copyright
  3. Praise for the first edition
  4. contents
  5. front matter
  6. Part 1 Getting started with microservices
  7. 1 Microservices at a glance
  8. 2 A basic shopping cart microservice
  9. 3 Deploying a microservice to Kubernetes
  10. Part 2 Building microservices
  11. 4 Identifying and scoping microservices
  12. 5 Microservice collaboration
  13. 6 Data ownership and data storage
  14. 7 Designing for robustness
  15. 8 Writing tests for microservices
  16. Part 3 Handling cross-cutting concerns: Building a reusable microservice platform
  17. 9 Cross-cutting concerns: Monitoring and logging
  18. 10 Securing microservice-to-microservice communication
  19. 11 Building a reusable microservice platform
  20. Part 4 Building applications
  21. 12 Creating applications over microservices
  22. appendix A. Development environment setup
  23. further reading
  24. index
  25. inside back cover