hadoop application architectures tutorial - strata london

159
Architectural Considerations for Hadoop Applications Strata+Hadoop World, London– May 5 th , 2015 tiny.cloudera.com/app-arch-london Mark Grover | @mark_grover Ted Malaska | @TedMalaska Jonathan Seidman | @jseidman Gwen Shapira | @gwenshap

Upload: hadooparchbook

Post on 15-Jul-2015

758 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Hadoop Application Architectures tutorial - Strata London

Architectural Considerations for Hadoop Applications Strata+Hadoop World, London– May 5th, 2015 tiny.cloudera.com/app-arch-london

Mark Grover | @mark_grover Ted Malaska | @TedMalaska Jonathan Seidman | @jseidman Gwen Shapira | @gwenshap

Page 2: Hadoop Application Architectures tutorial - Strata London

2

About the book •  @hadooparchbook •  hadooparchitecturebook.com •  github.com/hadooparchitecturebook •  slideshare.com/hadooparchbook

©2014 Cloudera, Inc. All Rights Reserved.

Page 3: Hadoop Application Architectures tutorial - Strata London

3

About the presenters

•  Principal Solutions Architect at Cloudera

•  Previously, lead architect at FINRA

•  Contributor to Apache Hadoop, HBase, Flume, Avro, Pig and Spark

•  Senior Solutions Architect/Partner Enablement at Cloudera

•  Contributor to Apache Sqoop.

•  Previously, Technical Lead on the big data team at Orbitz, co-founder of the Chicago Hadoop User Group and Chicago Big Data

©2014 Cloudera, Inc. All Rights Reserved.

Ted Malaska Jonathan Seidman

Page 4: Hadoop Application Architectures tutorial - Strata London

4

About the presenters

•  Solutions Architect turned Software Engineer at Cloudera

•  Committer on Apache Sqoop

•  Contributor to Apache Flume and Apache Kafka

•  Software Engineer at Cloudera

•  Committer on Apache Bigtop, PMC member on Apache Sentry (incubating)

•  Contributor to Apache Hadoop, Spark, Hive, Sqoop, Pig and Flume

©2014 Cloudera, Inc. All Rights Reserved.

Gwen Shapira Mark Grover

Page 5: Hadoop Application Architectures tutorial - Strata London

5

Logistics •  Break at 10:30-11:00 AM •  Questions at the end of each section

©2014 Cloudera, Inc. All Rights Reserved.

Page 6: Hadoop Application Architectures tutorial - Strata London

6

Case Study Clickstream Analysis

Page 7: Hadoop Application Architectures tutorial - Strata London

7

Analytics

©2014 Cloudera, Inc. All Rights Reserved.

Page 8: Hadoop Application Architectures tutorial - Strata London

8

Analytics

©2014 Cloudera, Inc. All Rights Reserved.

Page 9: Hadoop Application Architectures tutorial - Strata London

9

Analytics

©2014 Cloudera, Inc. All Rights Reserved.

Page 10: Hadoop Application Architectures tutorial - Strata London

10

Analytics

©2014 Cloudera, Inc. All Rights Reserved.

Page 11: Hadoop Application Architectures tutorial - Strata London

11

Analytics

©2014 Cloudera, Inc. All Rights Reserved.

Page 12: Hadoop Application Architectures tutorial - Strata London

12

Analytics

©2014 Cloudera, Inc. All Rights Reserved.

Page 13: Hadoop Application Architectures tutorial - Strata London

13

Analytics

©2014 Cloudera, Inc. All Rights Reserved.

Page 14: Hadoop Application Architectures tutorial - Strata London

14

Web Logs – Combined Log Format

©2014 Cloudera, Inc. All Rights Reserved.

244.157.45.12 - - [17/Oct/2014:21:08:30 ] "GET /seatposts HTTP/1.0" 200 4463 "http://bestcyclingreviews.com/top_online_shops" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36” 244.157.45.12 - - [17/Oct/2014:21:59:59 ] "GET /Store/cart.jsp?productID=1023 HTTP/1.0" 200 3757 "http://www.casualcyclist.com" "Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1”

Page 15: Hadoop Application Architectures tutorial - Strata London

15

Clickstream Analytics

©2014 Cloudera, Inc. All Rights Reserved.

244.157.45.12 - - [17/Oct/2014:21:08:30 ] "GET /seatposts HTTP/1.0" 200 4463 "http://bestcyclingreviews.com/top_online_shops" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36”

Page 16: Hadoop Application Architectures tutorial - Strata London

16

Similar use-cases •  Sensors – heart, agriculture, etc. •  Casinos – session of a person at a table

©2014 Cloudera, Inc. All Rights Reserved.

Page 17: Hadoop Application Architectures tutorial - Strata London

17

Pre-Hadoop Architecture Clickstream Analysis

Page 18: Hadoop Application Architectures tutorial - Strata London

18

Click Stream Analysis (Before Hadoop)

©2014 Cloudera, Inc. All Rights Reserved.

Web logs (full fidelity) (2 weeks)

Data Warehouse Transform/Aggregate Business

Intelligence

Tape Archive

Page 19: Hadoop Application Architectures tutorial - Strata London

19

Problems with Pre-Hadoop Architecture •  Full fidelity data is stored for small amount of time (~weeks). •  Older data is sent to tape, or even worse, deleted! •  Inflexible workflow - think of all aggregations beforehand

©2014 Cloudera, Inc. All Rights Reserved.

Page 20: Hadoop Application Architectures tutorial - Strata London

20

Effects of Pre-Hadoop Architecture •  Regenerating aggregates is expensive or worse, impossible •  Can’t correct bugs in the workflow/aggregation logic •  Can’t do experiments on existing data

©2014 Cloudera, Inc. All Rights Reserved.

Page 21: Hadoop Application Architectures tutorial - Strata London

21

