Slide 1

Slide 1 text

CloudFront BEST PRACTICES & ANTI-PATTERNS Abhishek Tiwari @abhishektiwari http:/ /abhishek-tiwari.com Wednesday, 7 August 13

Slide 2

Slide 2 text

About me Wednesday, 7 August 13

Slide 3

Slide 3 text

About me Solutions Architect Wednesday, 7 August 13

Slide 4

Slide 4 text

About me Solutions Architect Early AWS adopter (2007) Wednesday, 7 August 13

Slide 5

Slide 5 text

About me Solutions Architect Early AWS adopter (2007) Built Cotton On Group’s AWS Infrastructure (2012) Wednesday, 7 August 13

Slide 6

Slide 6 text

Agenda CloudFront in a nutshell CloudFront Best Practices/Anti-Patterns Wednesday, 7 August 13

Slide 7

Slide 7 text

CloudFront (CF) Wednesday, 7 August 13

Slide 8

Slide 8 text

CloudFront (CF) Content Delivery Network Wednesday, 7 August 13

Slide 9

Slide 9 text

CloudFront (CF) Content Delivery Network Serves Static and Dynamic Content Wednesday, 7 August 13

Slide 10

Slide 10 text

CloudFront (CF) Content Delivery Network Serves Static and Dynamic Content Global, Redundant, Scalable Wednesday, 7 August 13

Slide 11

Slide 11 text

CloudFront (CF) Content Delivery Network Serves Static and Dynamic Content Global, Redundant, Scalable Low Latency, High Bandwidth Wednesday, 7 August 13

Slide 12

Slide 12 text

CloudFront (CF) Content Delivery Network Serves Static and Dynamic Content Global, Redundant, Scalable Low Latency, High Bandwidth Cost Effective: Transparent, PAYG, Price Classes Wednesday, 7 August 13

Slide 13

Slide 13 text

CloudFront (CF) Content Delivery Network Serves Static and Dynamic Content Global, Redundant, Scalable Low Latency, High Bandwidth Cost Effective: Transparent, PAYG, Price Classes NO Edge Side Includes (ESI) Wednesday, 7 August 13

Slide 14

Slide 14 text

CF Concepts Wednesday, 7 August 13

Slide 15

Slide 15 text

CF Concepts Distribution Wednesday, 7 August 13

Slide 16

Slide 16 text

CF Concepts Distribution Delivery Method (Download or Streaming) Wednesday, 7 August 13

Slide 17

Slide 17 text

CF Concepts Distribution Delivery Method (Download or Streaming) CNAME Aliases (1-10) Wednesday, 7 August 13

Slide 18

Slide 18 text

CF Concepts Distribution Delivery Method (Download or Streaming) CNAME Aliases (1-10) Origin Server/s (M:M) Wednesday, 7 August 13

Slide 19

Slide 19 text

CF Concepts Distribution Delivery Method (Download or Streaming) CNAME Aliases (1-10) Origin Server/s (M:M) Domain Name, Origin ID, Origin Protocol Wednesday, 7 August 13

Slide 20

Slide 20 text

CF Concepts Distribution Delivery Method (Download or Streaming) CNAME Aliases (1-10) Origin Server/s (M:M) Domain Name, Origin ID, Origin Protocol Object/s (Object Path/Cache Key) Wednesday, 7 August 13

Slide 21

Slide 21 text

CF Concepts Distribution Delivery Method (Download or Streaming) CNAME Aliases (1-10) Origin Server/s (M:M) Domain Name, Origin ID, Origin Protocol Object/s (Object Path/Cache Key) Cache Behavior/s (1-10, 1:1, Ordered) Wednesday, 7 August 13

Slide 22

Slide 22 text

CF Concepts Distribution Delivery Method (Download or Streaming) CNAME Aliases (1-10) Origin Server/s (M:M) Domain Name, Origin ID, Origin Protocol Object/s (Object Path/Cache Key) Cache Behavior/s (1-10, 1:1, Ordered) Path Patterns, Origin ID, Viewer Protocol, Minimum TTL, Cookies/ Query String Forwarding Wednesday, 7 August 13

Slide 23

Slide 23 text

CF Concepts Distribution Delivery Method (Download or Streaming) CNAME Aliases (1-10) Origin Server/s (M:M) Domain Name, Origin ID, Origin Protocol Object/s (Object Path/Cache Key) Cache Behavior/s (1-10, 1:1, Ordered) Path Patterns, Origin ID, Viewer Protocol, Minimum TTL, Cookies/ Query String Forwarding Edge Location (42+) Wednesday, 7 August 13

Slide 24

Slide 24 text

CF Concepts Distribution Delivery Method (Download or Streaming) CNAME Aliases (1-10) Origin Server/s (M:M) Domain Name, Origin ID, Origin Protocol Object/s (Object Path/Cache Key) Cache Behavior/s (1-10, 1:1, Ordered) Path Patterns, Origin ID, Viewer Protocol, Minimum TTL, Cookies/ Query String Forwarding Edge Location (42+) Viewer (GET, Range GET, HEAD Requests) Wednesday, 7 August 13

Slide 25

Slide 25 text

CF Concepts http:/ /mycontent.cloudfront.net/photos/profile.png Cache Key: photos/profile.png (Same for HTTP/HTTPS) Cache Key: object path relative to origin + forwarded query string/cookies Wednesday, 7 August 13

