Chapter 8. Service Discovery

Up to this point in the book, we have discussed the concepts and code required to build basic microservices, configure and consume backing services, talk to databases, and build web applications. We’ve even spent a great deal of time and effort discussing the Event Sourcing and CQRS patterns and how they can be applied to build massive-scale applications out of a suite of related microservices.

In this chapter we’re going to continue to build on the idea that we don’t simply build single services in a vacuum; that everything we build is consumed by or consumes other services.

To keep the configuration and management of large numbers of services as simple as possible, I’m going to introduce the concept of service discovery.

Refresher on Cloud-Native Factors

Before we get into the details of service discovery, I thought it would be worth a quick refresher on some of the original twelve factors of cloud-native applications that are important and relevant to the sample we’ll be building: external configuration and backing services.

External Configuration

As discussed throughout this book and on the original Twelve-Factor App website, properly handling configuration is key to building applications that thrive in the cloud.

Let’s start with a review of what it looks like when we aren’t properly externalizing our configuration. How many times have you seen (or written) code that looks like this in your application?

using (var httpClient = new HttpClient ...

Get Building Microservices with ASP.NET Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.