Why is Hadoop A Great Fit? Clickstream Analysis

Page 22: Hadoop Application Architectures tutorial - Strata London

22

Why is Hadoop a great fit? •  Volume of clickstream data is huge •  Velocity at which it comes in is high •  Variety of data is diverse - semi-structured data •  Hadoop enables

–  active archival of data –  Aggregation jobs –  Querying the above aggregates or raw fidelity data

©2014 Cloudera, Inc. All Rights Reserved.

Page 23: Hadoop Application Architectures tutorial - Strata London

23

Click Stream Analysis (with Hadoop)

©2014 Cloudera, Inc. All Rights Reserved.

Web logs Hadoop Business Intelligence

Active archive (no tape) Aggregation engine Querying engine

Page 24: Hadoop Application Architectures tutorial - Strata London

24

Challenges of Hadoop Implementation

©2014 Cloudera, Inc. All Rights Reserved.

Page 25: Hadoop Application Architectures tutorial - Strata London

25

Challenges of Hadoop Implementation

©2014 Cloudera, Inc. All Rights Reserved.

Page 26: Hadoop Application Architectures tutorial - Strata London

26

Other challenges - Architectural Considerations •  Storage managers?

–  HDFS? HBase? •  Data storage and modeling:

–  File formats? Compression? Schema design? •  Data movement

–  How do we actually get the data into Hadoop? How do we get it out? •  Metadata

–  How do we manage data about the data? •  Data access and processing

–  How will the data be accessed once in Hadoop? How can we transform it? How do we query it?

•  Orchestration –  How do we manage the workflow for all of this?

©2014 Cloudera, Inc. All Rights Reserved.

Page 27: Hadoop Application Architectures tutorial - Strata London

27

Case Study Requirements Overview of Requirements

Page 28: Hadoop Application Architectures tutorial - Strata London

28

Overview of Requirements

Data Sources Ingestion

Raw Data Storage

(Formats, Schema)

Processed Data Storage

(Formats, Schema)

©2014 Cloudera, Inc. All Rights Reserved.

Processing Data Consumption

Orchestration (Scheduling, Managing, Monitoring)

Page 29: Hadoop Application Architectures tutorial - Strata London

29

Case Study Requirements Data Ingestion

Page 30: Hadoop Application Architectures tutorial - Strata London

30

Data Ingestion Requirements

©2014 Cloudera, Inc. All Rights Reserved.

Web Servers Web Servers

Web Servers Web Servers

Web Servers Logs

244.157.45.12 - - [17/Oct/2014:21:08:30 ]

"GET /seatposts HTTP/1.0" 200 4463 …

CRM Data

ODS Web Servers

Web Servers Web Servers

Web Servers Web Servers

Logs

Hadoop

Page 31: Hadoop Application Architectures tutorial - Strata London

31

Data Ingestion Requirements •  So we need to be able to support:

–  Reliable ingestion of large volumes of semi-structured event data arriving with high velocity (e.g. logs).

–  Timeliness of data availability – data needs to be available for processing to meet business service level agreements.

–  Periodic ingestion of data from relational data stores.

©2014 Cloudera, Inc. All Rights Reserved.

Page 32: Hadoop Application Architectures tutorial - Strata London

32

Case Study Requirements Data Storage

Page 33: Hadoop Application Architectures tutorial - Strata London

33

Data Storage Requirements

©2014 Cloudera, Inc. All Rights Reserved.

Store all the data Make the data accessible for

processing

Compress the data

Page 34: Hadoop Application Architectures tutorial - Strata London

34

Case Study Requirements Data Processing

Page 35: Hadoop Application Architectures tutorial - Strata London

35

Processing requirements Be able to answer questions like: •  What is my website’s bounce rate?

–  i.e. how many % of visitors don’t go past the landing page?

•  Which marketing channels are leading to most sessions? •  Do attribution analysis

–  Which channels are responsible for most conversions?

©2014 Cloudera, Inc. All Rights Reserved.

Page 36: Hadoop Application Architectures tutorial - Strata London

36

Sessionization

©2014 Cloudera, Inc. All Rights Reserved.

Website visit

Visitor 1 Session 1

Visitor 1 Session 2

Visitor 2 Session 1

> 30 minutes

Page 37: Hadoop Application Architectures tutorial - Strata London

37

Case Study Requirements Orchestration

Page 38: Hadoop Application Architectures tutorial - Strata London

38

Orchestration is simple We just need to execute actions One after another

©2014 Cloudera, Inc. All Rights Reserved.

Page 39: Hadoop Application Architectures tutorial - Strata London

39 ©2014 Cloudera, Inc. All Rights Reserved.

Actually, we also need to handle errors And user notifications ….

Page 40: Hadoop Application Architectures tutorial - Strata London

40 ©2014 Cloudera, Inc. All Rights Reserved.

And… •  Re-start workflows after errors •  Reuse of actions in multiple workflows •  Complex workflows with decision points •  Trigger actions based on events •  Tracking metadata •  Integration with enterprise software •  Data lifecycle •  Data quality control •  Reports

Page 41: Hadoop Application Architectures tutorial - Strata London

41 ©2014 Cloudera, Inc. All Rights Reserved.

OK, maybe we need a product To help us do all that

Page 42: Hadoop Application Architectures tutorial - Strata London

42

Architectural Considerations Data Modeling

Page 43: Hadoop Application Architectures tutorial - Strata London

43

Data Modeling Considerations •  We need to consider the following in our architecture:

–  Storage layer – HDFS? HBase? Etc. –  File system schemas – how will we lay out the data? –  File formats – what storage formats to use for our data, both raw and

processed data? –  Data compression formats?

©2014 Cloudera, Inc. All Rights Reserved.

Page 44: Hadoop Application Architectures tutorial - Strata London

44

Architectural Considerations Data Modeling – Storage Layer