Slide 26

Slide 26 text

CF Concepts Dynamic Content http:/ /mycontent.cloudfront.net/photos/profile.png Cache Key: photos/profile.png (Same for HTTP/HTTPS) Cache Key: object path relative to origin + forwarded query string/cookies Wednesday, 7 August 13

Slide 27

Slide 27 text

CF Concepts Dynamic Content Static Content http:/ /mycontent.cloudfront.net/photos/profile.png Cache Key: photos/profile.png (Same for HTTP/HTTPS) Cache Key: object path relative to origin + forwarded query string/cookies Wednesday, 7 August 13

Slide 28

Slide 28 text

How it works 1. Client request file 2. If file in cache CF return file Nearest Edge Location a. If file not in cache, CF request to origin b. Origin returns file, status 200, cached in CF 1. Client request file 2. If file in cache CF return file Nearest Edge Location a. If file in cache but expired, CF request to origin b. Origin returns 304, CF keeps file in cache Routing based on low latency/price class Routing based on low latency/price class Condition GET Wednesday, 7 August 13

Slide 29

Slide 29 text

Distribution Wednesday, 7 August 13

Slide 30

Slide 30 text

Distribution Download Distribution Wednesday, 7 August 13

Slide 31

Slide 31 text

Distribution Download Distribution Viewer Protocol HTTP/HTTPS Wednesday, 7 August 13

Slide 32

Slide 32 text

Distribution Download Distribution Viewer Protocol HTTP/HTTPS Origin: S3 or Custom Wednesday, 7 August 13

Slide 33

Slide 33 text

Distribution Download Distribution Viewer Protocol HTTP/HTTPS Origin: S3 or Custom Cookies/Query String Forwarding Wednesday, 7 August 13

Slide 34

Slide 34 text

Distribution Download Distribution Viewer Protocol HTTP/HTTPS Origin: S3 or Custom Cookies/Query String Forwarding Streaming Distribution Wednesday, 7 August 13

Slide 35

Slide 35 text

Distribution Download Distribution Viewer Protocol HTTP/HTTPS Origin: S3 or Custom Cookies/Query String Forwarding Streaming Distribution Viewer Protocol: Adobe RTMP Wednesday, 7 August 13

Slide 36

Slide 36 text

Distribution Download Distribution Viewer Protocol HTTP/HTTPS Origin: S3 or Custom Cookies/Query String Forwarding Streaming Distribution Viewer Protocol: Adobe RTMP Origin: S3 only (No Custom) Wednesday, 7 August 13

Slide 37

Slide 37 text

Distribution Download Distribution Viewer Protocol HTTP/HTTPS Origin: S3 or Custom Cookies/Query String Forwarding Streaming Distribution Viewer Protocol: Adobe RTMP Origin: S3 only (No Custom) Dynamic/Adoptive Streaming (Adjust bit rate during playback) Wednesday, 7 August 13

Slide 38

Slide 38 text

Query String Forwarding Wednesday, 7 August 13

Slide 39

Slide 39 text

Query String Forwarding Forward query string to origin Wednesday, 7 August 13

Slide 40

Slide 40 text

Query String Forwarding Forward query string to origin Multiple parameters, order/case sensitive Wednesday, 7 August 13

Slide 41

Slide 41 text

Query String Forwarding Forward query string to origin Multiple parameters, order/case sensitive Order sensitive: Two objects in CF Wednesday, 7 August 13

Slide 42

Slide 42 text

Query String Forwarding Forward query string to origin Multiple parameters, order/case sensitive Order sensitive: Two objects in CF http:/ /d111111abcdef8.cloudfront.net/images/image.jpg?height=a&width=b Wednesday, 7 August 13

Slide 43

Slide 43 text

Query String Forwarding Forward query string to origin Multiple parameters, order/case sensitive Order sensitive: Two objects in CF http:/ /d111111abcdef8.cloudfront.net/images/image.jpg?height=a&width=b http:/ /d111111abcdef8.cloudfront.net/images/image.jpg?width=b&height=a Wednesday, 7 August 13

Slide 44

Slide 44 text

Query String Forwarding Forward query string to origin Multiple parameters, order/case sensitive Order sensitive: Two objects in CF http:/ /d111111abcdef8.cloudfront.net/images/image.jpg?height=a&width=b http:/ /d111111abcdef8.cloudfront.net/images/image.jpg?width=b&height=a Case sensitive: Two objects in CF Wednesday, 7 August 13

Slide 45

Slide 45 text

Query String Forwarding Forward query string to origin Multiple parameters, order/case sensitive Order sensitive: Two objects in CF http:/ /d111111abcdef8.cloudfront.net/images/image.jpg?height=a&width=b http:/ /d111111abcdef8.cloudfront.net/images/image.jpg?width=b&height=a Case sensitive: Two objects in CF http:/ /d111111abcdef8.cloudfront.net/images/image.jpg?type=png Wednesday, 7 August 13

Slide 46

Slide 46 text

Query String Forwarding Forward query string to origin Multiple parameters, order/case sensitive Order sensitive: Two objects in CF http:/ /d111111abcdef8.cloudfront.net/images/image.jpg?height=a&width=b http:/ /d111111abcdef8.cloudfront.net/images/image.jpg?width=b&height=a Case sensitive: Two objects in CF http:/ /d111111abcdef8.cloudfront.net/images/image.jpg?type=png http:/ /d111111abcdef8.cloudfront.net/images/image.jpg?type=PNG Wednesday, 7 August 13

