SlideShare a Scribd company logo
1 of 23
Architecting for
Microservices Part 2
Denver Code Club Meetup Bill Schwanitz, Technical Architect
December 15, 2016 Craig Martin, Vice President of Engineering
Agenda
• Microservices (isn’t that what we are here
for?)
• What is a microservice?
• NETFLIX OSS
• Zuul
• Eureka
• Hystrix
• Archaius
• Million Song Library code walkthrough
• Build Million Song Library
An overview of Microservices
• N number of modular components joined
together via the network.
• Decomposed by units of business or functionality
• Combined makes up an entire backend system
• Single Responsibility Principle (SRP)
• Code with a singleness of purpose
• Interface Segregation Principle (ISP)
• No client should be forced to depend on
methods it does not use
• Service grouped by business domain area or
capability
• Many standalone “vertical” stack focused on a
single domain
• Netflix OSS
• “Gatekeeper”
Routing
Monitoring
Security
• Makes endpoints available
• Main use cases
Auth-N (not Auth-z)
DDOS
Transformation
• Groovy and Java
Filters in Groovy
Zuul
Challenges
• Performance
• Forgetting to open endpoints
• Logging
• “Pre” filter - First line of defence
Check URL (Sitemap)
Auth-N
Structure
Data Transformation
• “routing” filters
Endpoint Mapping
Service Discovery
• “post” filters
Data transformation
logging
• “static” filters
Healthcheck
References:
MSL server/msl-zuul:
github.com/kenzanlabs/msl-
zuul/tree/master/src/main/groovy/filters
Zuul - How does it
work?
Lessons Learned
• Keep it lightweight
• Can be used for
soaking
Other Options
• NginX
• ELBs
• API Gateway
• Netflix OSS Service Registry
• Used for “discovery”
• Heartbeat of the application
• Why not use ELBs?
Fewer IPs
Compromise Security
Groups
Stateless
• Replicated across regions
• Load balancing
• “Push” heartbeat monitoring
Eureka
Challenges
• Only works with
AWS
• Performance
• Scalability
Other Options
• Containerization
(Kubernetes)
• Consul
• ELBs
What is it?
• Eureka Client
Registers with Eureka Server
Part of the bootstrap process
Routinely updates
• Eureka Server
Maintains mapping of VIPs to IPs
Redundancy
Round Robin Load Balancing
Netflix OSS Service Registry
• Typically abstract discovery via
Ribbon Client
Best Practices
• Discovery shouldn’t be a dev
responsibility
• Single point of failure
• Scale “correctly”
Eureka
How it works.
Hystrix - What is it?
Controls the interactions between
distributed services, by:
• Adding latency tolerance logic
• Adding fault tolerance logic
• Isolating points of access between the
services
• Stopping cascading failures across
them
• Providing fallback options
Hystrix - Why?
Compared to Monolithic applications,
Microservices strongly rely upon networks.
So failure detection and manipulation logic
is essential.
Normal function (Closed)
When a system is functioning smoothly
Failure state (Open)
At this juncture, every call to the dependency is short-circuited with a
HystrixRuntimeException, giving clear indication of its cause.
Half-open state
Once the sleep Interval passes, Hystrix checks system availability, letting other
requests fail-fast until the response is obtained. If the call is successful, go to
Closed; in case of failure, go back to Open
Hystrix - How?
● Wrapping all external calls in a HystrixCommand or HystrixObservableCommand
● Timing-out calls when needed.
● Maintaining a small thread-pool for each dependency (monitor load)
● Measuring successes, failures , timeouts, and thread rejections.
● Tripping a circuit-breaker to stop all requests to a particular service for a period of time
● Performing fallback logic when a request fails, is rejected, times-out, or short-circuits.
● Monitoring metrics and configuration changes in near real-time.
For Additional information:
https://github.com/Netflix/Hystrix/wiki/How-it-Works
Archaius
Java library that provides APIs
to access and utilize properties
that can change dynamically at
runtime. It includes the following
features:
● Dynamic, Typed Properties
● High throughput and Thread Safe
Configuration operations
● A polling framework that allows users to
obtain property changes to a
Configuration Source
● Allows retrieval of properties from local
properties files or a properties server
○ Darchaius.configurationSource.additi
onalUrls=file:///apps/myapp/applicatio
n.properties
○ Darchaius.configurationSource.additi
onalUrls=http://myserver/properties
● Automatically updates to all servers
Million Song
Library
• Java 8
• Netflix OSS (Eureka, Hystrix, Zuul,
Archaius)
• Datastax (Cassandra)
• Swagger
Backend Tech
Platform Tech
• Maven
• Docker
• Spinnaker
Documentation Tech
• Swagger
• Ascii Docs
Time to Look at Some Code
Netflix OSS
• Zuul
• Eureka
• Hystrix
• Archaius
Zuul - Example of Zuul
Configuration -
pom.xml
• In MSL, we configure Zuul via
the pom.xml and Archaius
properties
• So here you see the
pom.xml:
Zuul runs in jetty
We can supply additional
configuration via
Archaius
Zuul will listen on port
9000
Example:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-version}</version>
<configuration>
<systemProperties>
<systemProperty>
<name>archaius.deployment.applicationId</name>
<value>zuul</value>
</systemProperty>
</systemProperties>
.
.
.
<httpConnector>
<port>9000</port>
</httpConnector>
</configuration>
</plugin>
References:
github.com/kenzanlabs/msl-zuul
Zuul - Example of Zuul
Configuration - properties
• In MSL, we configure Zuul via
the pom.xml and Archaius
properties:
Locations of the pre, routing
and post filters
Allowable and default
clients
Configuration for one of
those clients
• And an example of a URL
Notice it goes to port 9000
Has the client name
loginedge
Then the rest of the URL is
the URI to the client
• So Zuul redirects this request to
login-edge:9001
Properties:
zuul.filter.pre.path=src/main/groovy/filters/pre
zuul.filter.routing.path=src/main/groovy/filters/route
zuul.filter.post.path=src/main/groovy/filters/post
zuul.niws.clientlist=loginedge|accountedge|catalogedge|ratingsedge
loginedge.zuul.client.DeploymentContextBasedVipAddresses=msl.log
in.edge
loginedge.zuul.client.Port=9001
Example URL:
https://msl.kenzanlabs.com:9000/loginedge/login
References:
github.com/kenzanlabs/msl-zuul/tree/master/src/main/resources
Eureka Example
• Registration
Tell Eureka Server that a
new instance of a
microservice has
started
Needs eureka properties
Needs Karyon to be
instantiated
Handles routine
heartbeat from client
to server
• Healthcheck
Allows Eureka Server to
check if instance is still
up and running
Eureka Server will
remove any down
instance
Properties:
eureka.name=loginedge
eureka.vipAddress=msl.login.edge
eureka.port=9001
eureka.serviceUrl.default=http://localhost:8080/eureka/v2/
eureka.region=default
eureka.preferSameZone=true
eureka.registration.enabled=true
Karyon Startup:
KaryonServer server = new KaryonServer();
server.start();
Healthcheck ReST Endpoint:
@Path("/healthcheck")
public class HealthCheckResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response healthcheck() {
return Response.status(Response.Status.OK).build();
}
}
Hystrix example
Setup
• Create a subclass of
HystrixCommand
• The command group key
groups commands for
configuration, thread pooling,
etc.
• Override the run() method
• Optionally override the
getFallback() method
Calling
• Instantiate your command
class
• Call its execute() method
Code:
class ValidateAccountCommand extends HystrixCommand<Boolean>
{
private Account account;
protected ValidateAccountCommand(Account account) {
super(Setter.withGroupKey(HystrixCommandGroupKey.Factory
.asKey("validateAccount")));
this.account = account;
}
@Override
protected Boolean run() throws Exception {
return AccountValidator.isValid(account);
}
@Override
protected Boolean getFallback() {
return false;
}
}
public Boolean save(Account account) throws Exception {
return (new ValidateAccountCommand(account).execute());
}
Archaius
Example• Configuration
Declare the properties
source(s)
Can be a local file or a
properties server
• Use
Properties are typed
Boolean
Int
Long
String
etc.
Only need to declare the
DynamicXProperty
once
Then just use x.get()
whenever you need to
use the value
Calling x.get() once and
storing the result is an
anti-pattern - doesn’t
allow for dynamic
reconfiguration
Properties:
archaius.configurationSource.additionalUrls=
file://msl-login-edge-config/edge-config.properties
or
archaius.configurationSource.additionalUrls=http://myserver/properties
Code:
static final DynamicLongProperty timeToWait = DynamicPropertyFactory
.getInstance().getLongProperty("msl.sleep", 100);
void foo() {
long t = timeToWait.get();
sleep(t)
}
Anti-pattern:
static final long t = DynamicPropertyFactory
.getInstance().getLongProperty("msl.sleep", 100).get();
void foo() {
sleep(t)
}
Why?
• The API is described in one place, a
yaml formatted file (can also be
described using annotations in an
existing Java file)
• From the yaml file, swagger tools
generate client and server code stubs,
and documentation
• Since code and documentation are
created from the same yaml file, the
code and the documentation will never
diverge
Swagger - What?
A specification and associated tools for
describing, producing, consuming, and
visualizing a ReST API
YAML File:
.
.
.
/catalog-edge/browse/album:
x-swagger-router-controller: catalog_controller
get:
description: "Get browsing data for albums in the catalog"
tags:
- Catalog
operationId: browse_albums
parameters:
-
$ref: "#/parameters/PagingState"
-
$ref: "#/parameters/Items"
-
$ref: "#/parameters/Facets"
responses:
"200":
description: Success
schema:
$ref: "#/definitions/AlbumList"
"400":
description: “Invalid pagingState or facet”
.
.
.
Yaml Details
• First line defines the URI path to the
endpoint
• tags: grouping endpoints for docs
• x-swagger-router-controller: the name
of the Node controller file
• operationId: name of the function in
server stub
• parameters: optional path and query
parameters
Swagger - Generated Server Stub
CatalogEdgeApi.java
@Path("/catalog-edge")
@Consumes({ "application/json" })
@Produces({ "application/json" })
public class CatalogEdgeApi {
private final CatalogEdgeApiService delegate = CatalogEdgeApiServiceFactory.getCatalogEdgeApi();
@GET
@Path("/browse/album")
@Consumes({ "application/json" })
@Produces({ "application/json" })
public Response browseAlbums(
@QueryParam("items") Integer items,
@QueryParam("pagingState") String pagingState,
@QueryParam("facets") String facets)
) throws NotFoundException {
return delegate.browseAlbums(items,pagingState,facets);
}
...
}
CatalogEdgeApiService.java
public abstract class CatalogEdgeApiService {
public abstract Response browseAlbums(Integer items,String pagingState,String facets)
throws NotFoundException;
}
MSL Local Installation
Prerequisites
● git installed
● personal git account created
CD to where you want to install it
cd ~
Retrieve the main MSL repository from github
git clone https://github.com/kenzanmedia/million-song-library
CD into the new directory
cd million-song-library/bin
Be sure the setup script is executable
chmod +x setup.sh
Run the setup script
./setup.sh
Want to learn more?
Follow us!
@kenzanmedia
www.linkedin.com/company/kenzan-media
techblog.kenzan.com
www.facebook.com/kenzanmedia/