Page 45: Hadoop Application Architectures tutorial - Strata London

45

Data Storage Layer Choices •  Two likely choices for raw data:

©2014 Cloudera, Inc. All Rights Reserved.

Page 46: Hadoop Application Architectures tutorial - Strata London

46

Data Storage Layer Choices

•  Stores data directly as files •  Fast scans •  Poor random reads/writes

•  Stores data as Hfiles on HDFS

•  Slow scans •  Fast random reads/writes

©2014 Cloudera, Inc. All Rights Reserved.

Page 47: Hadoop Application Architectures tutorial - Strata London

47

Data Storage – Storage Manager Considerations

•  Incoming raw data: –  Processing requirements call for batch transformations across multiple

records – for example sessionization.

•  Processed data: –  Access to processed data will be via things like analytical queries – again

requiring access to multiple records.

•  We choose HDFS –  Processing needs in this case served better by fast scans.

©2014 Cloudera, Inc. All Rights Reserved.

Page 48: Hadoop Application Architectures tutorial - Strata London

48

Architectural Considerations Data Modeling – Raw Data Storage

Page 49: Hadoop Application Architectures tutorial - Strata London

49

Storage Formats – Raw Data and Processed Data

©2014 Cloudera, Inc. All Rights Reserved.

Processed Data

Raw Data

Page 50: Hadoop Application Architectures tutorial - Strata London

50

Data Storage – Format Considerations

Click to enter confidentiality information

Logs (plain text)

Page 51: Hadoop Application Architectures tutorial - Strata London

51

Data Storage – Format Considerations

Click to enter confidentiality information

Logs (plain text)

Logs (plain text)

Logs (plain text)

Logs (plain text)

Logs (plain text)

Logs (plain text)

Logs

Logs Logs

Logs Logs

Page 52: Hadoop Application Architectures tutorial - Strata London

52

Data Storage – Compression

Click to enter confidentiality information

snappy

Well, maybe. But not splittable.

X Splittable. Getting better…

Hmmm…. Splittable, but no...

Page 53: Hadoop Application Architectures tutorial - Strata London

53

Raw Data Storage – More About Snappy •  Designed at Google to provide high compression speeds with reasonable

compression. •  Not the highest compression, but provides very good performance for

processing on Hadoop. •  Snappy is not splittable though, which brings us to…

©2014 Cloudera, Inc. All Rights Reserved.

Page 54: Hadoop Application Architectures tutorial - Strata London

54

Hadoop File Types •  Formats designed specifically to store and process data on Hadoop:

–  File based – SequenceFile –  Serialization formats – Thrift, Protocol Buffers, Avro –  Columnar formats – RCFile, ORC, Parquet

Click to enter confidentiality information

Page 55: Hadoop Application Architectures tutorial - Strata London

55

SequenceFile

• Stores records as binary key/value pairs.

• SequenceFile “blocks” can be compressed.

•  This enables splittability with non-splittable compression.

©2014 Cloudera, Inc. All Rights Reserved.

Page 56: Hadoop Application Architectures tutorial - Strata London

56

Avro

• Kinda SequenceFile on Steroids.

• Self-documenting – stores schema in header.

• Provides very efficient storage.

• Supports splittable compression. ©2014 Cloudera, Inc. All Rights Reserved.

Page 57: Hadoop Application Architectures tutorial - Strata London

57

Our Format Recommendations for Raw Data…

•  Avro with Snappy –  Snappy provides optimized compression. –  Avro provides compact storage, self-documenting files, and supports schema

evolution. –  Avro also provides better failure handling than other choices.

•  SequenceFiles would also be a good choice, and are directly supported by ingestion tools in the ecosystem. –  But only supports Java.

©2014 Cloudera, Inc. All Rights Reserved.

Page 58: Hadoop Application Architectures tutorial - Strata London

58

But Note… •  For simplicity, we’ll use plain text for raw data in our example.

©2014 Cloudera, Inc. All Rights Reserved.

Page 59: Hadoop Application Architectures tutorial - Strata London

59

Architectural Considerations Data Modeling – Processed Data Storage

Page 60: Hadoop Application Architectures tutorial - Strata London

60

Storage Formats – Raw Data and Processed Data

©2014 Cloudera, Inc. All Rights Reserved.

Processed Data

Raw Data

Page 61: Hadoop Application Architectures tutorial - Strata London

61

Access to Processed Data

©2014 Cloudera, Inc. All Rights Reserved.

Column A Column B Column C Column D Value Value Value Value Value Value Value Value Value Value Value Value Value Value Value Value

Analytical Queries

Page 62: Hadoop Application Architectures tutorial - Strata London

62

Columnar Formats •  Eliminates I/O for columns that are not part of a query. •  Works well for queries that access a subset of columns. •  Often provide better compression. •  These add up to dramatically improved performance for many

queries.

©2014 Cloudera, Inc. All Rights Reserved.

1 2014-10-13

abc

2 2014-10-14

def

3 2014-10-15

ghi

1 2 3

2014-10-13

2014-10-14

2014-10-15

abc def ghi

Page 63: Hadoop Application Architectures tutorial - Strata London

63

Columnar Choices – RCFile •  Designed to provide efficient processing for Hive queries. •  Only supports Java. •  No Avro support. •  Limited compression support. •  Sub-optimal performance compared to newer columnar formats.

©2014 Cloudera, Inc. All Rights Reserved.

Page 64: Hadoop Application Architectures tutorial - Strata London

64

Columnar Choices – ORC •  A better RCFile. •  Also designed to provide efficient processing of Hive queries. •  Only supports Java.

©2014 Cloudera, Inc. All Rights Reserved.

Page 65: Hadoop Application Architectures tutorial - Strata London

65

Columnar Choices – Parquet •  Designed to provide efficient processing across Hadoop

