to microservices and beyond! - yow! conferences...•microservices are not an inherently superior...
TRANSCRIPT
© Copyright 2014 Pivotal. All rights reserved.© Copyright 2014 Pivotal. All rights reserved.
To Microservices and Beyond!YOW! Conference 2014
1
Matt Stine (@mstine) - Senior Product Manager, Spring for Pivotal CF Simon Elisha (@simon_elisha) - CTO & Senior Manager, Field Engineering
© Copyright 2014 Pivotal. All rights reserved. 2
IT SEEMS THERE’S SOME HYPE…
M!CR0S3RV!C3$!!!!!
© Copyright 2014 Pivotal. All rights reserved.
DEFINE: Microservice
3
Loosely coupled service oriented architecture with bounded contexts
Adrian Cockcroft Technology Fellow, Battery Ventures Former Netflix Chief Cloud Architect
© Copyright 2014 Pivotal. All rights reserved.
DEFINE: Microservice
4
Loosely coupled service oriented architecture with bounded contexts
If every service has to be updated in concert, it’s not loosely coupled!
If you have to know about surrounding services you don’t have a bounded context.
© Copyright 2014 Pivotal. All rights reserved.
Not Monoliths
5
Relational Database
Data Access
Service
HTML JavaScript MVC
Service
Monolithic ApplicationBrowser
© Copyright 2014 Pivotal. All rights reserved. 6
Not Traditional (ESB-centric) SOA
Enterprise Service Bus
Service Service Service Service
Service Service Service Service
UI UI
© Copyright 2014 Pivotal. All rights reserved. 7
But Microservices!
© Copyright 2014 Pivotal. All rights reserved. 8
But why?
© Copyright 2014 Pivotal. All rights reserved. 9
Issues We’ll Confront•Microservices are not an inherently superior architecture.
•We’re still building big systems from smaller things.
• Just like Docker won’t save the world, neither will microservices. They’re not free.
• You absolutely cannot forget about data.
• Let’s begin!
© Copyright 2014 Pivotal. All rights reserved. 10
Not an end in themselves…It’s about Continuous Delivery!
© Copyright 2014 Pivotal. All rights reserved.
What is Continuous Delivery?
11
$Busin
ess
Devel
opm
ent
QA
Ope
ratio
nsCu
stom
er
© Copyright 2014 Pivotal. All rights reserved.
What is Continuous Delivery?
12
$
© Copyright 2014 Pivotal. All rights reserved. 13
Keep the Wheel Spinning!
Design Develop
Test
Customer Feedback Customer
Delivery
Analytics
© Copyright 2014 Pivotal. All rights reserved. 14
Prod Release #1
Prod Release #2
Prod Release #3
Agile Development
Waterfall Organization!
© Copyright 2014 Pivotal. All rights reserved.
Silo Delivery
15
Project Mgmt UX Dev QA DBA Sys
AdminNet
AdminStorage Admin
Adapted from: http://www.slideshare.net/adriancockcroft/goto-berlin
MONOLITHIC DELIVERY
© Copyright 2014 Pivotal. All rights reserved.
Continuous Delivery
16
Product Mgr UX Dev QA DBA Sys
AdminNet
AdminStorage Admin
BUSINESS CAPABILITY TEAMS USING MICROSERVICES
PLATFORM OPERATIONS TEAM
Adapted from: http://www.slideshare.net/adriancockcroft/goto-berlin
© Copyright 2014 Pivotal. All rights reserved.
Continuous Delivery
17
Product Mgr UX Dev QA DBA Sys
AdminNet
AdminStorage Admin
BUSINESS CAPABILITY TEAMS USING MICROSERVICES
PLATFORM OPERATIONS TEAM
Adapted from: http://www.slideshare.net/adriancockcroft/goto-berlin
Self Service
API
© Copyright 2014 Pivotal. All rights reserved. 18
INVENTORY
Prod Release
Prod Release
Prod Release
CATALOG
Prod Release
Prod Release
Prod Release
REVIEWS
Prod Release
Prod Release
Prod Release
SHIPPING
Prod Release
Prod Release
Prod Release
© Copyright 2014 Pivotal. All rights reserved. 19
Microservices Enabling Continuous Delivery•Decoupling Capabilities -> Decoupling Change Cycles
• Product Ownership: Tip to Tail
•We Build and Operate What We Understand BEST
•We Collaborate via API Contracts
•Microservice to Microservice
•Microservice to Platform
© Copyright 2014 Pivotal. All rights reserved. 20
Systems over ServicesComposition over Components
© Copyright 2014 Pivotal. All rights reserved.
Microframeworks for Microservices
21
Spring Boot http://projects.spring.io/spring-boot
Dropwizard http://dropwizard.io
© Copyright 2014 Pivotal. All rights reserved.
It can get pretty small…
22
@RestController class ThisWillActuallyRun { @RequestMapping("/") String home() { Hello World! } }
© Copyright 2014 Pivotal. All rights reserved.
With Spring Data REST!
23
http://projects.spring.io/spring-data-rest
@Entity @Table(name = "city") public class City implements Serializable { ! @Id @GeneratedValue private Long id; ! @Column(nullable = false) private String name; ! @Column(nullable = false) private String county; !//... !}
© Copyright 2014 Pivotal. All rights reserved.
With Spring Data REST!
24
http://projects.spring.io/spring-data-rest
@RepositoryRestResource(collectionResourceRel = "cities", path = "cities") public interface CityRepository extends PagingAndSortingRepository<City, Long> {}
@Configuration @ComponentScan @EnableAutoConfiguration @EnableJpaRepositories @Import(RepositoryRestMvcConfiguration.class) public class Application { ! public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
© Copyright 2014 Pivotal. All rights reserved.
With Spring Data REST!
25
http://projects.spring.io/spring-data-rest
{ "_links" : { "next" : { "href" : "http://localhost:8080/cities?page=1&size=20" }, "self" : { "href" : "http://localhost:8080/cities{?page,size,sort}", "templated" : true } }, "_embedded" : { "cities" : [ { "name" : "HOLTSVILLE", "county" : "SUFFOLK", "stateCode" : "NY", "postalCode" : "00501", "latitude" : "+40.922326", "longitude" : "-072.637078",
© Copyright 2014 Pivotal. All rights reserved.
But No Microservice is an Island…
26
© Copyright 2014 Pivotal. All rights reserved.
Example Distributed System: Minified
27
© Copyright 2014 Pivotal. All rights reserved. 28
Some emergent features of microservices systems…
•Distributed/Versioned Configuration
• Service Registration/Discovery
• Routing/Load Balancing
• Fault Tolerance (Circuit Breakers, Bulkheads, …)
© Copyright 2014 Pivotal. All rights reserved.
Example: Coordination Boiler Plate
29
© Copyright 2014 Pivotal. All rights reserved. 30
• Eureka
•Hystrix + Turbine
• Ribbon
• Feign
• Zuul
•Archaius
+
http://netflix.github.io
© Copyright 2014 Pivotal. All rights reserved. 31
http://projects.spring.io/spring-cloud
© Copyright 2014 Pivotal. All rights reserved.
Example: Spring Cloud + Netflix OSS
32
© Copyright 2014 Pivotal. All rights reserved.
Running a Config Server
33
@Configuration @EnableAutoConfiguration @EnableEurekaClient @EnableConfigServer public class ConfigServerApplication { ! public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); } !}
© Copyright 2014 Pivotal. All rights reserved.
Running a Eureka Server
34
@ComponentScan @Configuration @EnableAutoConfiguration @EnableEurekaServer @EnableEurekaClient public class EurekaApplication { ! public static void main(String[] args) { SpringApplication.run(EurekaApplication.class, args); } !}
© Copyright 2014 Pivotal. All rights reserved.
Service Registration/Discovery
35
@EnableAutoConfiguration @ComponentScan @EnableScheduling @EnableHystrix @EnableEurekaClient public class CustomerApp extends RepositoryRestMvcConfiguration { @Override protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { config.exposeIdsFor(Customer.class); } ! public static void main(String[] args) { SpringApplication.run(CustomerApp.class, args); } !}
© Copyright 2014 Pivotal. All rights reserved.
Service Registration/Discovery
36
© Copyright 2014 Pivotal. All rights reserved.
Fault Tolerance
37
@EnableAutoConfiguration @ComponentScan @EnableScheduling @EnableHystrix @EnableEurekaClient public class CustomerApp extends RepositoryRestMvcConfiguration { @Override protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { config.exposeIdsFor(Customer.class); } ! public static void main(String[] args) { SpringApplication.run(CustomerApp.class, args); } !}
© Copyright 2014 Pivotal. All rights reserved.
Enabling a Circuit Breaker
38
@HystrixCommand(fallbackMethod = "defaultLink") public Link getStoresByLocationLink(Map<String, Object> parameters) { URI storesUri = URI.create(uri); try { ServiceInstance instance = loadBalancer.choose("stores"); storesUri = URI.create(String.format("http://%s:%s", instance.getHost(), instance.getPort())); } catch (RuntimeException e) { // Eureka not available } ! Traverson traverson = new Traverson(storesUri, MediaTypes.HAL_JSON); Link link = traverson.follow("stores", "search", "by-location") .withTemplateParameters(parameters).asLink(); ! return link; }
Client-Side Load Balancing
© Copyright 2014 Pivotal. All rights reserved. 39
{ "id" : 3, "firstname" : "Matt", "lastname" : "Stine", "address" : { "street" : "9195 East Mineral Circle", "zipCode" : "80112", "city" : "Centennial", "location" : { "latitude" : 39.5738106, "longitude" : -104.8816934 } }, "_links" : { "self" : { "href" : "http://pivotalcustomers.cfapps.io/customers/3" }, "stores-nearby" : { "href" : "http://pivotalstores.cfapps.io/stores/search/findByAddressLocationNear?location=39.5738106,-104.8816934&distance=50" } } }
© Copyright 2014 Pivotal. All rights reserved. 40
© Copyright 2014 Pivotal. All rights reserved.
Circuit Breaker Fallback
41
public Link defaultLink(Map<String, Object> parameters) { return null; }
@HystrixCommand(fallbackMethod = "defaultLink") public Link getStoresByLocationLink(Map<String, Object> parameters) { //... }
© Copyright 2014 Pivotal. All rights reserved. 42
{ "id" : 3, "firstname" : "Matt", "lastname" : "Stine", "address" : { "street" : "9195 East Mineral Circle", "zipCode" : "80112", "city" : "Centennial", "location" : { "latitude" : 39.5738106, "longitude" : -104.8816934 } }, "_links" : { "self" : { "href" : "http://pivotalcustomers.cfapps.io/customers/3" } } } // stores-nearby is gone!!!
© Copyright 2014 Pivotal. All rights reserved. 43
© Copyright 2014 Pivotal. All rights reserved. 44
Operationalized ArchitectureYou have to pay for your lunch!
© Copyright 2014 Pivotal. All rights reserved.© Copyright 2014 Pivotal. All rights reserved. 45
http://highscalability.com/blog/2014/4/8/microservices-not-a-free-lunch.html
© Copyright 2014 Pivotal. All rights reserved. 46
Paying for your lunch…• Significant Operations Overhead
• Substantial DevOps Skills Required
• Implicit Interfaces
•Duplication of Effort
•Distributed System Complexity
•Asynchronicity is Difficult!
• Testability Challenges
© Copyright 2014 Pivotal. All rights reserved.
You must be this tall to use Microservices…
47
http://martinfowler.com/bliki/MicroservicePrerequisites.html
https://www.flickr.com/photos/gusset/3723961589
• RAPID PROVISIONING
•BASIC MONITORING
• RAPID APPLICATION DEPLOYMENT
•DEVOPS CULTURE
© Copyright 2014 Pivotal. All rights reserved.
It takes a platform…
48
http://techblog.netflix.com/2013/01/optimizing-netflix-api.htmlhttp://techblog.netflix.com/2014/03/the-netflix-dynamic-scripting-platform.html
© Copyright 2014 Pivotal. All rights reserved.
It takes a platform…
49
Pivotal CF Spring Cloud
© Copyright 2014 Pivotal. All rights reserved. 50
Platform Features• Environment Provisioning
•On-Demand/Automatic Scaling
• Failover/Resilience
• Routing/Load Balancing
•Data Service Operations
•Monitoring
© Copyright 2014 Pivotal. All rights reserved.
Environment Provisioning/App Deployment
51
Rou
ter
Cloud Controller Service Broker Node(s)
DEA DEA
DEA DEA
Blobstore DB
Runtime
1. Upload bits/metadata
2. Create/bind services
3. Stage via Buildpack
4. Deploy via Container
push app+ app MD
SC
+ =
http://docs.cloudfoundry.org/devguide/deploy-apps/
© Copyright 2014 Pivotal. All rights reserved.
Environment Provisioning/App Deployment
52
Rou
ter
Cloud Controller
DEA
Blobstore DB
Runtime
Detect Compile UploadNo
System Buildpacks
+ =
Yes
http://docs.cloudfoundry.org/buildpacks/
© Copyright 2014 Pivotal. All rights reserved.
Deployment/Load Balancing/Scaling
53
Blobstore
R
oute
r Cloud Controller
DEA
Messaging (NATS)
DEA DEA
Runtime
Access App
http://docs.cloudfoundry.org/concepts/architecture/warden.html
Container Container
© Copyright 2014 Pivotal. All rights reserved.
Failover/Resilience
54
Blobstore
R
oute
r Cloud Controller
DEA
Messaging (NATS)
DEA DEA
Runtime
Health ManagerActual StateDesired State
http://docs.cloudfoundry.org/concepts/architecture/#hm9k
Container Container Container
© Copyright 2014 Pivotal. All rights reserved.
Data Service Operations: Cluster Provisioning
55
Blobstore
BOSH
Health Monitor
DBDeploy my Services
IaaS
Worker VMs BOSH Director
NATS Cassandra Node
Target VMCassandra Node
Target VMCassandra Node
Target VM
http://bosh.cloudfoundry.org/
© Copyright 2014 Pivotal. All rights reserved.
DB
Rou
ter
Data Service Operations: Application Binding
56
Service credentials
reserve resources
obtain connection data
CLI Cloud Controller
Service Broker
Data Service
Runtime
create service (HTTP)
bind service (HTTP)
create service (HTTP)
bind service (HTTP)
http://docs.cloudfoundry.org/services/api.html
© Copyright 2014 Pivotal. All rights reserved.
Monitoring
57
© Copyright 2014 Pivotal. All rights reserved. 58
It’s All About the DataWhat about the BIG QUESTIONS?
© Copyright 2014 Pivotal. All rights reserved.
This won’t work…
59
© Copyright 2014 Pivotal. All rights reserved. 60
Instead!
© Copyright 2014 Pivotal. All rights reserved.
Bounded Contexts
61
Movie Movie
Actor
Genre
Media Type
Media Type
Kiosk
Location
Media
Product Catalog
Inventory
© Copyright 2014 Pivotal. All rights reserved.
Polyglot Persistence
62
REST XYou shall not pass…
© Copyright 2014 Pivotal. All rights reserved.
But I have a question!
63
REST XYou shall not pass…
?
?
? ?
?
?
© Copyright 2014 Pivotal. All rights reserved.
Lambda Architecture
64
© Copyright 2014 Pivotal. All rights reserved.
Join via Events!
65
© Copyright 2014 Pivotal. All rights reserved. 66
http://projects.spring.io/spring-xd/
© Copyright 2014 Pivotal. All rights reserved. 67
© Copyright 2014 Pivotal. All rights reserved. 68
© Copyright 2014 Pivotal. All rights reserved.
Redbox Conceptual Workflow
69
© Copyright 2014 Pivotal. All rights reserved.
SpringBox Microservices
70
Catalog Service
Inventory Service
Kiosk
Kiosk
Kiosk
Reservation Service
https://github.com/cf-platform-eng/springbox-datacloud
© Copyright 2014 Pivotal. All rights reserved.
…and if you have a question:
71
Kiosk
Kiosk
Kiosk
Speed Layer
Batch Layer Serving Layer
Event Ingest
https://github.com/cf-platform-eng/springbox-datacloud
“What movie genres are most popular in what geographic locations?”
© Copyright 2014 Pivotal. All rights reserved.
“What movie genres are most popular in what geographic locations?”
72
// Aggregate preferences across all kiosks: stream create --name kiosk_agg_prefs --definition "rabbit --queues=lambda.kiosk.events | field-value-counter --fieldName=genreIds" !// Tap aggregate preferences, filter for kiosk #1: stream create --name kiosk_1_prefs --definition "tap:stream:kiosk_agg_prefs > filter --expression=#jsonPath(payload,'$.locationId').equals(1) | field-value-counter --fieldName=genreIds"
© Copyright 2014 Pivotal. All rights reserved.
“What movie genres are most popular in what geographic locations?”
73
field-value-counter display --name kiosk_agg_prefs field-value-counter display=kiosk_agg_prefs ------------------------------------------- - ----- VALUE - COUNT Action | 14 Adventure | 6 Comedy | 27 Sci-Fi | 18
© Copyright 2014 Pivotal. All rights reserved. 74
Where We’ve Been…•Microservices are an enabler to Continuous Delivery.
• Less about services, more about composed distributed systems. Patterns can help.
• You’re going to need a platform.
•Decomposed data governance -> recomposed data discovery.
• Thank You!
A NEW PLATFORM FOR A NEW ERA