More Related Content

What's hot

Sf bay area Kubernetes meetup dec8 2016 - deployment models
Sf bay area Kubernetes meetup dec8 2016 - deployment modelsSf bay area Kubernetes meetup dec8 2016 - deployment models
Sf bay area Kubernetes meetup dec8 2016 - deployment modelsPeter Ss
 
Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes
 Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes
Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnesdistributed matters
 
Service discovery in mesos miguel, Angel Guillen
Service discovery in mesos miguel, Angel GuillenService discovery in mesos miguel, Angel Guillen
Service discovery in mesos miguel, Angel GuillenJ On The Beach
 
The Operator Pattern - Managing Stateful Services in Kubernetes
The Operator Pattern - Managing Stateful Services in KubernetesThe Operator Pattern - Managing Stateful Services in Kubernetes
The Operator Pattern - Managing Stateful Services in KubernetesQAware GmbH
 
CDK Meetup: Rule the World through IaC
CDK Meetup: Rule the World through IaCCDK Meetup: Rule the World through IaC
CDK Meetup: Rule the World through IaCsmalltown
 
Netflix0SS Services on Docker
Netflix0SS Services on DockerNetflix0SS Services on Docker
Netflix0SS Services on DockerDocker, Inc.
 
Kubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive OverviewKubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive OverviewBob Killen
 