programming interfaces – MapReduce, Hive, Impala, Pig. •  Multiple language support – Java, C++ •  Good object model support, including Avro. •  Broad vendor support. •  These features make Parquet a good choice for our processed data.

©2014 Cloudera, Inc. All Rights Reserved.

Page 66: Hadoop Application Architectures tutorial - Strata London

66

Architectural Considerations Data Modeling – Schema Design

Page 67: Hadoop Application Architectures tutorial - Strata London

67

HDFS Schema Design – One Recommendation

/etl – Data in various stages of ETL workflow /data – processed data to be shared data with the entire organization /tmp – temp data from tools or shared between users /user/<username> - User specific data, jars, conf files /app – Everything but data: UDF jars, HQL files, Oozie workflows

©2014 Cloudera, Inc. All Rights Reserved.

Page 68: Hadoop Application Architectures tutorial - Strata London

68

Partitioning •  Split the dataset into smaller consumable chunks. •  Rudimentary form of “indexing”. Reduces I/O needed to process

queries.

©2014 Cloudera, Inc. All Rights Reserved.

Page 69: Hadoop Application Architectures tutorial - Strata London

69

Partitioning

©2014 Cloudera, Inc. All Rights Reserved.

dataset col=val1/file.txt col=val2/file.txt … col=valn/file.txt

dataset file1.txt file2.txt … filen.txt

Un-partitioned HDFS directory structure

Partitioned HDFS directory structure

Page 70: Hadoop Application Architectures tutorial - Strata London

70

Partitioning considerations •  What column to partition by?

–  Don’t have too many partitions (<10,000) –  Don’t have too many small files in the partitions –  Good to have partition sizes at least ~1 GB, generally a multiple of block size.

•  We’ll partition by timestamp. This applies to both our raw and processed data.

©2014 Cloudera, Inc. All Rights Reserved.

Page 71: Hadoop Application Architectures tutorial - Strata London

71

Partitioning For Our Case Study •  Raw dataset:

–  /etl/BI/casualcyclist/clicks/rawlogs/year=2014/month=10/day=10!

•  Processed dataset: –  /data/bikeshop/clickstream/year=2014/month=10/day=10!

©2014 Cloudera, Inc. All Rights Reserved.

Page 72: Hadoop Application Architectures tutorial - Strata London

72

Architectural Considerations Data Ingestion

Page 73: Hadoop Application Architectures tutorial - Strata London

73 ©2014 Cloudera, Inc. All rights reserved.

•  Omniture data on FTP •  Apps •  App Logs •  RDBMS

Typical Clickstream data sources

Page 74: Hadoop Application Architectures tutorial - Strata London

74 ©2014 Cloudera, Inc. All rights reserved.

Getting Files from FTP

Page 75: Hadoop Application Architectures tutorial - Strata London

75 ©2014 Cloudera, Inc. All rights reserved.

curl ftp://myftpsite.com/sitecatalyst/myreport_2014-10-05.tar.gz --user name:password | hdfs -put - /etl/clickstream/raw/sitecatalyst/myreport_2014-10-05.tar.gz

Don’t over-complicate things

Page 76: Hadoop Application Architectures tutorial - Strata London

76 ©2014 Cloudera, Inc. All rights reserved.

Apache NiFi

Page 77: Hadoop Application Architectures tutorial - Strata London

77 ©2014 Cloudera, Inc. All rights reserved.

Reliable, distributed and highly available systems That allow streaming events to Hadoop

Event Streaming – Flume and Kafka

Page 78: Hadoop Application Architectures tutorial - Strata London

78 ©2014 Cloudera, Inc. All rights reserved.

•  Many available data collection sources •  Well integrated into Hadoop •  Supports file transformations •  Can implement complex topologies •  Very low latency •  No programming required

Flume:

Page 79: Hadoop Application Architectures tutorial - Strata London

79 ©2014 Cloudera, Inc. All rights reserved.

“We just want to grab data from this directory

and write it to HDFS”

We use Flume when:

Page 80: Hadoop Application Architectures tutorial - Strata London

80 ©2014 Cloudera, Inc. All rights reserved.

•  Very high-throughput publish-subscribe messaging •  Highly available •  Stores data and can replay •  Can support many consumers with no extra latency

Kafka is:

Page 81: Hadoop Application Architectures tutorial - Strata London

81 ©2014 Cloudera, Inc. All rights reserved.

“Kafka is awesome. We heard it cures cancer”

Use Kafka When:

Page 82: Hadoop Application Architectures tutorial - Strata London

82 ©2014 Cloudera, Inc. All rights reserved.

•  Use Flume with a Kafka Source •  Allows to get data from Kafka,

run some transformations write to HDFS, HBase or Solr

Actually, why choose?

Page 83: Hadoop Application Architectures tutorial - Strata London

83 ©2014 Cloudera, Inc. All rights reserved.

•  We want to ingest events from log files •  Flume’s Spooling Directory source fits •  With HDFS Sink

•  We would have used Kafka if… –  We wanted the data in non-Hadoop systems too

In Our Example…

Page 84: Hadoop Application Architectures tutorial - Strata London

84

Sources Interceptors Selectors Channels Sinks

Flume Agent

Short Intro to Flume Twitter, logs, JMS, webserver, Kafka

Mask, re-format, validate…

DR, critical Memory, file,

Kafka HDFS, HBase,

Solr

Page 85: Hadoop Application Architectures tutorial - Strata London

85

Configuration

• Declarative – No coding required. – Configuration specifies

how components are wired together.

©2014 Cloudera, Inc. All Rights Reserved.

Page 86: Hadoop Application Architectures tutorial - Strata London

86

Interceptors

• Mask fields • Validate information

against external source • Extract fields • Modify data format •  Filter or split events

©2014 Cloudera, Inc. All rights reserved.

Page 87: Hadoop Application Architectures tutorial - Strata London