Slide 47

Slide 47 text

Cookies Forwarding Wednesday, 7 August 13

Slide 48

Slide 48 text

Cookies Forwarding Forwarded cookies (FC): NV pairs, not attributes Wednesday, 7 August 13

Slide 49

Slide 49 text

Cookies Forwarding Forwarded cookies (FC): NV pairs, not attributes If choose to forward cookies to origin, Wednesday, 7 August 13

Slide 50

Slide 50 text

Cookies Forwarding Forwarded cookies (FC): NV pairs, not attributes If choose to forward cookies to origin, Can forward all cookies, OR Wednesday, 7 August 13

Slide 51

Slide 51 text

Cookies Forwarding Forwarded cookies (FC): NV pairs, not attributes If choose to forward cookies to origin, Can forward all cookies, OR Only specified cookies Wednesday, 7 August 13

Slide 52

Slide 52 text

Cookies Forwarding Forwarded cookies (FC): NV pairs, not attributes If choose to forward cookies to origin, Can forward all cookies, OR Only specified cookies Object path+FC uniquely identify in CF Wednesday, 7 August 13

Slide 53

Slide 53 text

Cookies Forwarding Forwarded cookies (FC): NV pairs, not attributes If choose to forward cookies to origin, Can forward all cookies, OR Only specified cookies Object path+FC uniquely identify in CF NV pair/Case sensitive Wednesday, 7 August 13

Slide 54

Slide 54 text

Origin Wednesday, 7 August 13

Slide 55

Slide 55 text

Origin S3 Origin: Best for Static media content (Image, Video, Audio) Wednesday, 7 August 13

Slide 56

Slide 56 text

Origin S3 Origin: Best for Static media content (Image, Video, Audio) Custom Origin: Best for Static application content (JS, CSS, Fonts) Wednesday, 7 August 13

Slide 57

Slide 57 text

Origin S3 Origin: Best for Static media content (Image, Video, Audio) Custom Origin: Best for Static application content (JS, CSS, Fonts) Custom Origin: Best for Dynamic media content (HTML, Thumbnails) Wednesday, 7 August 13

Slide 58

Slide 58 text

Make a note Wednesday, 7 August 13

Slide 59

Slide 59 text

Make a note Eventual Consistency Wednesday, 7 August 13

Slide 60

Slide 60 text

Make a note Eventual Consistency 10 Origin Servers per CF Distribution Wednesday, 7 August 13

Slide 61

Slide 61 text

Make a note Eventual Consistency 10 Origin Servers per CF Distribution 10 Cache Behavior per CF Distribution Wednesday, 7 August 13

Slide 62

Slide 62 text

Make a note Eventual Consistency 10 Origin Servers per CF Distribution 10 Cache Behavior per CF Distribution 10 CNAME per CF Distribution Wednesday, 7 August 13

Slide 63

Slide 63 text

Make a note Eventual Consistency 10 Origin Servers per CF Distribution 10 Cache Behavior per CF Distribution 10 CNAME per CF Distribution 10 Cookies forwarded per Cache Behavior Wednesday, 7 August 13

Slide 64

Slide 64 text

Best Practices Wednesday, 7 August 13

Slide 65

Slide 65 text

Best Practices Versioning Wednesday, 7 August 13

Slide 66

Slide 66 text

Best Practices Versioning Compression Wednesday, 7 August 13

Slide 67

Slide 67 text

Best Practices Versioning Compression Domain Sharding Wednesday, 7 August 13

Slide 68

Slide 68 text

Best Practices Versioning Compression Domain Sharding Expiration Wednesday, 7 August 13

Slide 69

Slide 69 text

Best Practices Versioning Compression Domain Sharding Expiration Bucket Organization Wednesday, 7 August 13

Slide 70

Slide 70 text

Best Practices Versioning Compression Domain Sharding Expiration Bucket Organization Logging Wednesday, 7 August 13

Slide 71

Slide 71 text

Best Practices Versioning Compression Domain Sharding Expiration Bucket Organization Logging Performance Testing Wednesday, 7 August 13

Slide 72

Slide 72 text

Anti-Patterns Cache Invalidation Wednesday, 7 August 13

Slide 73

Slide 73 text

Cache Invalidation Wednesday, 7 August 13

Slide 74

Slide 74 text

Cache Invalidation Programmatic Cache Invalidation Wednesday, 7 August 13

Slide 75

Slide 75 text

Cache Invalidation Programmatic Cache Invalidation Cache Invalidation is expensive Wednesday, 7 August 13

Slide 76

Slide 76 text

Cache Invalidation Programmatic Cache Invalidation Cache Invalidation is expensive Unmanageable if you have object dependencies Wednesday, 7 August 13

Slide 77

Slide 77 text

Cache Invalidation Programmatic Cache Invalidation Cache Invalidation is expensive Unmanageable if you have object dependencies 3 invalidation requests at any given time Wednesday, 7 August 13

Slide 78

Slide 78 text

Cache Invalidation Programmatic Cache Invalidation Cache Invalidation is expensive Unmanageable if you have object dependencies 3 invalidation requests at any given time Each invalidation request can included maximum of 1000 files Wednesday, 7 August 13

Slide 79

Slide 79 text