OpenStack Neutron Reverse Engineered
OpenStack Neutron Reverse EngineeredOpenStack Neutron Reverse Engineered
OpenStack Neutron Reverse Engineeredopenstackindia
 
Building ‘Bootiful’ microservices cloud
Building ‘Bootiful’ microservices cloudBuilding ‘Bootiful’ microservices cloud
Building ‘Bootiful’ microservices cloudIdan Fridman
 
Serverless and Servicefull Applications - Where Microservices complements Ser...
Serverless and Servicefull Applications - Where Microservices complements Ser...Serverless and Servicefull Applications - Where Microservices complements Ser...
Serverless and Servicefull Applications - Where Microservices complements Ser...Red Hat Developers
 
Kubernetes Monitoring & Best Practices
Kubernetes Monitoring & Best PracticesKubernetes Monitoring & Best Practices
Kubernetes Monitoring & Best PracticesAjeet Singh Raina
 
Kubernetes Summit 2019 - Harden Your Kubernetes Cluster
Kubernetes Summit 2019 - Harden Your Kubernetes ClusterKubernetes Summit 2019 - Harden Your Kubernetes Cluster
Kubernetes Summit 2019 - Harden Your Kubernetes Clustersmalltown
 
KubeCon Prometheus Salon -- Kubernetes metrics deep dive
KubeCon Prometheus Salon -- Kubernetes metrics deep diveKubeCon Prometheus Salon -- Kubernetes metrics deep dive
KubeCon Prometheus Salon -- Kubernetes metrics deep diveBob Cotton
 