87 ©2014 Cloudera, Inc. All rights reserved.

Any sufficiently complex configuration Is indistinguishable from code

Page 88: Hadoop Application Architectures tutorial - Strata London

88

A Brief Discussion of Flume Patterns – Fan-in •  Flume agent runs on

each of our servers. •  These client agents

send data to multiple agents to provide reliability.

•  Flume provides support for load balancing.

©2014 Cloudera, Inc. All Rights Reserved.

Page 89: Hadoop Application Architectures tutorial - Strata London

89

A Brief Discussion of Flume Patterns – Splitting •  Common need is to split

data on ingest. •  For example:

– Sending data to multiple clusters for DR.

– To multiple destinations. •  Flume also supports

partitioning, which is key to our implementation.

©2014 Cloudera, Inc. All Rights Reserved.

Page 90: Hadoop Application Architectures tutorial - Strata London

90

Flume Agent

Web Logs Spooling

Dir Source

Timestamp Interceptor

File Channel

Avro Sink Avro Sink Avro Sink

Flume Architecture – Client Tier Web Server Flume Agent

Page 91: Hadoop Application Architectures tutorial - Strata London

91

Flume Architecture – Collector Tier Flume Agent

Flume Agent

HDFS Avro

Source File

Channel HDFS Sink

HDFS Sink

Page 92: Hadoop Application Architectures tutorial - Strata London

92 ©2014 Cloudera, Inc. All rights reserved.

•  Add Kafka producer to our webapp •  Send clicks and searches as messages •  Flume can ingest events from Kafka •  We can add a second consumer for real-time

processing in SparkStreaming •  Another consumer for alerting… •  And maybe a batch consumer too

What if…. We were to use Kafka?

Page 93: Hadoop Application Architectures tutorial - Strata London

93

Channels Sinks

Flume Agent

The Kafka Channel Kafka HDFS, HBase,

Solr

Producer A

Producer B

Producer C

Kafka Producers

Page 94: Hadoop Application Architectures tutorial - Strata London

94

Sources Interceptors Channels

Flume Agent

The Kafka Channel Twitter, logs, JMS,

webserver Mask, re-format,

validate… Kafka

Consumer A

Kafka Consumers

Consumer B

Consumer C

Page 95: Hadoop Application Architectures tutorial - Strata London

95

Sources Interceptors Selectors Channels Sinks

Flume Agent

The Kafka Channel Twitter, logs, JMS,

webserver Mask, re-format,

validate… DR, critical Kafka HDFS, HBase,

Solr

Page 96: Hadoop Application Architectures tutorial - Strata London

96

Architectural Considerations Data Processing – Engines tiny.cloudera.com/app-arch-slides

Page 97: Hadoop Application Architectures tutorial - Strata London

97

Processing Engines •  MapReduce •  Abstractions •  Spark •  Spark Streaming •  Impala

Confidentiality Information Goes Here

Page 98: Hadoop Application Architectures tutorial - Strata London

98

MapReduce •  Oldie but goody •  Restrictive Framework / Innovated Work Around •  Extreme Batch

Confidentiality Information Goes Here

Page 99: Hadoop Application Architectures tutorial - Strata London

99

MapReduce Basic High Level

Confidentiality Information Goes Here

Mapper

HDFS (Replicated)

Native File System

Block of Data

Temp Spill Data

Partitioned Sorted Data

Reducer

Reducer Local Copy

Output File

Page 100: Hadoop Application Architectures tutorial - Strata London

100

MapReduce Innovation •  Mapper Memory Joins •  Reducer Memory Joins •  Buckets Sorted Joins •  Cross Task Communication •  Windowing •  And Much More

Confidentiality Information Goes Here

Page 101: Hadoop Application Architectures tutorial - Strata London

101

Abstractions •  SQL

–  Hive

•  Script/Code –  Pig: Pig Latin –  Crunch: Java/Scala –  Cascading: Java/Scala

Confidentiality Information Goes Here

Page 102: Hadoop Application Architectures tutorial - Strata London

102

Spark •  The New Kid that isn’t that New Anymore •  Easily 10x less code •  Extremely Easy and Powerful API •  Very good for machine learning •  Scala, Java, and Python •  RDDs •  DAG Engine

Confidentiality Information Goes Here

Page 103: Hadoop Application Architectures tutorial - Strata London

103

Spark - DAG

Confidentiality Information Goes Here

Page 104: Hadoop Application Architectures tutorial - Strata London

104

Spark - DAG

Confidentiality Information Goes Here

Filter KeyBy

KeyBy

TextFile

TextFile

Join Filter Take

Page 105: Hadoop Application Architectures tutorial - Strata London

105

Spark - DAG

Confidentiality Information Goes Here

Filter KeyBy

KeyBy

TextFile

TextFile

Join Filter Take

Good

Good

Good

Good

Good

Good

Good-Replay

Good-Replay

Good-Replay

Good

Good-Replay

Good

Good-Replay

Lost Block Replay

Good-Replay

Lost Block

Good

Future

Future

Future

Future

Page 106: Hadoop Application Architectures tutorial - Strata London

106

Spark Streaming •  Calling Spark in a Loop •  Extends RDDs with DStream •  Very Little Code Changes from ETL to Streaming

Confidentiality Information Goes Here

Page 107: Hadoop Application Architectures tutorial - Strata London

107

Spark Streaming

Confidentiality Information Goes Here

Single Pass

Source Receiver RDD

Source Receiver RDD

RDD

Filter Count Print

Source Receiver RDD

RDD

RDD

Single Pass

Filter Count Print

Pre-first Batch

First Batch

Second Batch

Page 108: Hadoop Application Architectures tutorial - Strata London

108

Spark Streaming

Confidentiality Information Goes Here

Single Pass

Source Receiver RDD

Source Receiver RDD

RDD

Filter Count

Print

Source Receiver RDD

