integrating multiple cdn providers at etsy - velocity europe (london) 2013

98
Integrating Multiple CDN Providers Our experiences at Etsy @lozzd • @ickymettle

Upload: marcus-barczak

Post on 08-Sep-2014

13 views

Category:

Technology


1 download

DESCRIPTION

Relying on a single content delivery network for your site can impose a number of flexibility limitations. By diversifying your CDN providers you can put the power back in your hands, allowing you to get the best of both worlds in terms of performance, reliability and cost. In this talk Marcus and Laurie will present Etsy’s recent work integrating multiple CDN providers to their site delivery infrastructure. This presentation was delivered at Velocity Europe, November 2013

TRANSCRIPT

Page 1: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

Integrating Multiple CDN ProvidersOur experiences at Etsy

@lozzd • @ickymettle

Page 2: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

Marcus Barczak Laurie Denness

Staff Operations Engineers

Page 3: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013
Page 4: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Page 5: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Page 6: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Beginning of 2010 Today

Page 7: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Background▪ First started using a single CDN in 2008

▪ Exponential Growth

▪ Start of 2012 began investigation into running multiple CDNs

Page 8: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Why use a CDN?▪ Goal: Consistently fast user experience globally

▪ Improve last mile performance by caching content close to the user

▪ Offload content delivery from origin infrastructure to the CDN provider

Page 9: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Why use more than one CDN?▪ Resilience

- Eliminate single point of failure

▪ Flexibility- Balance traffic based on business requirements

▪ Cost- Manage provider costs

Page 10: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

The Plan

http://www.flickr.com/photos/malloy/195204215

Page 11: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

The Plan1. Establish evaluation criteria

2. Initial configuration and testing

3. Test with production traffic

4. Operationalising

Page 12: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Evaluation Criteria

http://www.flickr.com/photos/49212595@N00/5646403386

Page 13: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Evaluation Criteria▪ Performance

▪ Configuration

▪ Reporting, Metrics and Logging

▪ Culture

Page 14: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Performance▪ Baseline Response Times

- Should be within ±5% of our existing CDN provider’s response times

▪ Hit Ratios and Origin Offload - Provider should achieve equivalent or better origin offload

performance and hit ratios

Page 15: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Configuration▪ Complexity

- how complex is the providers configuration system

▪ Self service- can you make changes directly or do they require

professional services or other intervention

▪ Latency for changes- how quickly do changes take to propagate

Page 16: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Reporting, Metrics and Logging▪ Resolution

▪ Latency

▪ Delivery

▪ Customisation

Page 17: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Culture▪ Understand our culture

▪ Postmortems

▪ Access to technical staff

▪ Shared success

Page 18: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

Initial Configuration

and Testing

http://www.flickr.com/photos/7269902@N07/4592239326

Page 19: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

Clean the househttp://www.flickr.com/photos/mastergeorge/8562623590

Page 20: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Clean the house▪ Managing caching TTLs from origin

- CDNs honour the origin cache-control headers!

<LocationMatch "\.(gif|jpg|jpeg|png|css|js)$"> Header set Cache-Control "max-age=94670800"</LocationMatch>

Page 21: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Clean the house▪ Manage gzip compression from origin

- Honoured by CDNs

- Compression from origin to CDN

## mod_deflate compression - see OPS-1537 ##AddOutputFilterByType DEFLATE text/html text/plain text/css application/x-javascript [..]

Page 22: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Clean the house

If you can do it at origin,do it at origin

Page 23: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

Mean Time To Curlhttp://www.flickr.com/photos/wwarby/3297205226

Page 24: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

HTTP/1.1 200 OKServer: ApacheLast-Modified: Sat, 09 Nov 2013 23:43:38 GMTCache-Control: max-age=94670800[...]X-Served-By: cache-lo82-LHRX-Cache: MISSX-Cache-Hits: 0

curl -i -H 'Host: img0.etsystatic.com' \ global-ssl.fastly.net/someimage.jpg

Page 25: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

HTTP/1.1 200 OKServer: ApacheLast-Modified: Sat, 09 Nov 2013 23:43:38 GMTCache-Control: max-age=94670800[...]X-Served-By: cache-lo82-LHRX-Cache: HITX-Cache-Hits: 1

curl -i -H 'Host: img0.etsystatic.com' \ global-ssl.fastly.net/someimage.jpg

Page 26: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

https://www.etsy.com/listing/99871278

Mean Time To Curl = Done

Page 27: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Mean Time To Curl▪ No need to touch existing infrastructure

▪ Smoke test of functionality

▪ 10 minutes from configuration to curl

▪ New providers should be plug and play

Page 28: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

Testing In Productionhttp://www.flickr.com/photos/solarnu/10646426865

Page 29: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Testing with Production Traffic▪ Images only at first

▪ Good test of caching performance

▪ Easy to test by swapping hostnames

▪ Made even easier with our A/B testing framework

Page 30: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

A/B Test Framework▪ Fine grained control

▪ Enable test for specific users or groups

▪ Percentage of users

▪ All controlled via configuration in code