Cache Invalidation Wednesday, 7 August 13

Slide 80

Slide 80 text

Cache Invalidation Invalidation takes time to propagate across all edge locations (5-15 minutes) Wednesday, 7 August 13

Slide 81

Slide 81 text

Cache Invalidation Invalidation takes time to propagate across all edge locations (5-15 minutes) Deal breaker: browser cache Wednesday, 7 August 13

Slide 82

Slide 82 text

Cache Invalidation Invalidation takes time to propagate across all edge locations (5-15 minutes) Deal breaker: browser cache Versioning is best way to avoid the invalidation related issues Wednesday, 7 August 13

Slide 83

Slide 83 text

Versioning Wednesday, 7 August 13

Slide 84

Slide 84 text

Versioning CF relies on Origin Servers for versioning Wednesday, 7 August 13

Slide 85

Slide 85 text

Versioning CF relies on Origin Servers for versioning S3 supports versioning Wednesday, 7 August 13

Slide 86

Slide 86 text

Versioning CF relies on Origin Servers for versioning S3 supports versioning Version enabled Custom Origin Wednesday, 7 August 13

Slide 87

Slide 87 text

Versioning Wednesday, 7 August 13

Slide 88

Slide 88 text

Versioning Versioning using query strings Wednesday, 7 August 13

Slide 89

Slide 89 text

Versioning Versioning using query strings File name plus query string with version /static/profile.png?versionID=123 Wednesday, 7 August 13

Slide 90

Slide 90 text

Versioning Versioning using query strings File name plus query string with version /static/profile.png?versionID=123 Versioning using content based hash key Wednesday, 7 August 13

Slide 91

Slide 91 text

Versioning Versioning using query strings File name plus query string with version /static/profile.png?versionID=123 Versioning using content based hash key File name as unique key based on file content /static/712vds57tr18929812312enb.png Wednesday, 7 August 13

Slide 92

Slide 92 text

Versioning Versioning using query strings File name plus query string with version /static/profile.png?versionID=123 Versioning using content based hash key File name as unique key based on file content /static/712vds57tr18929812312enb.png Versioning using prefix/suffix Wednesday, 7 August 13

Slide 93

Slide 93 text

Versioning Versioning using query strings File name plus query string with version /static/profile.png?versionID=123 Versioning using content based hash key File name as unique key based on file content /static/712vds57tr18929812312enb.png Versioning using prefix/suffix File name with version prefix/suffix /static/profile_123.png Wednesday, 7 August 13

Slide 94

Slide 94 text

Versioning Versioning using query strings File name plus query string with version /static/profile.png?versionID=123 Versioning using content based hash key File name as unique key based on file content /static/712vds57tr18929812312enb.png Versioning using prefix/suffix File name with version prefix/suffix /static/profile_123.png File name with version prefix/suffix /static/profile_ 712vds57tr18929812312enb.png Wednesday, 7 August 13

Slide 95

Slide 95 text

Versioning Versioning using query strings File name plus query string with version /static/profile.png?versionID=123 Versioning using content based hash key File name as unique key based on file content /static/712vds57tr18929812312enb.png Versioning using prefix/suffix File name with version prefix/suffix /static/profile_123.png File name with version prefix/suffix /static/profile_ 712vds57tr18929812312enb.png You can use a mixed versioning approach Wednesday, 7 August 13

Slide 96

Slide 96 text

Versioning using query strings Wednesday, 7 August 13

Slide 97

Slide 97 text

Versioning using query strings CF supports versioning using query strings forwarding Wednesday, 7 August 13

Slide 98

Slide 98 text

Versioning using query strings CF supports versioning using query strings forwarding Versioning enabled Origin (Custom/S3) Wednesday, 7 August 13

Slide 99

Slide 99 text

Versioning using query strings CF supports versioning using query strings forwarding Versioning enabled Origin (Custom/S3) For S3 Content Wednesday, 7 August 13

Slide 100

Slide 100 text

Versioning using query strings CF supports versioning using query strings forwarding Versioning enabled Origin (Custom/S3) For S3 Content On object upload version enabled S3 bucket will return x-amz-version-id Wednesday, 7 August 13

Slide 101

Slide 101 text

Versioning using query strings CF supports versioning using query strings forwarding Versioning enabled Origin (Custom/S3) For S3 Content On object upload version enabled S3 bucket will return x-amz-version-id profile.png Wednesday, 7 August 13

Slide 102

Slide 102 text

Versioning using query strings CF supports versioning using query strings forwarding Versioning enabled Origin (Custom/S3) For S3 Content On object upload version enabled S3 bucket will return x-amz-version-id profile.png Upload to S3 Wednesday, 7 August 13

Slide 103

Slide 103 text

Versioning using query strings CF supports versioning using query strings forwarding Versioning enabled Origin (Custom/S3) For S3 Content On object upload version enabled S3 bucket will return x-amz-version-id profile.png Upload to S3 static/images/profile.png Wednesday, 7 August 13

Slide 104

Slide 104 text

Versioning using query strings CF supports versioning using query strings forwarding Versioning enabled Origin (Custom/S3) For S3 Content On object upload version enabled S3 bucket will return x-amz-version-id profile.png Upload to S3 static/images/profile.png Return x-amz-version-id Wednesday, 7 August 13

Slide 105

Slide 105 text