RDD

RDD

Single Pass

Filter Count

Pre-first Batch

First Batch

Second Batch

Stateful RDD 1

Print

Stateful RDD 2

Stateful RDD 1

Page 109: Hadoop Application Architectures tutorial - Strata London

109

Impala

Confidentiality Information Goes Here

•  MPP Style SQL Engine on top of Hadoop •  Very Fast •  High Concurrency •  Analytical windowing functions (C5.2).

Page 110: Hadoop Application Architectures tutorial - Strata London

110

Impala – Broadcast Join

Confidentiality Information Goes Here

Impala Daemon

Smaller Table Data Block

100% Cached Smaller Table

Smaller Table Data Block

Impala Daemon

100% Cached Smaller Table

Impala Daemon

100% Cached Smaller Table

Impala Daemon

Hash Join Function

Bigger Table Data Block

100% Cached Smaller Table

Output

Impala Daemon

Hash Join Function

Bigger Table Data Block

100% Cached Smaller Table

Output

Impala Daemon

Hash Join Function

Bigger Table Data Block

100% Cached Smaller Table

Output

Page 111: Hadoop Application Architectures tutorial - Strata London

111

Impala – Partitioned Hash Join

Confidentiality Information Goes Here

Impala Daemon

Smaller Table Data Block

~33% Cached Smaller Table

Smaller Table Data Block

Impala Daemon

~33% Cached Smaller Table

Impala Daemon

~33% Cached Smaller Table

Hash Partitioner Hash Partitioner

Impala Daemon

BiggerTable Data Block

Impala Daemon Impala Daemon

Hash Partitioner Hash Join Function

33% Cached Smaller Table

Hash Join Function

33% Cached Smaller Table

Hash Join Function

33% Cached Smaller Table

Output Output Output

BiggerTable Data Block

Hash Partitioner

BiggerTable Data Block

Hash Partitioner

Page 112: Hadoop Application Architectures tutorial - Strata London

112

Impala vs Hive

Confidentiality Information Goes Here

•  Very different approaches and •  We may see convergence at some point •  But for now

–  Impala for speed –  Hive for batch

Page 113: Hadoop Application Architectures tutorial - Strata London

113

Architectural Considerations Data Processing – Patterns and Recommendations

Page 114: Hadoop Application Architectures tutorial - Strata London

114

What processing needs to happen?

Confidentiality Information Goes Here

•  Sessionization •  Filtering •  Deduplication •  BI / Discovery

Page 115: Hadoop Application Architectures tutorial - Strata London

115

Sessionization

Confidentiality Information Goes Here

Website visit

Visitor 1 Session 1

Visitor 1 Session 2

Visitor 2 Session 1

> 30 minutes

Page 116: Hadoop Application Architectures tutorial - Strata London

116

Why sessionize?

Confidentiality Information Goes Here

Helps answers questions like: •  What is my website’s bounce rate?

–  i.e. how many % of visitors don’t go past the landing page?

•  Which marketing channels (e.g. organic search, display ad, etc.) are leading to most sessions? –  Which ones of those lead to most conversions (e.g. people buying things,

signing up, etc.)

•  Do attribution analysis – which channels are responsible for most conversions?

Page 117: Hadoop Application Architectures tutorial - Strata London

117

Sessionization

Confidentiality Information Goes Here

244.157.45.12 - - [17/Oct/2014:21:08:30 ] "GET /seatposts HTTP/1.0" 200 4463 "http://bestcyclingreviews.com/top_online_shops" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36” 244.157.45.12+1413580110 244.157.45.12 - - [17/Oct/2014:21:59:59 ] "GET /Store/cart.jsp?productID=1023 HTTP/1.0" 200 3757 "http://www.casualcyclist.com" "Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1” 244.157.45.12+1413583199

Page 118: Hadoop Application Architectures tutorial - Strata London

118

How to Sessionize?

Confidentiality Information Goes Here

1.  Given a list of clicks, determine which clicks came from the same user (Partitioning, ordering)

2.  Given a particular user's clicks, determine if a given click is a part of a new session or a continuation of the previous session (Identifying session boundaries)

Page 119: Hadoop Application Architectures tutorial - Strata London

119

#1 – Which clicks are from same user? •  We can use:

–  IP address (244.157.45.12) –  Cookies (A9A3BECE0563982D) –  IP address (244.157.45.12)and user agent string ((KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36")

©2014 Cloudera, Inc. All Rights Reserved.

Page 120: Hadoop Application Architectures tutorial - Strata London

120

#1 – Which clicks are from same user? •  We can use:

–  IP address (244.157.45.12) –  Cookies (A9A3BECE0563982D) –  IP address (244.157.45.12)and user agent string ((KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36")

©2014 Cloudera, Inc. All Rights Reserved.

Page 121: Hadoop Application Architectures tutorial - Strata London

121

#1 – Which clicks are from same user?

©2014 Cloudera, Inc. All Rights Reserved.

244.157.45.12 - - [17/Oct/2014:21:08:30 ] "GET /seatposts HTTP/1.0" 200 4463 "http://bestcyclingreviews.com/top_online_shops" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36” 244.157.45.12 - - [17/Oct/2014:21:59:59 ] "GET /Store/cart.jsp?productID=1023 HTTP/1.0" 200 3757 "http://www.casualcyclist.com" "Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1”

Page 122: Hadoop Application Architectures tutorial - Strata London

122

#2 – Which clicks part of the same session?

©2014 Cloudera, Inc. All Rights Reserved.

244.157.45.12 - - [17/Oct/2014:21:08:30 ] "GET /seatposts HTTP/1.0" 200 4463 "http://bestcyclingreviews.com/top_online_shops" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36” 244.157.45.12 - - [17/Oct/2014:21:59:59 ] "GET /Store/cart.jsp?productID=1023 HTTP/1.0" 200 3757 "http://www.casualcyclist.com" "Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1”

> 30 mins apart = different sessions

Page 123: Hadoop Application Architectures tutorial - Strata London

123 ©2014 Cloudera, Inc. All rights reserved.

Sessionization engine recommendation •  We have sessionization code in MR and Spark on github. The

complexity of the code varies, depends on the expertise in the organization.

•  We choose MR –  MR API is stable and widely known –  No Spark + Oozie (orchestration engine) integration currently

Page 124: Hadoop Application Architectures tutorial - Strata London

124

Filtering – filter out incomplete records

©2014 Cloudera, Inc. All Rights Reserved.

244.157.45.12 - - [17/Oct/2014:21:08:30 ] "GET /seatposts HTTP/1.0" 200 4463 "http://bestcyclingreviews.com/top_online_shops" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36” 244.157.45.12 - - [17/Oct/2014:21:59:59 ] "GET /Store/cart.jsp?productID=1023 HTTP/1.0" 200 3757 "http://www.casualcyclist.com" "Mozilla/5.0 (Linux; U…

Page 125: Hadoop Application Architectures tutorial - Strata London

125

Filtering – filter out records from bots/spiders

©2014 Cloudera, Inc. All Rights Reserved.

244.157.45.12 - - [17/Oct/2014:21:08:30 ] "GET /seatposts HTTP/1.0" 200 4463 "http://bestcyclingreviews.com/top_online_shops" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36” 209.85.238.11 - - [17/Oct/2014:21:59:59 ] "GET /Store/cart.jsp?productID=1023 HTTP/1.0" 200 3757 "http://www.casualcyclist.com" "Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1”

Google spider IP address

Page 126: Hadoop Application Architectures tutorial - Strata London

126 ©2014 Cloudera, Inc. All rights reserved.

Filtering recommendation •  Bot/Spider filtering can be done easily in any of the engines •  Incomplete records are harder to filter in schema systems like

Hive, Impala, Pig, etc. •  Flume interceptors can also be used •  Pretty close choice between MR, Hive and Spark •  Can be done in Spark using rdd.filter() •  We can simply embed this in our MR sessionization job

Page 127: Hadoop Application Architectures tutorial - Strata London

127

Deduplication – remove duplicate records

©2014 Cloudera, Inc. All Rights Reserved.

244.157.45.12 - - [17/Oct/2014:21:08:30 ] "GET /seatposts HTTP/1.0" 200 4463 "http://bestcyclingreviews.com/top_online_shops" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36” 244.157.45.12 - - [17/Oct/2014:21:08:30 ] "GET /seatposts HTTP/1.0" 200 4463 "http://bestcyclingreviews.com/top_online_shops" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36”

Page 128: Hadoop Application Architectures tutorial - Strata London

128 ©2014 Cloudera, Inc. All rights reserved.

Deduplication recommendation •  Can be done in all engines. •  We already have a Hive table with all the columns, a simple

DISTINCT query will perform deduplication •  reduce() in spark •  We use Pig

Page 129: Hadoop Application Architectures tutorial - Strata London

129 ©2014 Cloudera, Inc. All rights reserved.

BI/Discovery engine recommendation •  Main requirements for this are:

–  Low latency –  SQL interface (e.g. JDBC/ODBC) –  Users don’t know how to code

•  We chose Impala –  It’s a SQL engine –  Much faster than other engines –  Provides standard JDBC/ODBC interfaces

Page 130: Hadoop Application Architectures tutorial - Strata London

130 ©2014 Cloudera, Inc. All rights reserved.

End-to-end processing

Sessionization Filtering Deduplication

BI tools

Page 131: Hadoop Application Architectures tutorial - Strata London

131

Architectural Considerations Orchestration

Page 132: Hadoop Application Architectures tutorial - Strata London

132

•  Data arrives through Flume •  Triggers a processing event:

–  Sessionize –  Enrich – Location, marketing channel… –  Store as Parquet

•  Each day we process events from the previous day

Orchestrating Clickstream

Page 133: Hadoop Application Architectures tutorial - Strata London

133 ©2014 Cloudera, Inc. All rights reserved.

•  Workflow is fairly simple •  Need to trigger workflow based on data •  Be able to recover from errors •  Perhaps notify on the status •  And collect metrics for reporting

Choosing Right

Page 134: Hadoop Application Architectures tutorial - Strata London

134

Oozie or Azkaban?

©2014 Cloudera, Inc. All rights reserved.

Page 135: Hadoop Application Architectures tutorial - Strata London

135 ©2014 Cloudera, Inc. All rights reserved.

Oozie Architecture

Page 136: Hadoop Application Architectures tutorial - Strata London

136 ©2014 Cloudera, Inc. All rights reserved.

•  Part of all major Hadoop distributions •  Hue integration •  Built -in actions – Hive, Sqoop, MapReduce, SSH •  Complex workflows with decisions •  Event and time based scheduling •  Notifications •  SLA Monitoring •  REST API

Oozie features

Page 137: Hadoop Application Architectures tutorial - Strata London

137 ©2014 Cloudera, Inc. All rights reserved.

•  Overhead in launching jobs •  Steep learning curve •  XML Workflows

Oozie Drawbacks

Page 138: Hadoop Application Architectures tutorial - Strata London

138 ©2014 Cloudera, Inc. All rights reserved.

Azkaban Architecture

Azkaban Executor Server

Azkaban Web Server

HDFS viewer plugin

Job types plugin

MySQL

Client Hadoop

Page 139: Hadoop Application Architectures tutorial - Strata London

139 ©2014 Cloudera, Inc. All rights reserved.

•  Simplicity •  Great UI – including pluggable visualizers •  Lots of plugins – Hive, Pig… •  Reporting plugin

Azkaban features

Page 140: Hadoop Application Architectures tutorial - Strata London

140 ©2014 Cloudera, Inc. All rights reserved.

•  Doesn’t support workflow decisions •  Can’t represent data dependency

Azkaban Limitations

Page 141: Hadoop Application Architectures tutorial - Strata London

141 ©2014 Cloudera, Inc. All rights reserved.

•  Workflow is fairly simple •  Need to trigger workflow based on data •  Be able to recover from errors •  Perhaps notify on the status •  And collect metrics for reporting

Choosing…

Easier in Oozie

Page 142: Hadoop Application Architectures tutorial - Strata London

142 ©2014 Cloudera, Inc. All rights reserved.

•  Workflow is fairly simple •  Need to trigger workflow based on data •  Be able to recover from errors •  Perhaps notify on the status •  And collect metrics for reporting

Choosing the right Orchestration Tool

Better in Azkaban

Page 143: Hadoop Application Architectures tutorial - Strata London

143 ©2014 Cloudera, Inc. All rights reserved.

The best orchestration tool is the one you are an expert on

Important Decision Consideration!

Page 144: Hadoop Application Architectures tutorial - Strata London

144 ©2014 Cloudera, Inc. All rights reserved.

Orchestration Patterns – Fan Out

Page 145: Hadoop Application Architectures tutorial - Strata London

145 ©2014 Cloudera, Inc. All rights reserved.

Capture & Decide Pattern

Page 146: Hadoop Application Architectures tutorial - Strata London

146

Putting It All Together Final Architecture

Page 147: Hadoop Application Architectures tutorial - Strata London

147

Final Architecture – High Level Overview

Data Sources Ingestion

Raw Data Storage

(Formats, Schema)

Processed Data Storage

(Formats, Schema)

©2014 Cloudera, Inc. All Rights Reserved.

Processing Data Consumption

Orchestration (Scheduling, Managing, Monitoring)

Page 148: Hadoop Application Architectures tutorial - Strata London

148

Final Architecture – High Level Overview

Data Sources Ingestion

Raw Data Storage

(Formats, Schema)

Processed Data Storage

(Formats, Schema)

©2014 Cloudera, Inc. All Rights Reserved.

Processing Data Consumption

Orchestration (Scheduling, Managing, Monitoring)

Page 149: Hadoop Application Architectures tutorial - Strata London

149

Final Architecture – Ingestion/Storage

Web Server Flume Agent Web Server Flume Agent

Web Server Flume Agent Web Server Flume Agent

Web Server Flume Agent Web Server Flume Agent

Web Server Flume Agent Web Server Flume Agent

Flume Agent

Flume Agent

Flume Agent

Flume Agent

Fan-in Pattern

Multi Agents for Failover and rolling restarts

HDFS

©2014 Cloudera, Inc. All Rights Reserved.

/etl/BI/casualcyclist/clicks/rawlogs/year=2014/month=10/day=10!

Page 150: Hadoop Application Architectures tutorial - Strata London

150

Final Architecture – High Level Overview

Data Sources Ingestion

Raw Data Storage

(Formats, Schema)

Processed Data Storage

(Formats, Schema)

©2014 Cloudera, Inc. All Rights Reserved.

Processing

Data Consumption

Orchestration (Scheduling, Managing, Monitoring)

Page 151: Hadoop Application Architectures tutorial - Strata London

151

Final Architecture – Processing and Storage

/etl/BI/casualcyclist/clicks/rawlogs/year=2014/month=10/day=10 …

dedup->filtering->sessionization

/data/bikeshop/clickstream/year=2014/month=10/day=10 …

©2014 Cloudera, Inc. All Rights Reserved.

parquetize

Page 152: Hadoop Application Architectures tutorial - Strata London

152

Final Architecture – High Level Overview

Data Sources Ingestion

Raw Data Storage

(Formats, Schema)

Processed Data Storage

(Formats, Schema)

©2014 Cloudera, Inc. All Rights Reserved.

Processing Data Consumption

Orchestration (Scheduling, Managing, Monitoring)

Page 153: Hadoop Application Architectures tutorial - Strata London

153

Final Architecture – Data Access

Hive/Impala

BI/Analytics

Tools

DWH Sqoop

Local Disk

R, etc.

DB import tool

JDBC/ODBC

©2014 Cloudera, Inc. All Rights Reserved.

Page 154: Hadoop Application Architectures tutorial - Strata London

154

Demo

©2014 Cloudera, Inc. All rights reserved.

Page 155: Hadoop Application Architectures tutorial - Strata London

155 Confidentiality Information Goes Here

Join the Discussion

Get community help or provide feedback cloudera.com/community

Page 156: Hadoop Application Architectures tutorial - Strata London

156 Built  for  Produc-on  Success.  Powered  by  Apache  Hadoop  

Page 157: Hadoop Application Architectures tutorial - Strata London

157 Try  Cloudera  Live  today—cloudera.com/live  

Page 158: Hadoop Application Architectures tutorial - Strata London

158

BOOK SIGNINGS THEATER SESSIONS

TECHNICAL DEMOS GIVEAWAYS

Visit us at Booth #101 HIGHLIGHTS: Apache Kafka is now fully supported with Cloudera Learn why Cloudera is the leader for security & governance in Hadoop

Page 159: Hadoop Application Architectures tutorial - Strata London

159

Free books and Lots of Q&A! •  Book signings

–  Wednesday, May 6th, 3:15 PM at Cloudera booth (#101) –  Wednesday, May 6th, 6PM at O’Reilly booth

•  Ask Us Anything! –  Wednesday, May 6th, 14:35-15:15 at Westminster Suite

•  Office hours! –  Thursday, May 7th, 11:45-12:25 at Table A

•  Stay in touch! –  @hadooparchbook –  hadooparchitecturebook.com –  slideshare.com/hadooparchbook

•  Please leave us a review!

©2014 Cloudera, Inc. All Rights Reserved.