▪ Rapid and complete rollback

Page 31: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Configure Mappings to CDNs$server_config["image"] = array( 'akamai' => array( 'img0-ak.etsystatic.com', 'img1-ak.etsystatic.com', ), 'edgecast' => array( 'img0-ec.etsystatic.com', 'img1-ec.etsystatic.com', ), 'fastly' => array( 'img0-f.etsystatic.com', 'img1-f.etsystatic.com', ),);

Page 32: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Test Controls

$server_config['ab']['cdn'] = array( 'enabled' => 'on', 'weights' => array( 'akamai' => 0.0, 'edgecast' => 0.0, 'fastly' => 0.0, 'origin' => 100.0, ), 'override' => 'cdn_diversity',);

Page 33: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Metrics and Monitoring

http://www.flickr.com/photos/nicolasfleury/6073151084

Page 34: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Metrics and Monitoring

Even if it doesn’t move, graph it anyway

Page 35: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Simplest approach: Provider’s dashboards

Metrics and Monitoring

Page 36: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

▪ Get more detail by pulling metrics in house

▪ Write script to pull data from API

▪ Create dashboards with data

Metrics and Monitoring

Page 37: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

▪ Get more detail by pulling metrics in house

▪ Write script to pull data from API

▪ Create dashboards with data

Metrics and Monitoring

Page 38: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Metrics and Monitoring

Page 39: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Metrics and Monitoring

Page 40: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Testing Plan1. for c in $cdns; do rampup $c; done;

2. Deliberately slow and steady

3. Watch traffic increase

4. Watch origin offload increase

5. Watch performance

Page 41: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Downsides of this approach▪ AB testing can’t be used for main site

▪ Exposing your test CNAMEs

▪ Especially if hotlinking is a concern

Page 42: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Downsides of this approach▪ Exposing your test CNAMEs

▪ Especially if hotlinking is a concern

Page 43: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

How do you know it’s broke? ▪ Check the graphs!

▪ Check with your community

▪ Keep support in the loop

Page 44: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

Operationalising

http://www.flickr.com/photos/98047351@N05/9706165200

Page 45: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Content Partitioning

Page 46: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Etsy’s site partitioning

Dynamic HTML Contentwww.etsy.com

Page 47: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Etsy’s site partitioning

Static Assets (js, css, fonts)site.etsystatic.com

Page 48: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Etsy’s site partitioning

Listing Images, AvatarsimgX.etsystatic.com

Page 49: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Etsy’s site partitioning

Listing Images, AvatarsimgX.etsystatic.com

Static Assets (js, css, fonts)site.etsystatic.com

Dynamic HTML Contentwww.etsy.com

Page 50: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

Balancing Traffic in Production

http://www.flickr.com/photos/wok_design/2499217405

Page 51: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Balancing Traffic Using DNS▪ Traffic Manager

▪ Extends DNS to dynamically return records based on rules

▪ Weighted round robin

Page 52: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Balancing Traffic Using DNS

[2589:~] $ dig +short www.etsy.comwww.etsy.com.edgekey.net.e2463.b.akamaiedge.net.23.74.122.37

[2589:~] $ dig +short www.etsy.comcs34.adn.edgecastcdn.net.93.184.219.54[2589:~] $ dig +short www.etsy.comglobal-ssl.fastly.net.185.31.19.184

[2589:~] $ dig +short www.etsy.cometsy.com.38.123.123.123

Page 53: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Balancing Traffic Using DNS

[2589:~] $ dig +short www.etsy.comwww.etsy.com.edgekey.net.e2463.b.akamaiedge.net.23.74.122.37

[2589:~] $ dig +short www.etsy.comcs34.adn.edgecastcdn.net.93.184.219.54

[2589:~] $ dig +short www.etsy.comglobal-ssl.fastly.net.185.31.19.184

[2589:~] $ dig +short www.etsy.cometsy.com.38.123.123.123

Page 54: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Balancing Traffic Using DNS▪ Rule updates typically made via web UI

▪ Can be slow and error prone

▪ Changes need to be applied to all three domains

▪ API available to make changes programmatically

Page 55: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

cdncontrol

http://www.flickr.com/photos/foshydog/4441105829

Page 56: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

cdncontrol

Page 57: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

cdncontrol

Page 58: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

cdncontrol

Page 59: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

cdncontrol

Page 60: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

cdncontrol

Page 61: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

cdncontrol

Page 62: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

cdncontrol

Page 63: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

cdncontrol

Page 64: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

cdncontrol

Page 65: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

cdncontrol

Page 66: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

DNS balancing downsides▪ Low TTLs for fast convergence

▪ More DNS lookups for users

▪ Not 100% instant or deterministic

▪ Mo QPS == Mo Money

Page 67: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

50% within 1 minute Long Tail is Loooong

Page 68: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Monitoring in Production

http://www.flickr.com/photos/9229426@N05/5160787240

Page 69: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Whoopsie Page▪ Static HTML delivered for 5xx errors

- Branding

- Translated error messages

- Links to status page