Versioning using query strings CF supports versioning using query strings forwarding Versioning enabled Origin (Custom/S3) For S3 Content On object upload version enabled S3 bucket will return x-amz-version-id profile.png Upload to S3 static/images/profile.png Return x-amz-version-id static/images/profile.png? versionId=644c69e148 Wednesday, 7 August 13

Slide 106

Slide 106 text

Versioning using query strings Wednesday, 7 August 13

Slide 107

Slide 107 text

Versioning using query strings Versionify Application content Wednesday, 7 August 13

Slide 108

Slide 108 text

Versioning using query strings Versionify Application content Use Build Number or Hash of GIT/HG Head Wednesday, 7 August 13

Slide 109

Slide 109 text

Versioning using query strings Versionify Application content Use Build Number or Hash of GIT/HG Head photo.css, app.css, profile.css photo.js, app.js, profile.js Wednesday, 7 August 13

Slide 110

Slide 110 text

Versioning using query strings Versionify Application content Use Build Number or Hash of GIT/HG Head photo.css, app.css, profile.css photo.js, app.js, profile.js Minify+Combine Wednesday, 7 August 13

Slide 111

Slide 111 text

Versioning using query strings Versionify Application content Use Build Number or Hash of GIT/HG Head photo.css, app.css, profile.css photo.js, app.js, profile.js Minify+Combine main.css main.js Wednesday, 7 August 13

Slide 112

Slide 112 text

Versioning using query strings Versionify Application content Use Build Number or Hash of GIT/HG Head photo.css, app.css, profile.css photo.js, app.js, profile.js Minify+Combine main.css main.js Versionify Wednesday, 7 August 13

Slide 113

Slide 113 text

Versioning using query strings Versionify Application content Use Build Number or Hash of GIT/HG Head photo.css, app.css, profile.css photo.js, app.js, profile.js Minify+Combine main.css main.js Versionify main.css?v=468df6b main.js?v=468df6b Wednesday, 7 August 13

Slide 114

Slide 114 text

Versioning using query strings Wednesday, 7 August 13

Slide 115

Slide 115 text

Versioning using content based hash key Wednesday, 7 August 13

Slide 116

Slide 116 text

Versioning using content based hash key File name is an unique hash key generated from file content (MD5) Wednesday, 7 August 13

Slide 117

Slide 117 text

Versioning using content based hash key File name is an unique hash key generated from file content (MD5) For S3 content Wednesday, 7 August 13

Slide 118

Slide 118 text

Versioning using content based hash key File name is an unique hash key generated from file content (MD5) For S3 content Before uploading to S3 generate MD5 hash for file Wednesday, 7 August 13

Slide 119

Slide 119 text

Versioning using content based hash key File name is an unique hash key generated from file content (MD5) For S3 content Before uploading to S3 generate MD5 hash for file Use hash as file name to upload on S3 Wednesday, 7 August 13

Slide 120

Slide 120 text

Versioning using content based hash key File name is an unique hash key generated from file content (MD5) For S3 content Before uploading to S3 generate MD5 hash for file Use hash as file name to upload on S3 Avoid content duplication by comparing MD5 hashes Wednesday, 7 August 13

Slide 121

Slide 121 text

Versioning using content based hash key File name is an unique hash key generated from file content (MD5) For S3 content Before uploading to S3 generate MD5 hash for file Use hash as file name to upload on S3 Avoid content duplication by comparing MD5 hashes profile.jpg Wednesday, 7 August 13

Slide 122

Slide 122 text

Versioning using content based hash key File name is an unique hash key generated from file content (MD5) For S3 content Before uploading to S3 generate MD5 hash for file Use hash as file name to upload on S3 Avoid content duplication by comparing MD5 hashes profile.jpg MD5 Hash File Name Wednesday, 7 August 13

Slide 123

Slide 123 text

Versioning using content based hash key File name is an unique hash key generated from file content (MD5) For S3 content Before uploading to S3 generate MD5 hash for file Use hash as file name to upload on S3 Avoid content duplication by comparing MD5 hashes profile.jpg MD5 Hash File Name b723eh0f0df.png Wednesday, 7 August 13

Slide 124

Slide 124 text

Versioning using content based hash key File name is an unique hash key generated from file content (MD5) For S3 content Before uploading to S3 generate MD5 hash for file Use hash as file name to upload on S3 Avoid content duplication by comparing MD5 hashes profile.jpg MD5 Hash File Name b723eh0f0df.png Upload to S3 Wednesday, 7 August 13

Slide 125

Slide 125 text

Versioning using content based hash key File name is an unique hash key generated from file content (MD5) For S3 content Before uploading to S3 generate MD5 hash for file Use hash as file name to upload on S3 Avoid content duplication by comparing MD5 hashes profile.jpg MD5 Hash File Name b723eh0f0df.png Upload to S3 static/images/b723eh0f0df.png Wednesday, 7 August 13

Slide 126

Slide 126 text

Versioning using content based hash key Wednesday, 7 August 13

Slide 127

Slide 127 text

Versioning using content based hash key For application content use a pipeline Wednesday, 7 August 13

Slide 128

Slide 128 text

Versioning using content based hash key For application content use a pipeline file names generated using MD5 hash of file content Wednesday, 7 August 13

Slide 129

Slide 129 text

Versioning using content based hash key For application content use a pipeline file names generated using MD5 hash of file content photo.css, app.css, profile.css photo.js, app.js, profile.js Wednesday, 7 August 13