Load Balancing in the Cloud using Nginx & Kubernetes
Load Balancing in the Cloud using Nginx & KubernetesLoad Balancing in the Cloud using Nginx & Kubernetes
Load Balancing in the Cloud using Nginx & KubernetesLee Calcote
 
Consul: Microservice Enabling Microservices and Reactive Programming
Consul: Microservice Enabling Microservices and Reactive ProgrammingConsul: Microservice Enabling Microservices and Reactive Programming
Consul: Microservice Enabling Microservices and Reactive ProgrammingRick Hightower
 
Cloud Native Microservices with Spring Cloud
Cloud Native Microservices with Spring CloudCloud Native Microservices with Spring Cloud
Cloud Native Microservices with Spring CloudConor Svensson
 

What's hot (20)

Sf bay area Kubernetes meetup dec8 2016 - deployment models
Sf bay area Kubernetes meetup dec8 2016 - deployment modelsSf bay area Kubernetes meetup dec8 2016 - deployment models
Sf bay area Kubernetes meetup dec8 2016 - deployment models
 
How to Develop OpenStack
How to Develop OpenStackHow to Develop OpenStack
How to Develop OpenStack
 
Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes
 Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes
Microservices with Netflix OSS & Spring Cloud - Arnaud Cogoluègnes
 
Service discovery in mesos miguel, Angel Guillen
Service discovery in mesos miguel, Angel GuillenService discovery in mesos miguel, Angel Guillen
Service discovery in mesos miguel, Angel Guillen
 
The Operator Pattern - Managing Stateful Services in Kubernetes
The Operator Pattern - Managing Stateful Services in KubernetesThe Operator Pattern - Managing Stateful Services in Kubernetes
The Operator Pattern - Managing Stateful Services in Kubernetes
 
CDK Meetup: Rule the World through IaC
CDK Meetup: Rule the World through IaCCDK Meetup: Rule the World through IaC
CDK Meetup: Rule the World through IaC
 
Netflix0SS Services on Docker
Netflix0SS Services on DockerNetflix0SS Services on Docker
Netflix0SS Services on Docker
 
Consul and Consul Pusher
Consul and Consul PusherConsul and Consul Pusher
Consul and Consul Pusher
 
Docker+java
Docker+javaDocker+java
Docker+java
 
Kubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive OverviewKubernetes - A Comprehensive Overview
Kubernetes - A Comprehensive Overview
 
Kubernetes 101
Kubernetes 101Kubernetes 101
Kubernetes 101
 
OpenStack Neutron Reverse Engineered
OpenStack Neutron Reverse EngineeredOpenStack Neutron Reverse Engineered
OpenStack Neutron Reverse Engineered
 
Building ‘Bootiful’ microservices cloud
Building ‘Bootiful’ microservices cloudBuilding ‘Bootiful’ microservices cloud
Building ‘Bootiful’ microservices cloud
 
Serverless and Servicefull Applications - Where Microservices complements Ser...
Serverless and Servicefull Applications - Where Microservices complements Ser...Serverless and Servicefull Applications - Where Microservices complements Ser...
Serverless and Servicefull Applications - Where Microservices complements Ser...
 
Kubernetes Monitoring & Best Practices
Kubernetes Monitoring & Best PracticesKubernetes Monitoring & Best Practices
Kubernetes Monitoring & Best Practices
 
Kubernetes Summit 2019 - Harden Your Kubernetes Cluster
Kubernetes Summit 2019 - Harden Your Kubernetes ClusterKubernetes Summit 2019 - Harden Your Kubernetes Cluster
Kubernetes Summit 2019 - Harden Your Kubernetes Cluster
 
KubeCon Prometheus Salon -- Kubernetes metrics deep dive
KubeCon Prometheus Salon -- Kubernetes metrics deep diveKubeCon Prometheus Salon -- Kubernetes metrics deep dive
KubeCon Prometheus Salon -- Kubernetes metrics deep dive
 
Load Balancing in the Cloud using Nginx & Kubernetes
Load Balancing in the Cloud using Nginx & KubernetesLoad Balancing in the Cloud using Nginx & Kubernetes
Load Balancing in the Cloud using Nginx & Kubernetes
 
Consul: Microservice Enabling Microservices and Reactive Programming
Consul: Microservice Enabling Microservices and Reactive ProgrammingConsul: Microservice Enabling Microservices and Reactive Programming
Consul: Microservice Enabling Microservices and Reactive Programming
 
