SlideShare a Scribd company logo
Architecting for the Cloud
- The Netflix Way!
Codemash PreCompiler Workshop
- Jan 8th 2014

Sudhir Tonse
Manager, Cloud Platform Infrastructure
@stonse
NETFLIX
Netflix is the world’s leading Internet television
network with more than 40 million members in >40
countries enjoying more than one billion hours of TV
shows and movies per month, including original
series.
NETFLIX SCALE
•  100s of Mid-tier services and applications
•  Billions of Requests per day
•  ~70 Billion Events per day
•  10,000s of Ec2 Instances in use in multiple AWS Regions/
Zones
•  Cassandra NoSQL database in a Global Ring spanning
regions: Terabytes of data
•  At peak consumes ~1/3 of US Internet Bandwidth
I am PaaS (and so can You!)

Your Cloud PaaS

@stonse
Presentation & Workshop

@stonse
Agenda
• 

PaaS? What is it good for?

• 

NetflixOSS -> Build your own PaaS the Netflix Way!
•  What you need to build, deploy and operate a Cloud Native set of applications
•  Cloud Native Architecture
•  Platform Services -> Application Services on top of IaaS
•  Platform Libraries -> Application Framework Libraries
•  Platform Tools/Operational Utilities -> Helps deploy and manage your
Cloud Apps

• 

@stonse

Build your own Web Service using NetflixOSS libraries
PaaS? What is it?

Libraries, Tools and Frameworks that enable
one to Build, Deploy and Manage Software
Services on Ephemeral, On Demand Virtual
Machines (IaaS)
@stonse
@stonse
Netflix Cloud Stack (IaaS, PaaS, SaaS, Cloud Management)

@stonse

Virtualization Technologies
Netflix Cloud Stack
Clients
Browsers, Mobile, Televisions …

Applications/Web Services

PaaS
Execution Env (JVM), Web/App Servers, Frameworks, Tools

IaaS
Virtual Machines, Networking, Load Balancers …

@stonse

Netflix
Apps/Services
@stonse
You can too!

@stonse

Virtualization Technologies
Build Your Own PaaS

@stonse
Build Your Own PaaS
• 

Yes you can!
•  Others have done it
•  Yes, on non-AWS environments too!!

@stonse
Architecting for the Cloud using NetflixOSS - Codemash Workshop
Cloud Native Architecture
The Netflix Way!?
Bus +

Freedom

Dev

+ Ops

Responsibility

Culture

@stonse

BusDevOps
Think …

Cloud Native Architecture

@stonse

More at http://www.siia.net/presentations/software/
AATC2013/OpenSourceAtNetflix.pdf

- Adrian Cockroft (@adrianco)
Fine-Grained Reliable, Available, Distributed Service
Oriented Architecture
- that supports Rapid Iteration/innovation

@stonse
Architectural Insights

@stonse

Slide courtesy @adrianco
Architectural Insights

@stonse

Courtesy @adrianco
TYPICAL DEPLOYMENT
• 

Multiple Availability Zone

• 

Multiple Regions

@adrianco
Active: Active Deployment

@stonse
Active: Active Deployment

@stonse
•  RPS
•  Load Average

Slow Growth

Predictable Bursts

Compute

•  …

Time

Time

Compute

•  Use CloudWatch

Time
Periodic Jobs

Compute

Scale UP & Down based on
Demand

Compute

• 

Compute

ON DEMAND AUTO SCALING!

Time

Unpredictable Bursts

Time
Steady State
Instance

Instance
Instance
Instance

Instance
Instance

Instance

Instance

Scale Up
Instance

Instance
Instance
Instance

Instance

Scale Up
Scale Down
Instance
Instance

Instance
Instance

Instance

Instance

Instance
LIFECYCLE
• 

Think, Implement, Deploy, Test, Operate
AWS SERVICES (IAAS)

As of Jan 2014
@stonse
Platform Services + Application Framework
Libraries + Operational Tools
Your Cloud PaaS!!

OR

@stonse

Other IaaS
Platform Runtime Services
Metadata
Registry
Eureka

Monitoring
Services
Turbine

Distributed
Coordinator/Registry
(Zookeeper)

Distributed Cache

Exhibitor

EVCache

Metrics
Services
Servo +

AWS Resources
Lifecycle Service

AWS CloudWatch

Edda

SQS

@stonse
Platform Libraries - Application Container/Framework
Function

NetflixOSS Library

REST Framework/Bootstrapping/DI

Karyon/Governator

Functional Reactive Programming

RxJava

Resiliency/Fallback

Hystrix

RPC (Routing/LB)

Ribbon/Eureka