Slide 130

Slide 130 text

Versioning using content based hash key For application content use a pipeline file names generated using MD5 hash of file content photo.css, app.css, profile.css photo.js, app.js, profile.js Minify+Combine Wednesday, 7 August 13

Slide 131

Slide 131 text

Versioning using content based hash key For application content use a pipeline file names generated using MD5 hash of file content photo.css, app.css, profile.css photo.js, app.js, profile.js Minify+Combine main.css main.js Wednesday, 7 August 13

Slide 132

Slide 132 text

Versioning using content based hash key For application content use a pipeline file names generated using MD5 hash of file content photo.css, app.css, profile.css photo.js, app.js, profile.js Minify+Combine main.css main.js MD5 Hash File Name Wednesday, 7 August 13

Slide 133

Slide 133 text

Versioning using content based hash key For application content use a pipeline file names generated using MD5 hash of file content photo.css, app.css, profile.css photo.js, app.js, profile.js Minify+Combine main.css main.js MD5 Hash File Name 8972bw7dyf2h.css 67bfwu9hhuw.js Wednesday, 7 August 13

Slide 134

Slide 134 text

Versioning using content based hash key Wednesday, 7 August 13

Slide 135

Slide 135 text

Compression Wednesday, 7 August 13

Slide 136

Slide 136 text

Compression Compressed content is served faster and uses less bandwidth Wednesday, 7 August 13

Slide 137

Slide 137 text

Compression Compressed content is served faster and uses less bandwidth CF can serve both compressed and uncompressed version of files Wednesday, 7 August 13

Slide 138

Slide 138 text

Compression Compressed content is served faster and uses less bandwidth CF can serve both compressed and uncompressed version of files Depends on viewer or browser request Wednesday, 7 August 13

Slide 139

Slide 139 text

Compression Compressed content is served faster and uses less bandwidth CF can serve both compressed and uncompressed version of files Depends on viewer or browser request To receive compressed content browser must include Accept-Encoding: gzip in the request header Wednesday, 7 August 13

Slide 140

Slide 140 text

Compression Compressed content is served faster and uses less bandwidth CF can serve both compressed and uncompressed version of files Depends on viewer or browser request To receive compressed content browser must include Accept-Encoding: gzip in the request header For compression CF relies on the custom origin servers Wednesday, 7 August 13

Slide 141

Slide 141 text

Compression Compressed content is served faster and uses less bandwidth CF can serve both compressed and uncompressed version of files Depends on viewer or browser request To receive compressed content browser must include Accept-Encoding: gzip in the request header For compression CF relies on the custom origin servers S3 does not perform the compression Wednesday, 7 August 13

Slide 142

Slide 142 text

Compression Wednesday, 7 August 13

Slide 143

Slide 143 text

Compression S3 can store both gzip and non-gzip versions of the file in the same bucket Wednesday, 7 August 13

Slide 144

Slide 144 text

Compression S3 can store both gzip and non-gzip versions of the file in the same bucket When uploading gzip file to Amazon S3 set Content-Encoding to gzip Wednesday, 7 August 13

Slide 145

Slide 145 text

Compression S3 can store both gzip and non-gzip versions of the file in the same bucket When uploading gzip file to Amazon S3 set Content-Encoding to gzip On-the-fly compression by custom origin server (Nginx, Apache) Wednesday, 7 August 13

Slide 146

Slide 146 text

Compression S3 can store both gzip and non-gzip versions of the file in the same bucket When uploading gzip file to Amazon S3 set Content-Encoding to gzip On-the-fly compression by custom origin server (Nginx, Apache) Compress: HTML, CSS, JS etc Wednesday, 7 August 13

Slide 147

Slide 147 text

Compression S3 can store both gzip and non-gzip versions of the file in the same bucket When uploading gzip file to Amazon S3 set Content-Encoding to gzip On-the-fly compression by custom origin server (Nginx, Apache) Compress: HTML, CSS, JS etc Compress Image: JPEG, WebP (Q= 0-100) Wednesday, 7 August 13

Slide 148

Slide 148 text

Expiration Wednesday, 7 August 13

Slide 149

Slide 149 text

Expiration Use one/both of these Wednesday, 7 August 13

Slide 150

Slide 150 text

Expiration Use one/both of these On Origin server set Cache-Control max-age header Wednesday, 7 August 13

Slide 151

Slide 151 text

Expiration Use one/both of these On Origin server set Cache-Control max-age header In Cache Behavior set Minimum TTL Wednesday, 7 August 13

Slide 152

Slide 152 text

Expiration Use one/both of these On Origin server set Cache-Control max-age header In Cache Behavior set Minimum TTL Date header/Age header (RFC 2616) Wednesday, 7 August 13

Slide 153

Slide 153 text

Expiration Use one/both of these On Origin server set Cache-Control max-age header In Cache Behavior set Minimum TTL Date header/Age header (RFC 2616) Avoid Expire header Wednesday, 7 August 13

Slide 154

Slide 154 text

Expiration Wednesday, 7 August 13

Slide 155

Slide 155 text

Expiration Browser cachability issues (known bug) Wednesday, 7 August 13

Slide 156

Slide 156 text

Expiration Browser cachability issues (known bug) Set Cache-Control max-age or Minimum TTL very far future Wednesday, 7 August 13