Cloud Native Microservices with Spring Cloud
Cloud Native Microservices with Spring CloudCloud Native Microservices with Spring Cloud
Cloud Native Microservices with Spring Cloud
 

Similar to Architecting for Microservices Part 2

Powering Remote Developers with Amazon Workspaces
Powering Remote Developers with Amazon WorkspacesPowering Remote Developers with Amazon Workspaces
Powering Remote Developers with Amazon WorkspacesAmazon Web Services
 
TechEvent 2019: Oracle Databases as Managed Service at AWS, Yes it works!; Al...
TechEvent 2019: Oracle Databases as Managed Service at AWS, Yes it works!; Al...TechEvent 2019: Oracle Databases as Managed Service at AWS, Yes it works!; Al...
TechEvent 2019: Oracle Databases as Managed Service at AWS, Yes it works!; Al...Trivadis
 
Event Bus as Backbone for Decoupled Microservice Choreography (Oracle Code, A...
Event Bus as Backbone for Decoupled Microservice Choreography (Oracle Code, A...Event Bus as Backbone for Decoupled Microservice Choreography (Oracle Code, A...
Event Bus as Backbone for Decoupled Microservice Choreography (Oracle Code, A...Lucas Jellema
 
DCSF19 Container Security: Theory & Practice at Netflix
DCSF19 Container Security: Theory & Practice at NetflixDCSF19 Container Security: Theory & Practice at Netflix
DCSF19 Container Security: Theory & Practice at NetflixDocker, Inc.
 
Flying to clouds - can it be easy? Cloud Native Applications
Flying to clouds - can it be easy? Cloud Native ApplicationsFlying to clouds - can it be easy? Cloud Native Applications
Flying to clouds - can it be easy? Cloud Native ApplicationsJacek Bukowski
 
JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?
JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?
JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?PROIDEA
 
Vault Digital Transformation
Vault Digital TransformationVault Digital Transformation
Vault Digital TransformationStenio Ferreira
 
Distributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and ScalaDistributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and ScalaMax Alexejev
 
Event Bus as Backbone for Decoupled Microservice Choreography (JFall 2017)
Event Bus as Backbone for Decoupled Microservice Choreography (JFall 2017)Event Bus as Backbone for Decoupled Microservice Choreography (JFall 2017)
Event Bus as Backbone for Decoupled Microservice Choreography (JFall 2017)Lucas Jellema
 
Secret Management with Hashicorp Vault and Consul on Kubernetes
Secret Management with Hashicorp Vault and Consul on KubernetesSecret Management with Hashicorp Vault and Consul on Kubernetes
Secret Management with Hashicorp Vault and Consul on KubernetesAn Nguyen
 
Alabama CyberNow 2018: Cloud Hardening and Digital Forensics Readiness
Alabama CyberNow 2018: Cloud Hardening and Digital Forensics ReadinessAlabama CyberNow 2018: Cloud Hardening and Digital Forensics Readiness
Alabama CyberNow 2018: Cloud Hardening and Digital Forensics ReadinessToni de la Fuente
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disquszeeg
 
Getting Started with Serverless Architectures
Getting Started with Serverless ArchitecturesGetting Started with Serverless Architectures
Getting Started with Serverless ArchitecturesAmazon Web Services
 
Cloud Architect Alliance #15: Openstack
Cloud Architect Alliance #15: OpenstackCloud Architect Alliance #15: Openstack
Cloud Architect Alliance #15: OpenstackMicrosoft
 
Getting Started with Apache CloudStack
Getting Started with Apache CloudStackGetting Started with Apache CloudStack
Getting Started with Apache CloudStackJoe Brockmeier
 
Kubernetes Infra 2.0
Kubernetes Infra 2.0Kubernetes Infra 2.0
Kubernetes Infra 2.0Deepak Sood
 
CloudStack Overview
CloudStack OverviewCloudStack Overview
CloudStack Overviewsedukull
 
Meetup on Apache Zookeeper
Meetup on Apache ZookeeperMeetup on Apache Zookeeper
Meetup on Apache ZookeeperAnshul Patel
 

Similar to Architecting for Microservices Part 2 (20)

Powering Remote Developers with Amazon Workspaces
Powering Remote Developers with Amazon WorkspacesPowering Remote Developers with Amazon Workspaces
Powering Remote Developers with Amazon Workspaces
 
TechEvent 2019: Oracle Databases as Managed Service at AWS, Yes it works!; Al...
TechEvent 2019: Oracle Databases as Managed Service at AWS, Yes it works!; Al...TechEvent 2019: Oracle Databases as Managed Service at AWS, Yes it works!; Al...
TechEvent 2019: Oracle Databases as Managed Service at AWS, Yes it works!; Al...
 
Event Bus as Backbone for Decoupled Microservice Choreography (Oracle Code, A...
Event Bus as Backbone for Decoupled Microservice Choreography (Oracle Code, A...Event Bus as Backbone for Decoupled Microservice Choreography (Oracle Code, A...
Event Bus as Backbone for Decoupled Microservice Choreography (Oracle Code, A...
 
DCSF19 Container Security: Theory & Practice at Netflix
DCSF19 Container Security: Theory & Practice at NetflixDCSF19 Container Security: Theory & Practice at Netflix
DCSF19 Container Security: Theory & Practice at Netflix
 
Flying to clouds - can it be easy? Cloud Native Applications
Flying to clouds - can it be easy? Cloud Native ApplicationsFlying to clouds - can it be easy? Cloud Native Applications
Flying to clouds - can it be easy? Cloud Native Applications
 
JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?
JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?
JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?
 
Vault Digital Transformation
Vault Digital TransformationVault Digital Transformation
Vault Digital Transformation
 
Distributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and ScalaDistributed & Highly Available server applications in Java and Scala
Distributed & Highly Available server applications in Java and Scala
 
Event Bus as Backbone for Decoupled Microservice Choreography (JFall 2017)
Event Bus as Backbone for Decoupled Microservice Choreography (JFall 2017)Event Bus as Backbone for Decoupled Microservice Choreography (JFall 2017)
Event Bus as Backbone for Decoupled Microservice Choreography (JFall 2017)
 
App fabric introduction
App fabric introductionApp fabric introduction
App fabric introduction
 
Secret Management with Hashicorp Vault and Consul on Kubernetes
Secret Management with Hashicorp Vault and Consul on KubernetesSecret Management with Hashicorp Vault and Consul on Kubernetes
Secret Management with Hashicorp Vault and Consul on Kubernetes
 
Alabama CyberNow 2018: Cloud Hardening and Digital Forensics Readiness
Alabama CyberNow 2018: Cloud Hardening and Digital Forensics ReadinessAlabama CyberNow 2018: Cloud Hardening and Digital Forensics Readiness
Alabama CyberNow 2018: Cloud Hardening and Digital Forensics Readiness
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disqus
 
Getting Started with Serverless Architectures
Getting Started with Serverless ArchitecturesGetting Started with Serverless Architectures
Getting Started with Serverless Architectures
 
Windows 8 Apps and the Outside World
Windows 8 Apps and the Outside WorldWindows 8 Apps and the Outside World
Windows 8 Apps and the Outside World
 
Cloud Architect Alliance #15: Openstack
Cloud Architect Alliance #15: OpenstackCloud Architect Alliance #15: Openstack
Cloud Architect Alliance #15: Openstack
 
Getting Started with Apache CloudStack
Getting Started with Apache CloudStackGetting Started with Apache CloudStack
Getting Started with Apache CloudStack
 
Kubernetes Infra 2.0
Kubernetes Infra 2.0Kubernetes Infra 2.0
Kubernetes Infra 2.0
 
CloudStack Overview
CloudStack OverviewCloudStack Overview
CloudStack Overview
 
Meetup on Apache Zookeeper
Meetup on Apache ZookeeperMeetup on Apache Zookeeper
Meetup on Apache Zookeeper
 

Recently uploaded

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 

Recently uploaded (20)

"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 

Architecting for Microservices Part 2

  • 1. Architecting for Microservices Part 2 Denver Code Club Meetup Bill Schwanitz, Technical Architect December 15, 2016 Craig Martin, Vice President of Engineering
  • 2. Agenda • Microservices (isn’t that what we are here for?) • What is a microservice? • NETFLIX OSS • Zuul • Eureka • Hystrix • Archaius • Million Song Library code walkthrough • Build Million Song Library
  • 3. An overview of Microservices • N number of modular components joined together via the network. • Decomposed by units of business or functionality • Combined makes up an entire backend system • Single Responsibility Principle (SRP) • Code with a singleness of purpose • Interface Segregation Principle (ISP) • No client should be forced to depend on methods it does not use • Service grouped by business domain area or capability • Many standalone “vertical” stack focused on a single domain
  • 4.
  • 5. • Netflix OSS • “Gatekeeper” Routing Monitoring Security • Makes endpoints available • Main use cases Auth-N (not Auth-z) DDOS Transformation • Groovy and Java Filters in Groovy Zuul Challenges • Performance • Forgetting to open endpoints • Logging
  • 6. • “Pre” filter - First line of defence Check URL (Sitemap) Auth-N Structure Data Transformation • “routing” filters Endpoint Mapping Service Discovery • “post” filters Data transformation logging • “static” filters Healthcheck References: MSL server/msl-zuul: github.com/kenzanlabs/msl- zuul/tree/master/src/main/groovy/filters Zuul - How does it work? Lessons Learned • Keep it lightweight • Can be used for soaking Other Options • NginX • ELBs • API Gateway
  • 7. • Netflix OSS Service Registry • Used for “discovery” • Heartbeat of the application • Why not use ELBs? Fewer IPs Compromise Security Groups Stateless • Replicated across regions • Load balancing • “Push” heartbeat monitoring Eureka Challenges • Only works with AWS • Performance • Scalability Other Options • Containerization (Kubernetes) • Consul • ELBs What is it?
  • 8. • Eureka Client Registers with Eureka Server Part of the bootstrap process Routinely updates • Eureka Server Maintains mapping of VIPs to IPs Redundancy Round Robin Load Balancing Netflix OSS Service Registry • Typically abstract discovery via Ribbon Client Best Practices • Discovery shouldn’t be a dev responsibility • Single point of failure • Scale “correctly” Eureka How it works.
  • 9. Hystrix - What is it? Controls the interactions between distributed services, by: • Adding latency tolerance logic • Adding fault tolerance logic • Isolating points of access between the services • Stopping cascading failures across them • Providing fallback options Hystrix - Why? Compared to Monolithic applications, Microservices strongly rely upon networks. So failure detection and manipulation logic is essential. Normal function (Closed) When a system is functioning smoothly Failure state (Open) At this juncture, every call to the dependency is short-circuited with a HystrixRuntimeException, giving clear indication of its cause. Half-open state Once the sleep Interval passes, Hystrix checks system availability, letting other requests fail-fast until the response is obtained. If the call is successful, go to Closed; in case of failure, go back to Open
  • 10. Hystrix - How? ● Wrapping all external calls in a HystrixCommand or HystrixObservableCommand ● Timing-out calls when needed. ● Maintaining a small thread-pool for each dependency (monitor load) ● Measuring successes, failures , timeouts, and thread rejections. ● Tripping a circuit-breaker to stop all requests to a particular service for a period of time ● Performing fallback logic when a request fails, is rejected, times-out, or short-circuits. ● Monitoring metrics and configuration changes in near real-time. For Additional information: https://github.com/Netflix/Hystrix/wiki/How-it-Works
  • 11. Archaius Java library that provides APIs to access and utilize properties that can change dynamically at runtime. It includes the following features: ● Dynamic, Typed Properties ● High throughput and Thread Safe Configuration operations ● A polling framework that allows users to obtain property changes to a Configuration Source ● Allows retrieval of properties from local properties files or a properties server ○ Darchaius.configurationSource.additi onalUrls=file:///apps/myapp/applicatio n.properties ○ Darchaius.configurationSource.additi onalUrls=http://myserver/properties ● Automatically updates to all servers
  • 13. • Java 8 • Netflix OSS (Eureka, Hystrix, Zuul, Archaius) • Datastax (Cassandra) • Swagger Backend Tech Platform Tech • Maven • Docker • Spinnaker Documentation Tech • Swagger • Ascii Docs
  • 14. Time to Look at Some Code Netflix OSS • Zuul • Eureka • Hystrix • Archaius
  • 15. Zuul - Example of Zuul Configuration - pom.xml • In MSL, we configure Zuul via the pom.xml and Archaius properties • So here you see the pom.xml: Zuul runs in jetty We can supply additional configuration via Archaius Zuul will listen on port 9000 Example: <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>${jetty-version}</version> <configuration> <systemProperties> <systemProperty> <name>archaius.deployment.applicationId</name> <value>zuul</value> </systemProperty> </systemProperties> . . . <httpConnector> <port>9000</port> </httpConnector> </configuration> </plugin> References: github.com/kenzanlabs/msl-zuul
  • 16. Zuul - Example of Zuul Configuration - properties • In MSL, we configure Zuul via the pom.xml and Archaius properties: Locations of the pre, routing and post filters Allowable and default clients Configuration for one of those clients • And an example of a URL Notice it goes to port 9000 Has the client name loginedge Then the rest of the URL is the URI to the client • So Zuul redirects this request to login-edge:9001 Properties: zuul.filter.pre.path=src/main/groovy/filters/pre zuul.filter.routing.path=src/main/groovy/filters/route zuul.filter.post.path=src/main/groovy/filters/post zuul.niws.clientlist=loginedge|accountedge|catalogedge|ratingsedge loginedge.zuul.client.DeploymentContextBasedVipAddresses=msl.log in.edge loginedge.zuul.client.Port=9001 Example URL: https://msl.kenzanlabs.com:9000/loginedge/login References: github.com/kenzanlabs/msl-zuul/tree/master/src/main/resources
  • 17. Eureka Example • Registration Tell Eureka Server that a new instance of a microservice has started Needs eureka properties Needs Karyon to be instantiated Handles routine heartbeat from client to server • Healthcheck Allows Eureka Server to check if instance is still up and running Eureka Server will remove any down instance Properties: eureka.name=loginedge eureka.vipAddress=msl.login.edge eureka.port=9001 eureka.serviceUrl.default=http://localhost:8080/eureka/v2/ eureka.region=default eureka.preferSameZone=true eureka.registration.enabled=true Karyon Startup: KaryonServer server = new KaryonServer(); server.start(); Healthcheck ReST Endpoint: @Path("/healthcheck") public class HealthCheckResource { @GET @Produces(MediaType.APPLICATION_JSON) public Response healthcheck() { return Response.status(Response.Status.OK).build(); } }
  • 18. Hystrix example Setup • Create a subclass of HystrixCommand • The command group key groups commands for configuration, thread pooling, etc. • Override the run() method • Optionally override the getFallback() method Calling • Instantiate your command class • Call its execute() method Code: class ValidateAccountCommand extends HystrixCommand<Boolean> { private Account account; protected ValidateAccountCommand(Account account) { super(Setter.withGroupKey(HystrixCommandGroupKey.Factory .asKey("validateAccount"))); this.account = account; } @Override protected Boolean run() throws Exception { return AccountValidator.isValid(account); } @Override protected Boolean getFallback() { return false; } } public Boolean save(Account account) throws Exception { return (new ValidateAccountCommand(account).execute()); }
  • 19. Archaius Example• Configuration Declare the properties source(s) Can be a local file or a properties server • Use Properties are typed Boolean Int Long String etc. Only need to declare the DynamicXProperty once Then just use x.get() whenever you need to use the value Calling x.get() once and storing the result is an anti-pattern - doesn’t allow for dynamic reconfiguration Properties: archaius.configurationSource.additionalUrls= file://msl-login-edge-config/edge-config.properties or archaius.configurationSource.additionalUrls=http://myserver/properties Code: static final DynamicLongProperty timeToWait = DynamicPropertyFactory .getInstance().getLongProperty("msl.sleep", 100); void foo() { long t = timeToWait.get(); sleep(t) } Anti-pattern: static final long t = DynamicPropertyFactory .getInstance().getLongProperty("msl.sleep", 100).get(); void foo() { sleep(t) }
  • 20. Why? • The API is described in one place, a yaml formatted file (can also be described using annotations in an existing Java file) • From the yaml file, swagger tools generate client and server code stubs, and documentation • Since code and documentation are created from the same yaml file, the code and the documentation will never diverge Swagger - What? A specification and associated tools for describing, producing, consuming, and visualizing a ReST API YAML File: . . . /catalog-edge/browse/album: x-swagger-router-controller: catalog_controller get: description: "Get browsing data for albums in the catalog" tags: - Catalog operationId: browse_albums parameters: - $ref: "#/parameters/PagingState" - $ref: "#/parameters/Items" - $ref: "#/parameters/Facets" responses: "200": description: Success schema: $ref: "#/definitions/AlbumList" "400": description: “Invalid pagingState or facet” . . . Yaml Details • First line defines the URI path to the endpoint • tags: grouping endpoints for docs • x-swagger-router-controller: the name of the Node controller file • operationId: name of the function in server stub • parameters: optional path and query parameters
  • 21. Swagger - Generated Server Stub CatalogEdgeApi.java @Path("/catalog-edge") @Consumes({ "application/json" }) @Produces({ "application/json" }) public class CatalogEdgeApi { private final CatalogEdgeApiService delegate = CatalogEdgeApiServiceFactory.getCatalogEdgeApi(); @GET @Path("/browse/album") @Consumes({ "application/json" }) @Produces({ "application/json" }) public Response browseAlbums( @QueryParam("items") Integer items, @QueryParam("pagingState") String pagingState, @QueryParam("facets") String facets) ) throws NotFoundException { return delegate.browseAlbums(items,pagingState,facets); } ... } CatalogEdgeApiService.java public abstract class CatalogEdgeApiService { public abstract Response browseAlbums(Integer items,String pagingState,String facets) throws NotFoundException; }
  • 22. MSL Local Installation Prerequisites ● git installed ● personal git account created CD to where you want to install it cd ~ Retrieve the main MSL repository from github git clone https://github.com/kenzanmedia/million-song-library CD into the new directory cd million-song-library/bin Be sure the setup script is executable chmod +x setup.sh Run the setup script ./setup.sh
  • 23. Want to learn more? Follow us! @kenzanmedia www.linkedin.com/company/kenzan-media techblog.kenzan.com www.facebook.com/kenzanmedia/