Distributed Co-ordination (Zookeeper)

Curator

Distributed Caching

EVCache

NoSQL (Cassandra) Persistence

Data Access/Caching

Astyanax

Monitoring

Turbine

Metrics

Servo

Logging

Blitz4J

Properties/Configuration

@stonse

Service Requests

Archaius

Config/Insights
Platform Big Data/Caching & Services
Cassandra NoSQL

@stonse

Astyanax
Priam
CassJMeter

Hadoop Platform As a Service

Genie
Lipstick
Platform Tools & Services
Deployment/Workflow

@stonse

Asgard

Frigga

Glisten

Aminator

Availability, Resiliency, Costing,
Monitoring (Ops Tools)

SimianArmy
ICE
Soon ….

@stonse
How do I get Started?
Workshop Session …
How do I create an App/Service?

Instructions at http://bit.ly/1dlDyVC
@stonse
Sample Application – RSS Reader

http://techblog.netflix.com/2013/03/introducing-first-netflixoss-recipe-rss.html
@stonse
STEP 1
Choice A: Bare bones Web Service Template
$git clone https://github.com/Netflix/karyon.git
$cd karyon
$./gradlew clean build
$./gradlew :karyon-examples:hello-netflixoss:jettyRun
Choice B: Full blown Recipe (RSS Reader
Recipe)
$git clone https://github.com/Netflix/recipes-rss.git
$cd recipes-rss
$./gradlew clean build

@stonse
STEP 2
• 

Customize your App using .war of previous step as a template
•  TIPS (optional)
•  Use Ribbon for RPC calls
•  Use Hystrix/RxJava for wrapping concurrent calls/RPC calls (Latency/Fault
Tolerance)

@stonse
STEP 3
• 

@stonse

Bake an AMI (Amazon Machine Image) using NetflixOSS Aminator
STEP 4
• 

Deploy to EC2 using Asgard

Deploy & Manage AWS
Applications/Infrastructure

•  TIP: Employ Simian Army to test Resiliency

@stonse
Building Apps and AMIs

@stonse
Building Apps and AMIs

App

Karyon

Build

WAR
Deploy

Aminator

Asgard

ASG /Cluster
Launch Instances
App
AMI
ASG/Cluster
@stonse
Your Cloud!

Metadata
Registry
Eureka
App
AMI
Billing ASG

@stonse

Ribbon (RPC)

App
AMI

Credit P ASG

App
AMI
Order P ASG
Libraries and Services in (some) Detail ...
Eureka: Metadata Registry as a Service

@stonse
Eureka: Metadata Registry as a Service
Ribbon: RPC Library (with Software Load Balancers)

