SlideShare une entreprise Scribd logo
1  sur  44
Télécharger pour lire hors ligne
@TwitterAds | Confidential
@lfcipriani
2013-08-30
APIs Caching
W h y y o u r s e r v e r n e e d s s o m e r e s t
R u b y c o n f B r a z i l 2 0 1 3
@TwitterAds | Confidential
Who?
@lfcipriani
@TwitterAds | Confidential
What?
@lfcipriani
Scope of this presentation
4
• Caching in a Distributed System
• The flows of HTTP Cache and how to control them
• Good and Bad Practices
@lfcipriani
If you need a friendly way to understand the Caching part of RFC 2616
Scope of this presentation
5
Source: http://www.slideshare.net/lfcipriani/fearless-http-requests-abuse
@TwitterAds | Confidential
Definitions and
Definitions and Motivations
6
@lfcipriani
Memorizing phone numbers or go check phonebook every time
7
Analogy
@lfcipriani
Network Effect
8
Welcome to the first year of Software Engineering...
...where every request delivers a response without
failure and all network is reliable and fast.
Source: First day on Internet Kid (know your meme)
@lfcipriani
What problems cache helps to solve?
• redundant and unnecessary data traffic
• network bottlenecks
• origin server heavy load (or spikes)
• long network latency
9
@lfcipriani
HTTP Archive
10
Motivations
Source: http://httparchive.org/trends.php?s=All&minlabel=Jan+20+2011&maxlabel=Aug+15+2013
All sites Top 1000
@lfcipriani
HTTP Archive Cache lifetime: All Sites vs Top 100
11
Motivations
http://httparchive.org/interesting.php?a=All&l=Aug%2015%202013&s=Top100
@TwitterAds | Confidential
HTTP Caching Protocol
12
@lfcipriani
HTTP Caching flows
13
@lfcipriani 14
https://vine.co/v/hOuAXTOetuz
bit.ly/vinecaching
@lfcipriani 15
https://vine.co/v/hOuMHbTzp6h
bit.ly/vinecaching
@lfcipriani 16https://vine.co/v/hOu5g9FVDa5
bit.ly/vinecaching
@lfcipriani 17
https://vine.co/v/hOuvzinwrt6
bit.ly/vinecaching
@lfcipriani
The Cache headers zoo
18
Source: http://www.slideshare.net/lfcipriani/fearless-http-requests-abuse
@TwitterAds | Confidential
Cache Coherency
19
@lfcipriani
What’s cache coherency?
20
Since only the Origin Server knows the state of a
resource with certainty, caches and other components must
to ensure that the cached response is still fresh before
returning it to client.
Due to the complexity, keep cache coherency in
distributed systems has a high cost.
In a distributed system
@lfcipriani
Better safe than sorry
Strong consistency
21
Maintain coherency by revalidating every request in origin
server.
@lfcipriani
Living dangerously
Weak consistency
22
Cache has autonomy to use a heuristic to decide whether
the cached response is still fresh, without consulting the
origin server
Basically, there are 2 types of weak consistency.
@lfcipriani
Weak consistency - Invalidation
23
@lfcipriani
Weak consistency - Invalidation is bad!
24
• approach does not scale
• server needs to coordinate with a unknown network of
caches
• choose 2: immediacy, scalability, reliability
• “There are only two hard things in Computer Science:
cache invalidation and naming things” - Phil Karlton
• Two Generals Problem
http://www.subbu.org/blog/2010/01/cache-invalidation
http://en.wikipedia.org/wiki/Two_Generals'_Problem
@lfcipriani
Weak consistency - When to do Invalidation
25
When your network is similar to the one below ;-)
@lfcipriani
Weak consistency - TTL approach
26
@TwitterAds | Confidential
Taming Cache
27
@lfcipriani
Topology considerations
28
@lfcipriani
Controlling cacheability
Protocol Specific Considerations
29
1. locally means a cache that servers only one consumer
2. these directives override any configuration of the cache
3. by default, we can cache non safe/authenticated requests, GET and
HEAD and those with status code 200, 203, 206, 300, 301, 410
cache-control
directive
may I cache locally?
may I cache
anywhere?
should revalidate,
even being fresh?
no-store no no n/a
private yes no no
no-cache yes yes yes
public yes yes no
@lfcipriani 30
Protocol Specific Considerations
Controlling cacheability
Be aware of the Vary header, if the value is a header name
which values are high diversified, you could fill cache
storage too fast.
@lfcipriani 31
Protocol Specific Considerations
Controlling revalidation
Revalidation is done with conditional requests.
If-Modified-Since != Last-Modified = 200
If-Modified-Since == Last-Modified = 304
If-None-Match != Etag = 200
If-None-Match == Etag = 304
You can even decide how revalidation is done.
@lfcipriani
Content specific considerations
32
Careful with cookies
Be aware of how privacy policy influences what’s
cacheable
@lfcipriani
Content life cycle considerations
33
TL;DR;
Know the rates of change of your resources and establish
a time to live for them.
Expires=[Date]
Cache-Control: max-age=[seconds]
@lfcipriani 34
• too short (seconds) or too long (days) TTLs smell bad
• TTL can vary, don’t consider it as a constant value.
• don’t be afraid to get sophisticated, if needed:
• L-Factor heuristic: (date - last modified) * factor
• Prediction Models http://www.slideshare.net/jseidman/real-world-machine-learning-at-orbitz-strata-2011
• Control your cache strategy!
Content life cycle considerations
@lfcipriani
General considerations
35
Deciding to have NO cache is part of the strategy.
Your cache strategy might not be honored by an
intermediary cache, no hard feelings about it, is more
common than you think.
@TwitterAds | Confidential
Measuring efficiency
36
@lfcipriani
Measuring Cache efficiency
37
Hit Rate = Cache hits / Total of requests
This will depend on:
• how big your cache is
• how similar the interests of the cache users are
• the data rate of change
• how caches are configured
@lfcipriani
Measuring Cache efficiency
38
Byte Hit Rate =
Bytes transferred from cache hits /
Bytes transferred by Total of requests
@lfcipriani
Measuring Cache efficiency
39
• the same metrics could be applied to revalidations
• do the measures by resource
• do continuous measures and monitor to improve strategy
@lfcipriani
Validate your strategy in redbot.org
40
Measuring Cache efficiency
@TwitterAds | Confidential
Final considerations
41
@lfcipriani
Final considerations
42
• Is important to have a good knowledge of Topology of the application and Distributed
Systems constraints.
• Think and build a good strategy, don’t rely on default heuristics
• Measure, monitor and improve. Strategies are dynamic and change it is part of the
process.
• All this can be done incrementally, focus on relevant resources
• Be careful to not turn cache into overhead.
@lfcipriani 43
References
Web Protocols and Practice: HTTP/1.1, Networking Protocols, Caching, and Traffic
Measurement (Balachander Krishnamurthy and Jennifer Rexford)
HTTP: The Definitive Guide (David Gourley, Brian Totty, Marjorie Sayer and Anshu
Aggarwal)
http://www.w3.org/Protocols/rfc2616/rfc2616.html (HTTP RFC)
http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13 (Caching in HTTP)
http://stevesouders.com/
http://talleye.com/
https://dev.twitter.com/
bit.ly/vinecaching
@TwitterAds | Confidential
Thank you!

