Spring Cloud, Spring Boot and Netflix OSS

Spencer Gibb, Dave Syer, 2015

Authors

Outline

  • Define microservices
  • Outline some distributed system problems
  • Introduce Netflix OSS and its integration with Spring Boot
  • Spring Cloud demos

What are microservices?

  • Not monolithic :-)
  • Smaller units of a larger system
  • Runs in its own process
  • Lightweight communication protocols
  • Single Responsibility Principle
  • The UNIX way

Spring Boot

It needs to be super easy to implement and update a service:

@RestController
class ThisWillActuallyRun {
    @RequestMapping("/")
    String home() {
        Hello World!
    }
}

and you don’t get much more "micro" than that.

Cloud Foundry

Deploying services needs to be simple and reproducible

$ cf push app -p app.groovy

and you don’t get much more convenient than that.

(Same argument for other PaaS solutions)

Example Distributed System: Minified

Example Distributed System: Minified

No Man (Microservice) is an Island

It’s excellent to be able to implement a microservice really easily (Spring Boot), but building a system that way surfaces "non-functional" requirements that you otherwise didn’t have.

There are laws of physics that make some problems unsolvable (consistency, latency), but brittleness and manageability can be addressed with generic, boiler plate patterns.

Emergent features of micro-services systems

Coordination of distributed systems leads to boiler plate patterns

  • Distributed/versioned configuration
  • Service registration and discovery
  • Routing
  • Service-to-service calls
  • Load balancing
  • Circuit Breaker
  • Asynchronous patterns
  • Distributed messaging

Spring IO Platform

spring-io-tree

Example: Coordination Boiler Plate

customer-stores-system

Netflix OSS

  • Eureka
  • Hystrix & Turbine
  • Ribbon
  • Feign
  • Zuul
  • Archaius
  • Curator - see Spring Cloud Zookeeper
  • Asgaard - see Spinnaker (soon)
  • …​

Example: Spring Cloud and Netflix

customer-stores

Configuration Server

  • Pluggable source
  • Git implementation
  • Versioned
  • Rollback-able
  • Configuration client auto-configured via starter

Discovery: Eureka

  • Service Registration Server
  • Highly Available
  • In AWS terms, multi Availability Zone and Region aware

Circuit Breaker: Hystrix

  • latency and fault tolerance
  • isolates access to other services
  • stops cascading failures
  • enables resilience
  • circuit breaker pattern
  • dashboard

Hystrix Observable

@HystrixCommand(fallbackMethod="getDefaultMessage")
public String getMessage() {
  return restTemplate.getForObject(/*...*/);
}

public String getDefaultMessage() {
  return "Hello World Default";
}

// somewhere else
helloService.getMessage();

Circuit Breaker Metrics

  • Via actuator /metrics
  • Server side event stream /hystrix.stream
  • Dashboard app via @EnableHystrixDashboard
  • Aggregation via Spring Cloud Turbine

Routing: Zuul

  • JVM based router and filter
  • Similar routing role as httpd, nginx, or CF go router
  • Fully programmable rules and filters
  • Groovy
  • Java
  • Any JVM language

Spring Cloud Zuul Proxy

  • Store routing rules in config server zuul.proxy.route.customers: /customers
  • Uses Hystrix→Ribbon→Eureka to forward requests to appropriate service
@EnableZuulProxy
@Controller
class Application {
}
  • Can be used as "sidecar" (or standalone edge server) via @EnableSidecar

Developer Experience

As a microservice developer, I want to write code and run it locally, but have a hight confidence that it will work in the target system.

  • Stubbing and contract-driven development
  • Remote debugging, e.g. Spring Boot live reload
  • Register local app with remote service catalog

/