@stonse
RIBBON (RPC) CALL
try {

RestClient client = (RestClient)
ClientFactory.getNamedClient("FlixmashClient");

HttpRequest request = HttpRequest.newBuilder().uri(new URI("/
flixmash/rest/v1/movies/popularMovies")).build();
response = client.executeWithLoadBalancer(request);
String movies = response.getEntity(String.class);
return movies;
} catch (Exception exc) {
throw new RuntimeException("Exception", exc);
} finally {
if (response!=null){
//hand the connection back to the pool
response.close();
}
}
Archaius: Configuration (properties) as a Service
• 

Property Driven Development

for (int i=0; I < numRowsProperty.get(); i++){
fetchMovieForRow(i, numMoviePerRowProperty.get());
}

@stonse
Archaius: Configuration (properties) as a Service

@stonse
Archaius: Configuration (properties) as a Service

@stonse
Curator + Exhibitor: Distributed Sync & Coordination
Services
(Zookeeper)

http://curator.incubator.apache.org/

@stonse
Hystrix: Defend your App

@stonse
Hystrix: Defend your App

@stonse
Architecting for the Cloud using NetflixOSS - Codemash Workshop
Libraries/Services/Framework for Operations
Deploy ..

@stonse
Asgard: Deployment

@stonse
Glisten: Orchestration/Workflow

@stonse
Observe/Monitor …

@stonse

Insights
Servo (+ AWS CloudWatch): Metrics as a Service

JMX

CloudWatch

@stonse
Turbine: Hystrix Dashboard (Real Time Metrics
Aggregator)
• 
• 

@stonse

Low Latency, High Throughput Stream
Processing Engine
Real Time Metrics Dashboard
Edda: Lifecycle (AWS resource) Blogger as a Service

@stonse
ICE : AWS Resource Usage (Cost)

@stonse
Are you Resilient?

@stonse
Simian Army: Availability/Resiliency as a Service
• 

Chaos Monkey
•  Kills instances

• 

Janitor Monkey
•  Clean up unused Resources

• 

Conformity Monkey
•  Confirms adherence to Best
Practices

• 

Others (yet to be open sourced)
•  Latency Monkey
•  Chaos Kong
•  …

@stonse
Monkeys Contd …

@stonse
Advanced Topics …

Predictive Auto Scaling Engine

http://techblog.netflix.com
@stonse
Genie: Hadoop Platform as a Service

@stonse

Jeff Magnusson: Tomorrow at
QConSF
Other Open Source Components (you can use)

+ Many Many More ….

@stonse
Further Reading …
• 

http://techblog.netflix.com

• 

http://slideshare.net/netflix

• 

http://netflix.github.io

• 

http://fluxcapacitor.com
•  https://github.com/cfregly/fluxcapacitor/wiki/NetflixOSS-FAQ

@stonse
Workshop …
Hands On: Building Hello Netflix OSS application
• 

Concepts
• 
• 

Configuration

• 

Build Script (gradle)

• 

Application Container/Bootstrap

• 

JSR-311 Web Resource

• 

Properties via Archaius

• 

Metrics via Servo

• 

Dependency Injection via Governator/Guice

• 

RPC calls via Ribbon/Eureka

• 

Resiliency via Hystrix (wrappers on top of Ribbon)

• 

Invoking a Mid-tier Web Service

• 

@stonse

Project Layout

AdminConsole (port 8077)
Workshop …
Hands On: Building Hello Netflix OSS application
• 

@stonse

Instructions at http://bit.ly/1dlDyVC
Project Layout

@stonse
Project Layout
Application Container /Bootstrap
Located at https://netflix.box.com/s/suk5qlis3sn9f2sz44dl
public class HelloWorldBootstrap extends
ServerBootstrap {
@Override
protected void
beforeInjectorCreation(LifecycleInjectorBuilder
builderToBeUsed) {
builderToBeUsed.withAdditionalModules(new
JerseyServletModule() {
@Override
protected void configureServlets() {
Map<String, String> params =
Maps.newHashMap();
params.put(PackagesResourceConfig.PROPERTY_PACKA
GES, "com.netflix.hellonoss, com.netflixoss.workshop");
serve("/rest/v1/
*").with(GuiceContainer.class, params);
binder().bind(GuiceContainer.class).asEagerSingleton();
}
});
}
}
JSR-311 Web Resource
1. Hello World Resource -> https://netflix.box.com/s/
nyspqi1an095d4p5xd7k
2. Flixmash Resource -> https://netflix.box.com/s/
nb1nd7bqk7qcmxnwuol0
@Path("/flixmash")
public class FlixmashResource {
@GET
@Path("popularMovies")
@Produces({MediaType.APPLICATION_JSON})
public Response movies() {
// Start timer
Stopwatch stopwatch = getMoviesTimer.start();
JSONObject response = new JSONObject();
try {
getMoviesCounter.increment();
response.put("Movies",
flixmashManager.getPopularMovies()); // obtain movies from our
flixMovies component
return Response.ok(response.toString()).build();
} catch (JSONException e) {
getMoviesErrorCounter.increment();
logger.error("Error creating json response.", e);
return
Response.status(Response.Status.INTERNAL_SERVER_ERROR).build
();
} finally {
stopwatch.stop();
}
}
ARCHAIUS: PROPERTIES
flixmash.popularMovieList=Lord of the Ring,Matrix,Harry Potter,Gravity
private static final DynamicStringListProperty popularMovieList
= new DynamicStringListProperty("flixmash.popularMovieList",
(List<String>) null);
List<String> movies = popularMovieList.get();
SERVO METRICS
// JMX: com.netflix.servo.COUNTER.FlixMash.getMovies
private static final Counter getMoviesCounter = new
BasicCounter(MonitorConfig.builder("FlixMash.getMoviesCounter").build
());
DefaultMonitorRegistry.getInstance().register(getMoviesCounter);
@GET
@Path("popularMovies")
@Produces({MediaType.APPLICATION_JSON})
public Response movies() {
try {
getMoviesCounter.increment();
…
}catch (Exception e){
}
}
SERVO METRICS IN JMX
KARYON’S ADMIN CONSOLE
Takeaways …
• 

Cloud Computing and Cloud based Services requires embracing Cloud Native

- Adrian Cockroft (@adrianco)
• 

NetflixOSS is here to help!
•  You can build your own custom PaaS the Netflix Way!

http://netflix.github.io
@stonse

Yes, we are Hiring!
CODEMASH
NETFLIX
SESSIONS

More Related Content

Architecting for the Cloud using NetflixOSS - Codemash Workshop