Contenu connexe

Similaire à API Caching, why your server needs some rest

cloud session uklug
cloud session uklugcloud session uklug
cloud session uklug
dominion
 

Similaire à API Caching, why your server needs some rest (20)

Cloud Design Patterns - Hong Kong Codeaholics
Cloud Design Patterns - Hong Kong CodeaholicsCloud Design Patterns - Hong Kong Codeaholics
Cloud Design Patterns - Hong Kong Codeaholics
 
Performance tuning Grails applications SpringOne 2GX 2014
Performance tuning Grails applications SpringOne 2GX 2014Performance tuning Grails applications SpringOne 2GX 2014
Performance tuning Grails applications SpringOne 2GX 2014
 
Resilient Event Driven Systems With Kafka
Resilient Event Driven Systems With KafkaResilient Event Driven Systems With Kafka
Resilient Event Driven Systems With Kafka
 
Technical standards & the RDTF Vision: some considerations
Technical standards & the RDTF Vision: some considerationsTechnical standards & the RDTF Vision: some considerations
Technical standards & the RDTF Vision: some considerations
 
CyberMLToolkit: Anomaly Detection as a Scalable Generic Service Over Apache S...
CyberMLToolkit: Anomaly Detection as a Scalable Generic Service Over Apache S...CyberMLToolkit: Anomaly Detection as a Scalable Generic Service Over Apache S...
CyberMLToolkit: Anomaly Detection as a Scalable Generic Service Over Apache S...
 
Documented Requirements are not Useless After All!
Documented Requirements are not Useless After All!Documented Requirements are not Useless After All!
Documented Requirements are not Useless After All!
 
Design for Scale / Surge 2010
Design for Scale / Surge 2010Design for Scale / Surge 2010
Design for Scale / Surge 2010
 
Cache Rules Everything Around Me - Momentum - October 2022.pptx
Cache Rules Everything Around Me - Momentum - October 2022.pptxCache Rules Everything Around Me - Momentum - October 2022.pptx
Cache Rules Everything Around Me - Momentum - October 2022.pptx
 
Cache Rules Everything Around Me - DevIntersection - December 2022
Cache Rules Everything Around Me - DevIntersection - December 2022Cache Rules Everything Around Me - DevIntersection - December 2022
Cache Rules Everything Around Me - DevIntersection - December 2022
 
Observability with Spring-based distributed systems
Observability with Spring-based distributed systemsObservability with Spring-based distributed systems
Observability with Spring-based distributed systems
 
Building data intensive applications
Building data intensive applicationsBuilding data intensive applications
Building data intensive applications
 