Slide 157

Slide 157 text

Expiration Browser cachability issues (known bug) Set Cache-Control max-age or Minimum TTL very far future Depending on request frequency, CloudFront might remove the object before its expiration Wednesday, 7 August 13

Slide 158

Slide 158 text

Expiration Browser cachability issues (known bug) Set Cache-Control max-age or Minimum TTL very far future Depending on request frequency, CloudFront might remove the object before its expiration Default expiration 24hrs Wednesday, 7 August 13

Slide 159

Slide 159 text

Expiration Browser cachability issues (known bug) Set Cache-Control max-age or Minimum TTL very far future Depending on request frequency, CloudFront might remove the object before its expiration Default expiration 24hrs Objects are cached for max {Cache-Control max-age directive, Cache Behavior Minimum TTL} Wednesday, 7 August 13

Slide 160

Slide 160 text

Domain Sharding Wednesday, 7 August 13

Slide 161

Slide 161 text

Domain Sharding To increase client side performance Wednesday, 7 August 13

Slide 162

Slide 162 text

Domain Sharding To increase client side performance On average 100+ resources on an ecommerce page Wednesday, 7 August 13

Slide 163

Slide 163 text

Domain Sharding To increase client side performance On average 100+ resources on an ecommerce page Browsers limit the number of simultaneous connections to one server Wednesday, 7 August 13

Slide 164

Slide 164 text

Domain Sharding To increase client side performance On average 100+ resources on an ecommerce page Browsers limit the number of simultaneous connections to one server Hence limit the parallel download from one server Wednesday, 7 August 13

Slide 165

Slide 165 text

Domain Sharding Wednesday, 7 August 13

Slide 166

Slide 166 text

Domain Sharding Use two or more CNAME aliases to serve the content from a CF distribution Wednesday, 7 August 13

Slide 167

Slide 167 text

Domain Sharding Use two or more CNAME aliases to serve the content from a CF distribution Browser treat them as different servers Wednesday, 7 August 13

Slide 168

Slide 168 text

Domain Sharding Use two or more CNAME aliases to serve the content from a CF distribution Browser treat them as different servers Sharding across 2 CNAME aliases will double the parallel download (Best 2-3) Wednesday, 7 August 13

Slide 169

Slide 169 text

Domain Sharding Use two or more CNAME aliases to serve the content from a CF distribution Browser treat them as different servers Sharding across 2 CNAME aliases will double the parallel download (Best 2-3) More than 4 CNAME will degrade browser performance (high CPU and memory uses) Wednesday, 7 August 13

Slide 170

Slide 170 text

Domain Sharding Wednesday, 7 August 13

Slide 171

Slide 171 text

Domain Sharding Use CF CNAME alias feature Wednesday, 7 August 13

Slide 172

Slide 172 text

Domain Sharding Use CF CNAME alias feature Use Route 53 for CNAME Aliasing Wednesday, 7 August 13

Slide 173

Slide 173 text

Domain Sharding Use CF CNAME alias feature Use Route 53 for CNAME Aliasing Custom Wild Card SSL Certificate Wednesday, 7 August 13

Slide 174

Slide 174 text

Domain Sharding Use CF CNAME alias feature Use Route 53 for CNAME Aliasing Custom Wild Card SSL Certificate On application side: enable CF sharding logic (template compilation etc) Wednesday, 7 August 13

Slide 175

Slide 175 text

Domain Sharding CDN with domain sharding CDN without domain sharding HTML Template Without CDN Compiled OR DOM Manipulation Compiled OR DOM Manipulation Wednesday, 7 August 13

Slide 176

Slide 176 text

Domain Sharding Wednesday, 7 August 13

Slide 177

Slide 177 text

Domain Sharding Wednesday, 7 August 13

Slide 178

Slide 178 text

Domain Sharding Apply domain sharding only where it’s needed most Wednesday, 7 August 13

Slide 179

Slide 179 text

Domain Sharding Apply domain sharding only where it’s needed most Evenly distribute the resources amongst the shards Wednesday, 7 August 13

Slide 180

Slide 180 text

Domain Sharding Apply domain sharding only where it’s needed most Evenly distribute the resources amongst the shards Consider performance overhead due to the DNS lookup and connection time Wednesday, 7 August 13

Slide 181

Slide 181 text

Domain Sharding Apply domain sharding only where it’s needed most Evenly distribute the resources amongst the shards Consider performance overhead due to the DNS lookup and connection time Sharding may not be good for Mobile Browsers (CPU, Battery Life) Wednesday, 7 August 13

Slide 182

Slide 182 text

Bucket Organisation Wednesday, 7 August 13

Slide 183

Slide 183 text

Bucket Organisation Limited Cache Behavior per CF Distribution Wednesday, 7 August 13

Slide 184

Slide 184 text

Bucket Organisation Limited Cache Behavior per CF Distribution Plan your bucket organisation (object keys) Wednesday, 7 August 13

Slide 185

Slide 185 text

Bucket Organisation Limited Cache Behavior per CF Distribution Plan your bucket organisation (object keys) Watch out for the upload paths Wednesday, 7 August 13

Slide 186

Slide 186 text

Bucket Organisation Limited Cache Behavior per CF Distribution Plan your bucket organisation (object keys) Watch out for the upload paths /video/uploads/, /audio/uploads/, /images/uploads/ BAD Wednesday, 7 August 13

