Dedicated to my son Ayaan
Table of contents
Module 1: Course Overview
The cloud, or cloud computing, is truly changing the way we, as developers, think about design and develop software. And that's where Spring Cloud comes in. Spring Cloud helps you take full advantage of these new paradigms by bringing together the best of Spring Boot with proven cloud strategies to help you design and develop cloud-native applications. Some of the major topics we'll cover include service discovery using Spring Cloud and Netflix Eureka, distributed configuration using Spring Cloud Config Server, client-side load balancing using Spring Cloud and Netflix Ribbon, intelligent routing via a gateway service using Spring Cloud and Netflix Zuul, and fault tolerance using Spring Cloud and Netflix Hystrix. By the end of this book, you'll know how to build applications that take full advantage of the cloud. Before beginning the book, you should be familiar with Java, Spring Boot, and have at least an introductory level understanding of microservices.
Module 2: Getting Familiar with Spring Cloud
The Infamous Cloud
I'm sure you've heard of this infamous thing called the cloud as it's often hyped as this game changer or the sort of magical solution to everything. It'll solve all your problems. And with so many things to learn these days, it's hard not to ignore a lot of that and just kind of brush it off as clever marketing. But now companies and enterprises are finally starting to truly embrace the cloud, and some of that hype is actually becoming a reality. And it's more often the norm to see enterprises and companies using the cloud than it is the exception. As software engineers, I think we have some really exciting times ahead of us. Cloud computing, or the cloud, is really changing the way that we build software. We're moving from using these centralized monoliths to applications which are distributed and use microservices. And not only is the software changing, but the hardware is changing as well. We're moving from this managed and finite resource to this infinite and on demand and self-service resource.
New Challenges with the Cloud
With the cloud, there comes these new challenges. We have to think differently. Things are not quite as static as we're used to, and we can't just design and architect and use the same principles or techniques that we're used to. The cloud is this elastic and ephemeral thing. Things can grow and shrink and appear and disappear at any given time. So we have to consider that the cloud is this ever-changing and constantly evolving thing, whereas we may be used to something that is a bit more static. We also can't just move our existing applications to the cloud and expect them to be automatically cloud enabled. This is often referred to as the lift and shift migration. And sure we're going to get some benefits by moving to the cloud, but we're not fully utilizing the cloud. In order to fully utilize the cloud, it requires change. And that's where Spring Cloud helps. Spring Cloud helps you build cloud-native applications. Now, you're probably asking what is a cloud-native application? Well, a cloud-native application means that your application was specifically built and engineered for the cloud. It means your application fully utilizes all of the cloud computing paradigms. Spring Cloud itself is not actually a framework. Loosely speaking, Spring Cloud is used to describe a number of projects that all fall under the same umbrella. In this book, we'll focus on the fundamentals, which is Spring Cloud Config and Spring Cloud Netflix.
Your Focus for the book
- Service Discovery
- Distributed
- Configuration
- Intelligent Routing
- Client-side Load Balancing
- Circuit Breaker
We're going to specifically target a number of key areas. First, we're going to look at service discovery. How do you dynamically find your application services in the cloud at runtime? Then, we'll move on to distributed configuration, or how to manage common or service-specific configuration in a distributed system. Then, we'll look at intelligent routing, or how to make a distributed system look as if it were a single cohesive system using Intelligent Routing. Then, we'll look at client-side load balancing, or how you distribute load among several instances of the same service. And last, we'll look at how you can use the circuit breaker pattern to build fault-tolerant applications in the cloud.
Prerequisites
- Java 8+
- Spring Boot 1.4+
- Knowledge of Microservices or SOA
Let's talk prerequisites. I assume that you have a good understanding of Java and particularly Java 8, as well as a good understanding of Spring Boot as Spring Cloud is largely built on top of Spring Boot. Last, I expect that you have at least a knowledge or an understanding of microservices or service-oriented architectures.
Java 8+
Maven 3+
Spring Tool Suite (Eclipse STS) 3.8+
Next, let's talk about what software you're going to need to be successful in this book. Of course you're going to need Java, Java 8, and you'll need Maven, at least Maven 3, in order to build the Spring Boot applications. And we're going to be doing all of our development using Spring Tool Suite, or Eclipse STS, as it's called. Make sure you have at least version 3.8.
Module 3: Finding Services Using Service Discovery
What Is Service Discovery?
- Service Discovery
- Discovering Services with Spring Cloud
- Using Eureka client and server
- Configuration
- Health & High Availability
- Dashboard
- AWS Support
In this module we'll look at how service discovery helps you locate your application services in the cloud. Let's quickly start off by talking about what this module contains, and first we're going to look at service discovery. Obviously this module's about service discovery, so we'll talk about what it is and why it's important. Then, we're going to look at how Spring Cloud implements service discovery. It uses a project from Netflix that was open sourced, it's called Eureka, and we're going to talk about the Eureka Client and the Eureka Server. Then, we'll move on to configuration, configuring the Eureka Client, the Eureka Server, and the Eureka Instance and how each of those are different and what you need to do to tweak them or configure them for your needs. Then, we'll move into health and high availability. How does the Eureka Server know when your application is down or when it's unhealthy? And how do you ensure that the Eureka Server is highly available? And then we're going to look at the Eureka Dashboard, which is a nice web UI that shows you all of your registered services, how many instances there are, and whether they're up or down. And last, we're going to finish out with how Eureka has specific support for AWS. Let's get started with the most important question, what is service discovery and why do we need it? Remember that the cloud is changing the way that we build software. We're moving from building these single large applications and instead breaking them up into smaller and smaller pieces called services. And each of those individual services can then be deployed and scaled on their own, and together, as a whole, they form the overall application. And herein lies the problem. How does one service know where another service is at, its host and its port, so that it can call it and use it? For starters, we could simply configure all of our services to know the location and the port of other services that it calls. And, depending on our needs, this actually might get us pretty far. But after a while, we'll learn that there are some problems to this approach. What if, for example, you had two instances of a particular service? So, in our example here, we have Application Service A calling Application Service B. And if we used configuration, every time we added or removed a new instance of Application Service B, we'd have to update that configuration. And, well, in our example, we only have two instances. Imagine if you had hundreds of instances. The configuration management alone would be unsustainable. Our simple configuration starts to break down even further as we move to a cloud environment. In a cloud environment, you have instances of services that can come and go in response to demand, for instance. So, for example, Application Service B starts with two instances, and consider that maybe you have this huge influx of traffic, maybe it's a flash sale on your eCommerce website, and an automated process kicks off and starts two more instances to handle all of that demand. Well, if you're using simple configuration, all of the callers of Application Service B, such as Application Service A, would not even know about the two new instances that were added in response to that demand. As far as they're concerned, their configuration says that there are only two instances that they know about. Another thing to consider is that application services will eventually fail. And regardless of the situation, whether it's a memory problem or a hardware problem, if you're using simple configuration, your services are going to continue to try to send traffic to those failed instances. For example here, we have Application Service B being called by Application Service A, and it has two instances. And if one of those instances fails, Application Service A is not going to know the better, and it's going to continue to send traffic to that failed instance. We need something that is more dynamic. The simple approach is just far too static. It's too frozen in time for our needs in the cloud. That's where service discovery comes into play.
Next page