Page 70: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Whoopsie Page▪ Static HTML delivered for 5xx errors

- Branding

- Translated error messages

- Links to status page

Page 71: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Failure Beacons1. 1x1 tracking pixel embedded in page

[...]<img src="//failure.etsy.com/status/images/beacon.gif?beacon_source=fastly_origin_failure-etsy.com"></body></html>

Page 72: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Failure Beacons1. 1x1 tracking pixel embedded in page

2. Request creates an access log line

Page 73: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Failure Beacons1. 1x1 tracking pixel embedded in page

2. Request creates an access log line

3. Scrape them out minutely using logster

self.reg = re.compile('^\S+(\s:)? (?P<remote_addr>[0-9\.]+),? [0-9\.,\- ]+ \[[^\]]+\] \"GET /status/images/beacon\.gif\?(beacon_)?source=(?P<source>\S+) HTTP/1\.\d\" \d+ [\d\-]+ \"(?P<referrer>[^\"]+)\" \"(?P<user_agent>[^\"]+)\" .*$')

Page 74: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

1. 1x1 tracking pixel embedded in page

2. Request creates an access log line

3. Scrape them out minutely using logster

4. Logster posts event counts to Graphite

Failure Beacons

Page 75: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

1. 1x1 tracking pixel embedded in page

2. Request creates an access log line

3. Scrape them out minutely using logster

4. Logster posts event counts to Graphite

Failure Beacons

Page 76: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Failure Beacons1. 1x1 tracking pixel embedded in page

2. Request creates an access log line

3. Scrape them out minutely using logster

4. Logster posts event counts to Graphite

5. Alert on Graphite graph in Nagios

Page 77: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Failure Beacons1. 1x1 tracking pixel embedded in page

2. Request creates an access log line

3. Scrape them out minutely using logster

4. Logster posts event counts to Graphite

5. Alert on Graphite graph in Nagios

Page 78: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Failure Beacons▪ Client IP address can be geolocated

Page 79: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Failure Beacons▪ Optional extra debugging information

[31/Oct/2013:07:06:42 +0000] "GET /status/images/beacon.gif?beacon_source=fastly_origin_failure-etsy.com&provider_error=Connection%20timed%20out&server_identity=cache-ny57-NYC HTTP/1.1"

Page 80: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Failure Beacons▪ Optional extra debugging information

Page 81: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Tracking Requests to Origin

GET / HTTP/1.1User-Agent: curl/7.24.0Accept: */*X-Forwarded-Host: www.etsy.com[...]X-CDN-Provider: edgecast[...]Host: www.etsy.com

Page 82: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

GET / HTTP/1.1User-Agent: curl/7.24.0Accept: */*X-Forwarded-Host: www.etsy.com[...]X-CDN-Provider: edgecast[...]Host: www.etsy.com

Tracking Requests to Origin

Page 83: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Backend Monitoring▪ Vendor APIs to bring data in house

Page 84: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Backend Monitoring▪ Logster on CDN provider header

▪ Vendor APIs to bring data in house

Page 85: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Backend Monitoring▪ Vendor APIs to bring data in house

▪ Data in-house benefits include- Integration with our anomaly detection systems

- Consistent and unified view of all CDN metrics

- We control data retention period

Page 86: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Awareness▪ Over 100 engineers

▪ Deploying 60 times a day

▪ Correlating external and internal services

Page 87: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Awareness

Page 88: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Awareness

Deploy lines

Page 89: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Frontend Monitoring▪ Performance is important to us

▪ Monitoring overall site performance

▪ Monitoring performance by CDN provider

▪ Real User Monitoring on key pages to track page performance

Page 90: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Frontend Monitoring▪ Performance is important to us

▪ Monitoring overall site performance

▪ Monitoring performance by CDN provider

▪ SOASTA mPulse on key pages to track real user page performance

Page 91: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

Downsides http://www.flickr.com/photos/39272170@N00/3841286802

Page 92: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Debugging: What broke?▪ MTTD/MTTR can be extremely low with this

system

▪ But not always

Page 93: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Debugging: What broke?▪ MTTD/MTTR can be extremely low with this

system

▪ But not always

Page 94: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Debugging: What broke?▪ Non technical member base

▪ Confusing and time consuming

▪ Amazing support team

▪ Log as much information as possible

Page 95: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

Conclusions/Takeaways

http://www.flickr.com/photos/sk8geek/4649776194

Page 96: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Great success▪ 12 months in the benefits have far outweighed the

few downsides

▪ We’re continuing to evolve the system

▪ We’ll be sure to share our experience with the community along the way

Page 97: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

@lozzd • @ickymettle

Links/Open Source▪ cdncontrol

http://github.com/etsy/cdncontrolhttp://github.com/etsy/cdncontrol_ui

▪ logsterhttp://github.com/etsy/logster

▪ CDN API to Graphite scripts http://github.com/lozzd/cdn_scripts

Page 98: Integrating multiple CDN providers at Etsy - Velocity Europe (London) 2013

Thanks!Questions?

@lozzd • @ickymettle