Slide 187

Slide 187 text

Bucket Organisation Limited Cache Behavior per CF Distribution Plan your bucket organisation (object keys) Watch out for the upload paths /video/uploads/, /audio/uploads/, /images/uploads/ BAD /uploads/video/, /uploads/audio/, /uploads/image/ GOOD Wednesday, 7 August 13

Slide 188

Slide 188 text

Bucket Organisation Limited Cache Behavior per CF Distribution Plan your bucket organisation (object keys) Watch out for the upload paths /video/uploads/, /audio/uploads/, /images/uploads/ BAD /uploads/video/, /uploads/audio/, /uploads/image/ GOOD Use wild card patterns (/uploads/*) Wednesday, 7 August 13

Slide 189

Slide 189 text

Logging Wednesday, 7 August 13

Slide 190

Slide 190 text

Logging Enable logging, store access log file to S3 Wednesday, 7 August 13

Slide 191

Slide 191 text

Logging Enable logging, store access log file to S3 One log file per distribution Wednesday, 7 August 13

Slide 192

Slide 192 text

Logging Enable logging, store access log file to S3 One log file per distribution Combine log files and analyze logs (EMR) Wednesday, 7 August 13

Slide 193

Slide 193 text

Logging Enable logging, store access log file to S3 One log file per distribution Combine log files and analyze logs (EMR) W3C extended log file format Wednesday, 7 August 13

Slide 194

Slide 194 text

Logging Enable logging, store access log file to S3 One log file per distribution Combine log files and analyze logs (EMR) W3C extended log file format Streaming log vs Download log Wednesday, 7 August 13

Slide 195

Slide 195 text

Logging Enable logging, store access log file to S3 One log file per distribution Combine log files and analyze logs (EMR) W3C extended log file format Streaming log vs Download log Content Analytics: Popularity, Error etc Wednesday, 7 August 13

Slide 196

Slide 196 text

Performance Testing Wednesday, 7 August 13

Slide 197

Slide 197 text

Performance Testing Tradition Load Testing not useful Wednesday, 7 August 13

Slide 198

Slide 198 text

Performance Testing Tradition Load Testing not useful Same DNS request, same set of IPs Wednesday, 7 August 13

Slide 199

Slide 199 text

Performance Testing Tradition Load Testing not useful Same DNS request, same set of IPs Backbone Testing (Ideal Word) Wednesday, 7 August 13

Slide 200

Slide 200 text

Performance Testing Tradition Load Testing not useful Same DNS request, same set of IPs Backbone Testing (Ideal Word) CDN Server ˠ Backbone Wednesday, 7 August 13

Slide 201

Slide 201 text

Performance Testing Tradition Load Testing not useful Same DNS request, same set of IPs Backbone Testing (Ideal Word) CDN Server ˠ Backbone Last Mile (Real World, User Experience) Wednesday, 7 August 13

Slide 202

Slide 202 text

Performance Testing Tradition Load Testing not useful Same DNS request, same set of IPs Backbone Testing (Ideal Word) CDN Server ˠ Backbone Last Mile (Real World, User Experience) CDN Server ˠ Backbone ˠ Device Wednesday, 7 August 13

Slide 203

Slide 203 text

Performance Testing Tradition Load Testing not useful Same DNS request, same set of IPs Backbone Testing (Ideal Word) CDN Server ˠ Backbone Last Mile (Real World, User Experience) CDN Server ˠ Backbone ˠ Device 3rd party service (Gomez), application monitor Wednesday, 7 August 13

Slide 204

Slide 204 text

Performance Testing Tradition Load Testing not useful Same DNS request, same set of IPs Backbone Testing (Ideal Word) CDN Server ˠ Backbone Last Mile (Real World, User Experience) CDN Server ˠ Backbone ˠ Device 3rd party service (Gomez), application monitor Load Testing (Edge Location, Elastic IP Aware) Wednesday, 7 August 13

Slide 205

Slide 205 text

Performance Testing Tradition Load Testing not useful Same DNS request, same set of IPs Backbone Testing (Ideal Word) CDN Server ˠ Backbone Last Mile (Real World, User Experience) CDN Server ˠ Backbone ˠ Device 3rd party service (Gomez), application monitor Load Testing (Edge Location, Elastic IP Aware) Clients request from different geolocations Wednesday, 7 August 13

Slide 206

Slide 206 text

Performance Testing Tradition Load Testing not useful Same DNS request, same set of IPs Backbone Testing (Ideal Word) CDN Server ˠ Backbone Last Mile (Real World, User Experience) CDN Server ˠ Backbone ˠ Device 3rd party service (Gomez), application monitor Load Testing (Edge Location, Elastic IP Aware) Clients request from different geolocations Independent DNS request, different set of IPs Wednesday, 7 August 13

Slide 207

Slide 207 text

Performance Testing Tradition Load Testing not useful Same DNS request, same set of IPs Backbone Testing (Ideal Word) CDN Server ˠ Backbone Last Mile (Real World, User Experience) CDN Server ˠ Backbone ˠ Device 3rd party service (Gomez), application monitor Load Testing (Edge Location, Elastic IP Aware) Clients request from different geolocations Independent DNS request, different set of IPs Distribute load across set of IPs Wednesday, 7 August 13

Slide 208

Slide 208 text

Thank You Q & A Wednesday, 7 August 13