Zero Trust And Best Practices for Securing Endpoint Apps on May 24th 2021
Zero Trust And Best Practices for Securing Endpoint Apps on May 24th 2021Zero Trust And Best Practices for Securing Endpoint Apps on May 24th 2021
Zero Trust And Best Practices for Securing Endpoint Apps on May 24th 2021
 
Monitoring Apache Kafka
Monitoring Apache KafkaMonitoring Apache Kafka
Monitoring Apache Kafka
 
: HL7 Survival Guide - Chapter 7 – Gap Analysis
: HL7 Survival Guide - Chapter 7 – Gap Analysis: HL7 Survival Guide - Chapter 7 – Gap Analysis
: HL7 Survival Guide - Chapter 7 – Gap Analysis
 
We have come full circle. The earliest form of market exchange was peer to p...
We have come full circle. The earliest form of market  exchange was peer to p...We have come full circle. The earliest form of market  exchange was peer to p...
We have come full circle. The earliest form of market exchange was peer to p...
 
Cache Consistency – Requirements and its packet processing Performance implic...
Cache Consistency – Requirements and its packet processing Performance implic...Cache Consistency – Requirements and its packet processing Performance implic...
Cache Consistency – Requirements and its packet processing Performance implic...
 
QCon 2015 - Microservices Track Notes
QCon 2015 - Microservices Track Notes QCon 2015 - Microservices Track Notes
QCon 2015 - Microservices Track Notes
 
cloud session uklug
cloud session uklugcloud session uklug
cloud session uklug
 
8 cloud design patterns you ought to know - Update Conference 2018
8 cloud design patterns you ought to know - Update Conference 20188 cloud design patterns you ought to know - Update Conference 2018
8 cloud design patterns you ought to know - Update Conference 2018
 
Data management and pipelines Measure Camp - San Francisco
Data management and pipelines Measure Camp - San FranciscoData management and pipelines Measure Camp - San Francisco
Data management and pipelines Measure Camp - San Francisco
 

Plus de Luis Cipriani

Plus de Luis Cipriani (11)

Adventures with Raspberry Pi and Twitter API
Adventures with Raspberry Pi and Twitter APIAdventures with Raspberry Pi and Twitter API
Adventures with Raspberry Pi and Twitter API
 
Capturando o pulso do planeta com as APIs de Streaming do Twitter
Capturando o pulso do planeta com as APIs de Streaming do TwitterCapturando o pulso do planeta com as APIs de Streaming do Twitter
Capturando o pulso do planeta com as APIs de Streaming do Twitter
 
Twitter e suas APIs de Streaming - Campus Party Brasil 7
Twitter e suas APIs de Streaming - Campus Party Brasil 7Twitter e suas APIs de Streaming - Campus Party Brasil 7
Twitter e suas APIs de Streaming - Campus Party Brasil 7
 
Segurança de APIs HTTP, um guia sensato para desenvolvedores preocupados
Segurança de APIs HTTP, um guia sensato para desenvolvedores preocupadosSegurança de APIs HTTP, um guia sensato para desenvolvedores preocupados
Segurança de APIs HTTP, um guia sensato para desenvolvedores preocupados
 
Explaining A Programming Model for Context-Aware Applications in Large-Scale ...
Explaining A Programming Model for Context-Aware Applications in Large-Scale ...Explaining A Programming Model for Context-Aware Applications in Large-Scale ...
Explaining A Programming Model for Context-Aware Applications in Large-Scale ...
 
Alexandria: um Sistema de Sistemas para Publicação de Conteúdo Digital utiliz...
Alexandria: um Sistema de Sistemas para Publicação de Conteúdo Digital utiliz...Alexandria: um Sistema de Sistemas para Publicação de Conteúdo Digital utiliz...
Alexandria: um Sistema de Sistemas para Publicação de Conteúdo Digital utiliz...
 
Como um verdadeiro sistema REST funciona: arquitetura e performance na Abril
Como um verdadeiro sistema REST funciona: arquitetura e performance na AbrilComo um verdadeiro sistema REST funciona: arquitetura e performance na Abril
Como um verdadeiro sistema REST funciona: arquitetura e performance na Abril
 
Explaining Semantic Web
Explaining Semantic WebExplaining Semantic Web
Explaining Semantic Web
 
Hbase: Introduction to column oriented databases
Hbase: Introduction to column oriented databasesHbase: Introduction to column oriented databases
Hbase: Introduction to column oriented databases
 
Case Abril: Tracking real time user behavior in websites Homes with Ruby, Sin...
Case Abril: Tracking real time user behavior in websites Homes with Ruby, Sin...Case Abril: Tracking real time user behavior in websites Homes with Ruby, Sin...
Case Abril: Tracking real time user behavior in websites Homes with Ruby, Sin...
 
Fearless HTTP requests abuse
Fearless HTTP requests abuseFearless HTTP requests abuse
Fearless HTTP requests abuse
 

Dernier

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

API Caching, why your server needs some rest